repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
shirasagi/opendata
spec/models/ss/site_spec.rb
require 'spec_helper' describe SS::Site do subject(:model) { SS::Site } describe "#save and #find" do subject(:factory) { :ss_site } it_behaves_like "mongoid#save" it_behaves_like "mongoid#find" end describe "#attributes" do subject { ss_site } it { expect(subject.domain).not_to eq nil } ...
shirasagi/opendata
app/controllers/opendata/app/appfiles_controller.rb
class Opendata::App::AppfilesController < ApplicationController include Cms::BaseFilter include Cms::CrudFilter helper Opendata::FormHelper model Opendata::Appfile navi_view "opendata/main/navi" before_action :set_app private def app @app ||= Opendata::App.site(@cur_site).node(@cur_node).fin...
shirasagi/opendata
app/models/concerns/opendata/addon/common_page_setting.rb
<reponame>shirasagi/opendata module Opendata::Addon::CommonPageSetting extend ActiveSupport::Concern included do field :show_point, type: String, default: 'show' field :show_tabs, type: SS::Extensions::Words field :tab_titles, type: Hash permit_params :show_point permit_params show_tabs: [] ...
shirasagi/opendata
app/controllers/chorg/changesets_controller.rb
class Chorg::ChangesetsController < ApplicationController include Cms::BaseFilter include Cms::CrudFilter model Chorg::Changeset navi_view "cms/main/navi" before_action :set_revision private def set_crumbs set_revision @crumbs << [:"chorg.revision", chorg_revisions_revisions_path] ...
shirasagi/opendata
spec/features/chorg/run_spec.rb
require 'spec_helper' describe "chorg_run", dbscope: :example do let(:site) { cms_site } let(:revision) { create(:revision, site_id: site.id) } let(:changeset) { create(:add_changeset, revision_id: revision.id) } let(:revision_show_path) { chorg_revisions_revision_path site.host, revision.id } context "with...
shirasagi/opendata
app/controllers/cms/search_contents/pages_controller.rb
<reponame>shirasagi/opendata class Cms::SearchContents::PagesController < ApplicationController include Cms::BaseFilter include Cms::ApiFilter::Contents model Cms::Page append_view_path "app/views/cms/search_contents/pages" navi_view "cms/search_contents/navi" private def set_params @name =...
shirasagi/opendata
app/models/ss/site.rb
class SS::Site include SS::Model::Site end
shirasagi/opendata
spec/support/webmock_helper.rb
# require 'webmock/rspec' # include WebMock::API # WebMock.disable! # # NOTE: Don't use WebMock now because existing tests for voice fail.
shirasagi/opendata
spec/factories/ss/groups.rb
<reponame>shirasagi/opendata FactoryGirl.define do factory :ss_group, class: SS::Group do name "ss_group" end end
shirasagi/opendata
db/seeds/opendata/load.rb
Dir.chdir @root = File.dirname(__FILE__) @site = SS::Site.find_by host: ENV["site"] ## ------------------------------------- puts "# roles" def add_permissions(name, permissions) puts name cond = { name: name, site_id: @site.id } item = Cms::Role.find_by cond rescue nil return unless item item.permissions...
shirasagi/opendata
app/models/opendata/url_resource.rb
<gh_stars>1-10 class Opendata::UrlResource include SS::Document include Opendata::Resource::Model include SS::Relation::File include Opendata::Addon::UrlRdfStore field :original_url, type: String field :original_updated, type: DateTime field :crawl_state, type: String, default: "same" field :crawl_upda...
shirasagi/opendata
app/models/concerns/ckan/addon/server.rb
module Ckan::Addon module Server extend ActiveSupport::Concern extend SS::Addon included do field :ckan_url, type: String field :ckan_basicauth_state, type: String field :ckan_basicauth_username, type: String field :ckan_basicauth_password, type: String field :ckan_max_docs,...
shirasagi/opendata
spec/models/sitemap/node_spec.rb
<filename>spec/models/sitemap/node_spec.rb require 'spec_helper' describe Sitemap::Node::Base do subject(:model) { Sitemap::Node::Base } subject(:factory) { :sitemap_node_base } it_behaves_like "mongoid#save" it_behaves_like "mongoid#find" end describe Sitemap::Node::Page do subject(:model) { Sitemap::Node...
shirasagi/opendata
app/controllers/opendata/agents/nodes/member_controller.rb
<reponame>shirasagi/opendata<gh_stars>1-10 class Opendata::Agents::Nodes::MemberController < ApplicationController include Cms::NodeFilter::View helper Opendata::UrlHelper before_action :set_member, except: :index protected def set_member @member = Opendata::Member.site(@cur_site).where(id: params[:...
shirasagi/opendata
spec/factories/opendata/member_notices.rb
FactoryGirl.define do factory :opendata_member_notice, class: Opendata::MemberNotice do transient do site nil member nil end site_id { site.present? ? site.id : cms_site.id } member_id { member.present? ? member.id : nil } commented_count 11 confirmed { Time.zone.now } end end
shirasagi/opendata
app/controllers/opendata/agents/nodes/idea/idea_category_controller.rb
<gh_stars>1-10 class Opendata::Agents::Nodes::Idea::IdeaCategoryController < ApplicationController include Cms::NodeFilter::View include Opendata::UrlHelper include Opendata::Idea::IdeaFilter private def pages @cur_node.cur_subcategory = params[:name] @item = @cur_node.related_category ra...
shirasagi/opendata
lib/mobile/converter.rb
<filename>lib/mobile/converter.rb class Mobile::Converter < String @@tags = { remove: %w( area audio canvas caption col colgroup embed iframe keygen map noscript object optgroup output param progress script source track video), strip: %w( command datalist link rp rt style tbody tfoot thead),...
shirasagi/opendata
app/controllers/sys/sites_controller.rb
class Sys::SitesController < ApplicationController include Sys::BaseFilter include Sys::CrudFilter model Sys::Site menu_view "sys/crud/menu" private def set_crumbs @crumbs << [:"sys.site", sys_sites_path] end public def index raise "403" unless @model.allowed?(:edit, @cur_user) ...
shirasagi/opendata
app/models/job/task.rb
class Job::Task extend SS::Translation include SS::Document include SS::Model::Task include SS::Reference::User #include SS::Reference::Site field :pool, type: String field :class_name, type: String field :args, type: Array field :priority, type: Integer, default: -> { Time.zone.now.to_i } field :a...
shirasagi/opendata
spec/factories/cms/pages.rb
<reponame>shirasagi/opendata FactoryGirl.define do trait :cms_page do site_id { cms_site.id } user_id { cms_user.id } name { "#{unique_id}" } filename { "#{name}.html" } route "cms/page" end factory :cms_page, class: Cms::Page, traits: [:cms_page] do # end factory :cms_import_page, c...
shirasagi/opendata
spec/features/opendata/agents/nodes/mypage/dataset/my_dataset_spec.rb
<gh_stars>1-10 require 'spec_helper' describe "opendata_agents_nodes_my_dataset", dbscope: :example do let(:site) { cms_site } let(:member) { opendata_member(site: site) } let!(:node_member) { create :opendata_node_member } let!(:node_search_dataset) { create_once :opendata_node_search_dataset, basename: "data...
shirasagi/opendata
app/models/chorg/main_runner.rb
<filename>app/models/chorg/main_runner.rb class Chorg::MainRunner < Chorg::Runner include Job::Worker private def save_or_collect_errors(entity) return true if entity.save entity.errors.full_messages.each do |message| put_error("#{message}") end false rescue ScriptError, St...
shirasagi/opendata
app/models/concerns/sys/reference/role.rb
<reponame>shirasagi/opendata<filename>app/models/concerns/sys/reference/role.rb module Sys::Reference module Role extend ActiveSupport::Concern included do embeds_ids :sys_roles, class_name: "Sys::Role" permit_params cms_role_ids: [] end public def sys_role_permissions retu...
shirasagi/opendata
spec/features/ezine/members_spec.rb
require 'spec_helper' describe "ezine_members" do subject(:site) { cms_site } subject(:node) { create_once :ezine_node } subject(:item) { Ezine::Member.last } subject(:index_path) { ezine_members_path site.host, node } subject(:new_path) { new_ezine_member_path site.host, node } subject(:show_path) { ezine...
shirasagi/opendata
app/models/ss/max_file_size.rb
class SS::MaxFileSize extend SS::Translation include SS::Document include Sys::Permission set_permission_name "sys_users", :edit # Upload limit size (Bytes) # 104857600 = 100MB(1024*1024*100) MAX_FILE_SIZE = 104_857_600 STATE_ENABLED = 'enabled'.freeze STATE_DISABLED = 'disabled'.freeze STATES = ...
shirasagi/opendata
app/controllers/workflow/search_approvers_controller.rb
class Workflow::SearchApproversController < ApplicationController include Cms::ApiFilter model Cms::User private def group_id default_group_id = @cur_user.group_ids.first return default_group_id if params[:s].blank? return default_group_id if params[:s][:group].blank? group_id = par...
shirasagi/opendata
config/routes/workflow/routes.rb
<reponame>shirasagi/opendata SS::Application.routes.draw do concern :deletion do get :delete, on: :member post :request_update, on: :member post :approve_update, on: :member post :remand_update, on: :member end concern :branch do post :branch_create, on: :member end content "workflow" d...
shirasagi/opendata
app/models/rdf/owl.rb
<filename>app/models/rdf/owl.rb<gh_stars>1-10 # module Rdf::Owl # class Restriction # include SS::Document # # attr_accessor :in_vocab, :in_class # attr_accessor :in_property_namespace, :in_property_prefix, :in_property_name # # field :_id, type: String, default: ->{ property.try(:name) } # field ...
shirasagi/opendata
spec/features/opendata/agents/nodes/mypage/mypage_spec.rb
require 'spec_helper' describe "opendata_agents_nodes_mypage", dbscope: :example do let(:site) { cms_site } let!(:node_dataset) { create :opendata_node_dataset } let(:node_mypage) { create :opendata_node_mypage, filename: "mypage", basename: "mypage" } let!(:node_my_dataset) { create :opendata_node_my_dataset,...
shirasagi/opendata
app/controllers/chorg/run_controller.rb
<reponame>shirasagi/opendata<gh_stars>1-10 class Chorg::RunController < ApplicationController include Cms::BaseFilter # include Cms::CrudFilter before_action :prepend_current_view_path before_action :append_view_paths before_action :set_item model Chorg::Revision navi_view "cms/main/navi" private ...
shirasagi/opendata
app/models/opendata/app.rb
class Opendata::App include Cms::Model::Page include ::Workflow::Addon::Approver include Opendata::Addon::Appfile include Opendata::Addon::Category include Opendata::Addon::Area include Opendata::Addon::Dataset include Opendata::Reference::Member include Opendata::Common include Cms::Addon::Release ...
shirasagi/opendata
app/controllers/facility/agents/nodes/search_controller.rb
class Facility::Agents::Nodes::SearchController < ApplicationController include Cms::NodeFilter::View helper Map::MapHelper append_view_path "app/views/facility/agents/addons/search_setting/view" append_view_path "app/views/facility/agents/addons/search_result/view" private def set_query @keyword ...
shirasagi/opendata
app/models/concerns/ckan/addon/status.rb
module Ckan::Addon module Status extend ActiveSupport::Concern extend SS::Addon included do field :ckan_url, type: String field :ckan_basicauth_state, type: String field :ckan_basicauth_username, type: String field :ckan_basicauth_password, type: String field :ckan_status, t...
shirasagi/opendata
config/routes/voice/routes.rb
<filename>config/routes/voice/routes.rb SS::Application.routes.draw do Voice::Initializer concern :deletion do get :delete, on: :member end concern :file do get :file, on: :member end concern :download do get :download, on: :collection end namespace "voice", path: ".voice" do get "/...
shirasagi/opendata
app/models/concerns/cms/addon/tabs.rb
<gh_stars>1-10 module Cms::Addon module Tabs extend ActiveSupport::Concern extend SS::Addon included do field :conditions, type: SS::Extensions::Words field :limit, type: Integer, default: 8 field :new_days, type: Integer, default: 1 permit_params :conditions, :limit, :new_days ...
shirasagi/opendata
config/routes/inquiry/routes.rb
<gh_stars>1-10 SS::Application.routes.draw do Inquiry::Initializer concern :deletion do get :delete, on: :member end concern :download do get :download, on: :collection end content "inquiry" do get "/" => redirect { |p, req| "#{req.path}/columns" }, as: :main resources :nodes, concerns: ...
shirasagi/opendata
spec/factories/ezine/node.rb
FactoryGirl.define do factory :ezine_node, class: Cms::Node do site_id { cms_site.id } user_id { cms_user.id } name 'title' filename 'magazine' route 'magazine' end end
shirasagi/opendata
spec/features/opendata/dataset/resources_spec.rb
require 'spec_helper' describe "opendata_datasets", type: :feature, dbscope: :example do let(:site) { cms_site } let(:node) { create_once :opendata_node_dataset, name: "opendata_dataset" } let!(:node_search) { create_once :opendata_node_search_dataset } let!(:license_logo_file_path) { Rails.root.join("spec", "...
shirasagi/opendata
spec/features/workflow/routes_spec.rb
require 'spec_helper' describe "workflow_routes", dbscope: :example do let!(:site) { cms_site } let!(:user) { cms_user } let!(:group) { cms_group } let(:index_path) { workflow_routes_path site.host } let(:new_path) { new_workflow_route_path site.host } it "without login" do visit index_path expect...
shirasagi/opendata
lib/voice/japanese_text_reconstructor.rb
# this class divides too long text, and also this class joins too small text. class Voice::JapaneseTextReconstructor include Enumerable SEPARATOR = /[\s 。、]+/ PAUSE_TEXT = '。' def initialize(texts, max_length) @texts = texts @max_length = max_length end def each # setup enumerable e = @te...
shirasagi/opendata
spec/factories/inquiry/columns.rb
<filename>spec/factories/inquiry/columns.rb<gh_stars>1-10 FactoryGirl.define do factory :inquiry_column_name, class: Inquiry::Column do name "お名前" input_type "text_field" required "required" html "<p>お名前を入力してくだ さい。</p>" order 10 end factory :inquiry_column_optional, class: Inquiry::Column do ...
shirasagi/opendata
app/models/event/page.rb
class Event::Page include Cms::Model::Page include Workflow::Addon::Branch include Workflow::Addon::Approver include Cms::Addon::Meta include Cms::Addon::Body include Cms::Addon::File include Category::Addon::Category include Cms::Addon::ParentCrumb include Event::Addon::Body include Cms::Addon::Add...
shirasagi/opendata
app/models/job/master_service.rb
require 'English' class Job::MasterService class << self public def run(config = nil) config ||= SS.config.job.default num_workers = config["num_workers"] if num_workers == 0 # execute jobs in-place Job::Service.run config return true end ...
shirasagi/opendata
app/controllers/chorg/results_controller.rb
class Chorg::ResultsController < ApplicationController include Cms::BaseFilter include Cms::CrudFilter before_action :filter_permission before_action :set_revision model Job::Log navi_view "cms/main/navi" private def set_crumbs @crumbs << [:"chorg.revision", controller: :revisions, action: ...
shirasagi/opendata
app/models/opendata/node.rb
module Opendata::Node class Base include Cms::Model::Node include Cms::Addon::GroupPermission default_scope ->{ where(route: /^opendata\//) } end class Category include Cms::Model::Node include Cms::Addon::NodeSetting include Cms::Addon::Release include Cms::Addon::Meta include C...
shirasagi/opendata
app/models/ezine/page.rb
<filename>app/models/ezine/page.rb class Ezine::Page include Cms::Model::Page include Ezine::Addon::Body include Ezine::Addon::DeliverPlan include Cms::Addon::Release include Cms::Addon::ReleasePlan include Cms::Addon::GroupPermission field :test_delivered, type: DateTime field :completed, type: Boolea...
shirasagi/opendata
spec/factories/opendata/csv2rdf_settings.rb
<filename>spec/factories/opendata/csv2rdf_settings.rb FactoryGirl.define do factory :opendata_csv2rdf_setting, class: Opendata::Csv2rdfSetting do transient do site nil resource nil end site_id { site.present? ? site.id : nil } dataset_id { resource.dataset.id } resource_id { resource....
shirasagi/opendata
app/models/concerns/ss/addon.rb
module SS::Addon def self.extended(mod) mod.extend SS::Translation end public def addon_name SS::Addon::Name.new(self) end end
shirasagi/opendata
app/controllers/opendata/dataset/url_resources_controller.rb
<filename>app/controllers/opendata/dataset/url_resources_controller.rb<gh_stars>1-10 class Opendata::Dataset::UrlResourcesController < ApplicationController include Cms::BaseFilter include Cms::CrudFilter helper Opendata::FormHelper model Opendata::UrlResource navi_view "opendata/main/navi" before_action...
shirasagi/opendata
app/controllers/rdf/owl/restrictions_controller.rb
# class Rdf::Owl::RestrictionsController < ApplicationController # include Cms::BaseFilter # include Cms::CrudFilter # # model Rdf::Owl::Restriction # # navi_view "cms/main/navi" # # before_action :set_class # # private # def set_vocab # return if @vocab.present? # @vocab = Rdf::Vocab.site(@...
shirasagi/opendata
spec/models/job/worker_spec.rb
require 'spec_helper' describe Job::Worker do subject(:model) do Struct.new("J#{unique_id}") do include Job::Worker def call end end end jobs = [] describe ".call_async" do it "creates Job::Task" do expect { jobs << model.call_async }.to change { Job::Task.count }.by(1) ...
shirasagi/opendata
app/controllers/concerns/opendata/api/package_show_filter.rb
<filename>app/controllers/concerns/opendata/api/package_show_filter.rb module Opendata::Api::PackageShowFilter extend ActiveSupport::Concern include Opendata::Api private def package_show_check(id) id_messages = [] id_messages << "Missing value" if id.blank? messages = {} ...
shirasagi/opendata
spec/features/opendata/agents/nodes/sparql_spec.rb
require 'spec_helper' describe "opendata_agents_nodes_sparql", dbscope: :example do let(:node) { create_once :opendata_node_sparql, name: "opendata_sparql" } let(:index_path) { "#{node.url}" } let(:search_label) { "Run Query" } context "sparql is disabled" do before do @save_config = SS...
shirasagi/opendata
config/routes/ldap/routes.rb
SS::Application.routes.draw do Ldap::Initializer concern :deletion do get :delete, on: :member end namespace("ldap", as: "ldap", path: ".:site/ldap", module: "ldap") do get "server/:dn/group" => "server#group" get "server/:dn/user" => "server#user" get "server/:dn" => "server#index" get "...
shirasagi/opendata
spec/features/opendata/app/search_apps_spec.rb
require 'spec_helper' describe "opendata_search_apps", dbscope: :example do let(:site) { cms_site } let(:node) { create_once :opendata_node_search_app, name: "opendata_search_apps" } let(:index_path) { opendata_search_apps_path site.host, node } context "search_app" do before { login_cms_user } it "...
shirasagi/opendata
app/models/concerns/cms/addon/release.rb
<gh_stars>1-10 module Cms::Addon module Release extend ActiveSupport::Concern extend SS::Addon end end
shirasagi/opendata
app/models/ezine/public_entry.rb
<filename>app/models/ezine/public_entry.rb<gh_stars>1-10 class Ezine::PublicEntry include Ezine::Entryable include Ezine::Addon::Data store_in session: :public, collection: :ezine_entries end
shirasagi/opendata
spec/factories/opendata/license.rb
FactoryGirl.define do factory :opendata_license, class: Opendata::License do transient do site nil user nil file nil end name { "#{unique_id}" } site_id { site.present? ? site.id : nil } user_id { user.present? ? user.id : nil } in_file { file } end end
shirasagi/opendata
app/controllers/ads/access_logs_controller.rb
<reponame>shirasagi/opendata class Ads::AccessLogsController < ApplicationController include Cms::BaseFilter model Ads::AccessLog navi_view "ads/main/navi" public def index if s = params[:s] @year = s[:year].presence @month = s[:month].presence end sy = Time.zone.today...
shirasagi/opendata
app/models/concerns/ss/model/user.rb
module SS::Model::User extend ActiveSupport::Concern extend SS::Translation include SS::Document include SS::Fields::Normalizer include Ldap::Addon::User attr_accessor :cur_user, :in_password TYPE_SNS = "sns".freeze TYPE_LDAP = "ldap".freeze LOGIN_ROLE_DBPASSWD = "<PASSWORD>".freeze LOGIN_ROLE_LD...
shirasagi/opendata
spec/features/opendata/app/appfiles_spec.rb
require 'spec_helper' describe "opendata_appfiles", dbscope: :example do def create_appfile(app, file) appfile = app.appfiles.new(text: "aaa", format: "csv") appfile.in_file = file appfile.save appfile end let(:site) { cms_site } let!(:node_search_app) { create(:opendata_node_search_app) } l...
shirasagi/opendata
spec/models/opendata/dataset_group_spec.rb
<gh_stars>1-10 require 'spec_helper' describe Opendata::DatasetGroup, dbscope: :example do describe "#state_options" do subject { create(:opendata_dataset_group, site: cms_site, categories: [ OpenStruct.new({ _id: 1 }) ]) } its(:state_options) { is_expected.to include %w(公開 public) } end describe ".publ...
evilmartians/fias
lib/fias/name/canonical.rb
module Fias module Name module Canonical class << self def canonical(name) result = search(name) || search_exception(name) result || fail("Unknown abbrevation: #{name}") fix_republic_case(result) end private def search(key) long = Fia...
evilmartians/fias
tasks/download.rake
require 'fias' namespace :fias do desc 'Returns lastest url of FIAS db (bundle exec rake fias:download | xargs wget)' task :download do url = Fias::Import::DownloadService.url if url puts url else puts 'An error occured during SOAP call' return 999 end end end
evilmartians/fias
lib/fias/import/dbf.rb
module Fias module Import class Dbf def initialize(path, encoding = DEFAULT_ENCODING) @path = path @files = {} unless Dir.exist?(@path) fail ArgumentError, "FIAS database path #{@path} does not exists" end open_files(encoding) end def only(*na...
evilmartians/fias
lib/fias/import/tables.rb
<filename>lib/fias/import/tables.rb module Fias module Import class Tables def initialize(db, files, prefix = DEFAULT_PREFIX) @db = db @files = files @prefix = prefix end attr_reader :files def create @files.each do |name, dbf| next if dbf.blank?...
evilmartians/fias
lib/fias/config.rb
<filename>lib/fias/config.rb<gh_stars>10-100 module Fias class Config def initialize @index = {} @longs = {} @shorts = {} @aliases = {} @exceptions = {} @proper_names = [] @replacements = {} @synonyms = [] @synonyms_index = {} yield(self) finaliz...
evilmartians/fias
lib/fias/name/house_number.rb
module Fias module Name module HouseNumber class << self def extract(name) return [name, nil] unless contains_number?(name) name, number = try_split_by_colon(name) || try_housing(name) || try_house_word(name) || tr...
evilmartians/fias
spec/lib/name/house_number_spec.rb
<reponame>evilmartians/fias<gh_stars>10-100 require 'spec_helper' describe Fias::Name::HouseNumber do { '14' => ['14', nil], 'мкр. 14' => ['мкр. 14', nil], 'лин. 5' => ['лин. 5', nil], 'линия 14' => ['линия 1...
evilmartians/fias
tasks/db.rake
<gh_stars>10-100 require 'fias' require 'ruby-progressbar' require 'sequel' namespace :fias do desc 'Create FIAS tables (PREFIX, FIAS_PATH to dbfs, DATABASE_URL and TABLES)' task :create_tables do within_connection do |tables| tables.create puts "#{tables.files.keys.join(', ')} created." end ...
wooga/rack-flash
lib/rack/flash.rb
<filename>lib/rack/flash.rb module Rack class Flash # Raised when the session passed to FlashHash initialize is nil. This # is usually an indicator that session middleware is not in use. class SessionUnavailable < StandardError; end # Implements bracket accessors for storing and retrieving flash ent...
louismerlin/croque
api/public.rb
<gh_stars>0 class PublicApp < Sinatra::Base # Gives the menu for the day get '/' do @menu = Menu.where(:date => Date.today).first if @menu @menu.questions.map{ |q| { id: q.id, body: q.body, answers: q.answers.map{|a| {place: a.place, body: a.body}} } }.to_json else "CLOSED".to_js...
louismerlin/croque
admin/algo.rb
def distribute # Creation of distribution objects @prop = Distribution.where { (proportion > 0) }.all.select { |d| d.size > 1 } @sum = 0 @prop.each do |p| @sum += p.proportion end # Default distribution if this one is not valid if @sum.zero? @prop = [{ size: 2, proportion: 1 }, { size: 3, proporti...
louismerlin/croque
api/lunches.rb
<reponame>louismerlin/croque<gh_stars>0 class LunchApp < Sinatra::Base # Check if you have a lunch assigned for today get '/lunch' do protected! @lunch = User[session[:logged]].lunches_dataset.where(date: Date.today).first if @lunch {id: @lunch[:lunch_id], users: @lunch.users.map{|u| {id: u[:id], ...
louismerlin/croque
api/users.rb
class UserApp < Sinatra::Base # Creates a new user (temporary) post '/users' do @data = JSON.parse(request.body.read) @email = @data['email'] @firstname = @data['firstname'] @lastname = @data['lastname'] @password = @data['password'] if @email != nil && @firstname != nil && @lastname != nil && @password !...
louismerlin/croque
api/models.rb
# Sequel => access to database Sequel::Model.plugin :force_encoding, 'UTF-8' DB = Sequel.connect('postgres://hello:coffee@db/') class User < Sequel::Model many_to_many :lunches end User.unrestrict_primary_key class Lunch < Sequel::Model many_to_many :users end class Lunchrequest < Sequel::Model many_to_many :ans...
louismerlin/croque
admin/app.rb
#!/usr/local/bin/ruby require 'sinatra/base' require 'rack/mount' require 'sequel' require 'date' require 'rufus-scheduler' require './models' require './algo' class Admin < Sinatra::Base # Stats page get '/' do protected! erb :index, layout: :layout end # Login page get '/login' do erb :login,...
louismerlin/croque
api/app.rb
<reponame>louismerlin/croque #!/usr/local/bin/ruby require 'sinatra/base' require 'rack/mount' require 'net/http' require 'sequel' require 'date' require 'json' require 'bcrypt' require './helpers' require './models' require './users' require './lunches' require './public' class Routes < Sinatra::Base get('/users*'...
louismerlin/croque
api/helpers.rb
<reponame>louismerlin/croque module HelpersApp # A protected page will only be available if you are authorized def protected! if authorized? true else halt 401 end end # You are autorized if you have logged in def authorized? if session[:logged] true else false ...
louismerlin/croque
admin/models.rb
<gh_stars>0 # Sequel => access to database DB = Sequel.connect('postgres://hello:coffee@db/') class User < Sequel::Model many_to_many :lunches end # Makes it able to use sciper as key User.unrestrict_primary_key Sequel.inflections do |inflect| inflect.irregular 'lunch', 'lunches' end class Lunch < Sequel::Model ...
kritikagarg/cs595-s21
assignments/Garg/4/framable/http-responses/ria.ru
HTTP/1.1 301 Moved Permanently Server: QRATOR Date: Thu, 01 Apr 2021 16:20:44 GMT Content-Length: 0 Connection: keep-alive Keep-Alive: timeout=15 Location: https://ria.ru/ HTTP/1.1 200 OK Server: QRATOR Date: Thu, 01 Apr 2021 16:20:44 GMT Content-Type: text/html; charset=utf-8 Connection: keep-alive Keep-...
nuthintrue/AuthEngine
app/api/auth_engine/v1/helpers/auth_token.rb
<reponame>nuthintrue/AuthEngine<filename>app/api/auth_engine/v1/helpers/auth_token.rb module AuthEngine module V1 module Helpers module AuthToken extend Grape::API::Helpers def authenticate_credentials! unless credential.authenticate(auth_params[:password]) error!('Inv...
nuthintrue/AuthEngine
app/api/auth_engine/v1/base.rb
module AuthEngine module V1 class Base < Grape::API mount V1::Health mount V1::Apply mount V1::User::Token add_swagger_documentation mount_path: '/v1/doc', api_version: 'v1', info: { title: "auth api", description: "auth api", contact_name: "a...
nuthintrue/AuthEngine
test/dummy/config/initializers/swagger.rb
GrapeSwaggerRails.options.app_name = 'auth_engine' GrapeSwaggerRails.options.url = '/api/v1/doc.json' GrapeSwaggerRails.options.app_url = 'http://localhost:3000' GrapeSwaggerRails.options.before_filter_proc = proc { GrapeSwaggerRails.options.app_url = request.protocol + request.host_with_port } GrapeSwaggerRail...
nuthintrue/AuthEngine
app/models/auth_engine/user.rb
<gh_stars>0 module AuthEngine class User < ApplicationRecord has_one :credential delegate :email, to: :credential end end
nuthintrue/AuthEngine
app/models/auth_engine/credential.rb
module AuthEngine class Credential < ApplicationRecord has_secure_password validates :email, uniqueness: true validates :password, length: { minimum: 6 }, if: :setting_password? belongs_to :user def generate_new_confirmation_token self.update_attributes(confirmation_token_expires_at: new_c...
nuthintrue/AuthEngine
app/api/auth_engine/v1/defaults.rb
module AuthEngine module V1 module Defaults extend ActiveSupport::Concern included do # Common Grape settings version 'v1' format :json # Common helpers helpers do def permitted_params @permitted_params ||= declared(params, include_missin...
nuthintrue/AuthEngine
app/api/auth_engine/v1/apply.rb
<gh_stars>0 module AuthEngine module V1 class Apply < Grape::API include V1::Defaults namespace :apply do params do requires :email, type: String requires :password, type: String optional :first_name, type: String optional :last_name, type: String ...
nuthintrue/AuthEngine
db/migrate/20160810185237_create_credentials.rb
<filename>db/migrate/20160810185237_create_credentials.rb class CreateCredentials < ActiveRecord::Migration[5.0] def change create_table :auth_engine_credentials do |t| t.string :email, null: false, index: { unique: true } t.string :password_digest t.belongs_to :user t.timestamps null: fal...
nuthintrue/AuthEngine
lib/auth_engine/engine.rb
<gh_stars>0 module AuthEngine class Engine < ::Rails::Engine isolate_namespace AuthEngine end end
nuthintrue/AuthEngine
app/api/auth_engine/v1/error/api_error.rb
<reponame>nuthintrue/AuthEngine<filename>app/api/auth_engine/v1/error/api_error.rb<gh_stars>0 module AuthEngine module V1 module Error class ApiError < StandardError attr_reader :data, :message, :status, :code def initialize(status:, message:, data: nil, code: nil) @status = statu...
nuthintrue/AuthEngine
test/dummy/config/routes.rb
<reponame>nuthintrue/AuthEngine Rails.application.routes.draw do #mount AuthEngine::Engine => "/auth_engine" mount AuthEngine::Base => '/api' mount GrapeSwaggerRails::Engine => 'api/documentation' end
nuthintrue/AuthEngine
app/api/auth_engine/v1/health.rb
<reponame>nuthintrue/AuthEngine<gh_stars>0 module AuthEngine module V1 class Health < Grape::API include V1::Defaults helpers V1::Helpers::Authentication before do authenticate_token! end namespace :health do desc 'headers', { headers: { "Autho...
nuthintrue/AuthEngine
app/coordinators/auth_engine/api/health/post_coordinator.rb
module AuthEngine module Api module Health class PostCoordinator < Api::ApiCoordinator def call result.status = 200 result.body = 'Success! The service is healthy!' result rescue StandardError => e result.status = e.status result.body = e.me...
nuthintrue/AuthEngine
app/helpers/auth_engine/application_helper.rb
module AuthEngine module ApplicationHelper end end
nuthintrue/AuthEngine
app/coordinators/auth_engine/api/api_coordinator_result.rb
module AuthEngine module Api class ApiCoordinatorResult attr_accessor :status, :body def initialize(status: '', body: '') @status = status @body = body end end end end
nuthintrue/AuthEngine
app/coordinators/auth_engine/api/apply/post_coordinator.rb
<filename>app/coordinators/auth_engine/api/apply/post_coordinator.rb module AuthEngine module Api module Apply class PostCoordinator < Api::ApiCoordinator def call user = AuthEngine::User.create!(first_name: params[:first_name], last_name: params[:last_name]) # credential = user...
nuthintrue/AuthEngine
app/coordinators/auth_engine/base_coordinator.rb
<reponame>nuthintrue/AuthEngine module AuthEngine class BaseCoordinator def raise_api_error!(message, status, data = nil, code = nil) raise V1::Error::ApiError, status: status, message: message, data: data, code: code end end end
nuthintrue/AuthEngine
auth_engine.gemspec
$:.push File.expand_path("../lib", __FILE__) # Maintain your gem's version: require "auth_engine/version" # Describe your gem and declare its dependencies: Gem::Specification.new do |s| s.name = "auth_engine" s.version = AuthEngine::VERSION s.authors = ["<NAME>"] s.email = ["<EMAIL>"] s...
nuthintrue/AuthEngine
app/api/auth_engine/v1/user/token.rb
<reponame>nuthintrue/AuthEngine<filename>app/api/auth_engine/v1/user/token.rb module AuthEngine module V1 module User class Token < Grape::API include V1::Defaults helpers V1::Helpers::AuthToken after_validation do authenticate_credentials! end params do ...