source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/models/phone_spec.rb | Ruby | bsd-3-clause | 187 | master | 1,347 | require 'rails_helper'
describe Phone do
subject { build(:phone) }
it { is_expected.not_to be_valid }
it { is_expected.to belong_to(:location).optional.touch(true).inverse_of(:phones) }
it { is_expected.to belong_to(:contact).optional.touch(true).inverse_of(:phones) }
it { is_expected.to belong_to(:service... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/models/holiday_schedule_spec.rb | Ruby | bsd-3-clause | 187 | master | 1,506 | require 'rails_helper'
describe HolidaySchedule do
subject { build(:holiday_schedule) }
it { is_expected.not_to be_valid }
it { is_expected.to belong_to(:location).optional.touch(true).inverse_of(:holiday_schedules) }
it { is_expected.to belong_to(:service).optional.touch(true).inverse_of(:holiday_schedules)... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/models/contact_spec.rb | Ruby | bsd-3-clause | 187 | master | 1,164 | require 'rails_helper'
describe Contact do
subject { build(:contact) }
it { is_expected.not_to be_valid }
it { is_expected.to belong_to(:location).optional.touch(true) }
it { is_expected.to belong_to(:service).optional.touch(true) }
it { is_expected.to belong_to(:organization).optional }
it { is_expected... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/models/api_application_spec.rb | Ruby | bsd-3-clause | 187 | master | 1,130 | require 'rails_helper'
# Uses the nifty shoulda-matchers
# https://github.com/thoughtbot/shoulda-matchers
describe ApiApplication do
it { is_expected.to belong_to :user }
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_presence_of(:main_url) }
it 'validates uniqueness of name an... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/models/organization_spec.rb | Ruby | bsd-3-clause | 187 | master | 4,587 | require 'rails_helper'
describe Organization do
subject { build(:organization) }
it { is_expected.to be_valid }
it { is_expected.to have_many(:locations).dependent(:destroy) }
it { is_expected.to have_many(:programs).dependent(:destroy) }
it { is_expected.to have_many(:contacts).dependent(:destroy) }
it... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/seeds.rb | Ruby | bsd-3-clause | 187 | master | 1,880 | # This file should contain all the record creation needed to seed the database
# with its default values. The data can then be loaded with rake db:seed
# (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel',... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20141027154101_create_regular_schedules.rb | Ruby | bsd-3-clause | 187 | master | 416 | class CreateRegularSchedules < ActiveRecord::Migration
def change
create_table :regular_schedules do |t|
t.integer :weekday
t.time :opens_at
t.time :closes_at
t.references :service, index: true
t.references :location, index: true
end
add_index :regular_schedules, :weekday
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20141024022657_create_programs.rb | Ruby | bsd-3-clause | 187 | master | 259 | class CreatePrograms < ActiveRecord::Migration
def change
create_table :programs do |t|
t.belongs_to :organization
t.string :name
t.string :alternate_name
t.timestamps
end
add_index :programs, :organization_id
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140328041648_create_api_applications.rb | Ruby | bsd-3-clause | 187 | master | 365 | class CreateApiApplications < ActiveRecord::Migration
def change
create_table :api_applications do |t|
t.belongs_to :user
t.text :name
t.text :main_url
t.text :callback_url
t.text :api_token
t.timestamps
end
add_index :api_applications, :user_id
add_index :api_appl... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20141010155451_drop_faxes_table.rb | Ruby | bsd-3-clause | 187 | master | 275 | class DropFaxesTable < ActiveRecord::Migration
def up
drop_table :faxes
end
def down
create_table :faxes do |t|
t.belongs_to :location
t.text :number
t.text :department
t.timestamps
end
add_index :faxes, :location_id
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20141030204742_add_array_fields_to_organization.rb | Ruby | bsd-3-clause | 187 | master | 325 | class AddArrayFieldsToOrganization < ActiveRecord::Migration
def change
add_column :organizations, :funding_sources, :string, array: true, default: []
add_column :organizations, :accreditations, :string, array: true, default: []
add_column :organizations, :licenses, :string, array: true, default: []
end... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140328044447_create_categories.rb | Ruby | bsd-3-clause | 187 | master | 241 | class CreateCategories < ActiveRecord::Migration
def change
create_table :categories do |t|
t.text :name
t.text :oe_id
t.text :slug
t.timestamps
end
add_index :categories, :slug, unique: true
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140328042359_create_phones.rb | Ruby | bsd-3-clause | 187 | master | 291 | class CreatePhones < ActiveRecord::Migration
def change
create_table :phones do |t|
t.belongs_to :location
t.text :number
t.text :department
t.text :extension
t.text :vanity_number
t.timestamps
end
add_index :phones, :location_id
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140929221750_add_fields_to_organization.rb | Ruby | bsd-3-clause | 187 | master | 556 | class AddFieldsToOrganization < ActiveRecord::Migration
def change
add_column :organizations, :alternate_name, :string
add_column :organizations, :date_incorporated, :date
add_column :organizations, :description, :text, null: false
add_column :organizations, :email, :string
add_column :organizatio... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20141109022202_add_email_index_to_locations.rb | Ruby | bsd-3-clause | 187 | master | 270 | class AddEmailIndexToLocations < ActiveRecord::Migration
def up
execute "CREATE INDEX locations_email_with_varchar_pattern_ops ON locations (email varchar_pattern_ops);"
end
def down
execute "DROP INDEX locations_email_with_varchar_pattern_ops"
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140829154350_add_search_indexes_to_services.rb | Ruby | bsd-3-clause | 187 | master | 255 | class AddSearchIndexesToServices < ActiveRecord::Migration
def up
execute "create index services_service_areas on services using gin(to_tsvector('english', service_areas))"
end
def down
execute "drop index services_service_areas"
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20141009185459_add_fields_to_address.rb | Ruby | bsd-3-clause | 187 | master | 281 | class AddFieldsToAddress < ActiveRecord::Migration
def change
add_column :addresses, :country_code, :string, null: false
add_column :addresses, :street_2, :string
rename_column :addresses, :zip, :postal_code
rename_column :addresses, :street, :street_1
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20141009204519_add_fields_to_mail_address.rb | Ruby | bsd-3-clause | 187 | master | 305 | class AddFieldsToMailAddress < ActiveRecord::Migration
def change
add_column :mail_addresses, :country_code, :string, null: false
add_column :mail_addresses, :street_2, :string
rename_column :mail_addresses, :zip, :postal_code
rename_column :mail_addresses, :street, :street_1
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140328052427_create_friendly_id_slugs.rb | Ruby | bsd-3-clause | 187 | master | 535 | class CreateFriendlyIdSlugs < ActiveRecord::Migration
def self.up
create_table :friendly_id_slugs do |t|
t.string :slug, :null => false
t.integer :sluggable_id, :null => false
t.string :sluggable_type, :limit => 40
t.datetime :created_at
end
add_index :friendly_id... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20150314204202_rename_fields.rb | Ruby | bsd-3-clause | 187 | master | 577 | class RenameFields < ActiveRecord::Migration
def change
rename_column :services, :how_to_apply, :application_process
rename_column :addresses, :street_1, :address_1
rename_column :addresses, :street_2, :address_2
rename_column :addresses, :state, :state_province
rename_column :addresses, :country_... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140328035528_create_users.rb | Ruby | bsd-3-clause | 187 | master | 1,387 | class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
t.string :name, null: false, default: ""
## Recov... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20141017154640_add_fields_to_services.rb | Ruby | bsd-3-clause | 187 | master | 744 | class AddFieldsToServices < ActiveRecord::Migration
def change
add_column :services, :accepted_payments, :string, array: true, default: []
add_column :services, :alternate_name, :string
add_column :services, :email, :string
add_column :services, :languages, :string, array: true, default: []
add_co... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140505011725_add_search_vector_to_locations.rb | Ruby | bsd-3-clause | 187 | master | 2,586 | class AddSearchVectorToLocations < ActiveRecord::Migration
def up
add_column :locations, :tsv_body, :tsvector
add_index :locations, :tsv_body, using: 'gin'
execute <<-SQL
CREATE OR REPLACE FUNCTION fill_search_vector_for_location() RETURNS trigger LANGUAGE plpgsql AS $$
declare
locat... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140328034754_create_locations.rb | Ruby | bsd-3-clause | 187 | master | 631 | class CreateLocations < ActiveRecord::Migration
def change
create_table :locations do |t|
t.belongs_to :organization
t.text :accessibility
t.text :admin_emails
t.text :description
t.text :emails
t.text :hours
t.text :kind
t.float :latitude
t.float :longitude
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140508030926_add_search_index_to_organizations.rb | Ruby | bsd-3-clause | 187 | master | 246 | class AddSearchIndexToOrganizations < ActiveRecord::Migration
def up
execute "create index organizations_name on organizations using gin(to_tsvector('english', name))"
end
def down
execute "drop index organizations_name"
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140629181523_devise_create_admins.rb | Ruby | bsd-3-clause | 187 | master | 1,309 | class DeviseCreateAdmins < ActiveRecord::Migration
def change
create_table(:admins) do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
t.string :name, null: false, default: ""
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140402222453_create_categories_services.rb | Ruby | bsd-3-clause | 187 | master | 386 | class CreateCategoriesServices < ActiveRecord::Migration
def change
create_table :categories_services, id: false do |t|
t.belongs_to :category, null: false
t.belongs_to :service, null: false
end
add_index(:categories_services, [:service_id, :category_id], unique: true)
add_index(:categori... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140328034023_create_addresses.rb | Ruby | bsd-3-clause | 187 | master | 280 | class CreateAddresses < ActiveRecord::Migration
def change
create_table :addresses do |t|
t.belongs_to :location
t.text :street
t.text :city
t.text :state
t.text :zip
t.timestamps
end
add_index :addresses, :location_id
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140508030435_add_search_indexes_to_locations.rb | Ruby | bsd-3-clause | 187 | master | 973 | class AddSearchIndexesToLocations < ActiveRecord::Migration
def up
execute "create index locations_name on locations using gin(to_tsvector('english', name))"
execute "create index locations_description on locations using gin(to_tsvector('english', description))"
execute "create index locations_admin_email... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140328043104_create_services.rb | Ruby | bsd-3-clause | 187 | master | 483 | class CreateServices < ActiveRecord::Migration
def change
create_table :services do |t|
t.belongs_to :location
t.text :audience
t.text :description
t.text :eligibility
t.text :fees
t.text :how_to_apply
t.text :name
t.text :short_desc
t.text :urls
t.text ... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140909031145_convert_languages_to_array_type.rb | Ruby | bsd-3-clause | 187 | master | 915 | class ConvertLanguagesToArrayType < ActiveRecord::Migration
def up
execute "drop index locations_languages"
change_column :locations, :languages, "text[] USING (string_to_array(languages, '\n- '))", default: []
add_index :locations, :languages, using: 'gin'
Location.find_each do |loc|
clean_lan... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20141030012617_create_holiday_schedules.rb | Ruby | bsd-3-clause | 187 | master | 370 | class CreateHolidaySchedules < ActiveRecord::Migration
def change
create_table :holiday_schedules do |t|
t.references :location, index: true
t.references :service, index: true
t.boolean :closed, null: false
t.date :start_date, null: false
t.date :end_date, null: false
t.time :o... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140508031024_add_search_index_to_categories.rb | Ruby | bsd-3-clause | 187 | master | 234 | class AddSearchIndexToCategories < ActiveRecord::Migration
def up
execute "create index categories_name on categories using gin(to_tsvector('english', name))"
end
def down
execute "drop index categories_name"
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20180212023953_convert_admin_emails_to_array.rb | Ruby | bsd-3-clause | 187 | master | 967 | class ConvertAdminEmailsToArray < ActiveRecord::Migration[5.0]
def up
execute "drop index locations_admin_emails"
change_column :locations, :admin_emails, "text[] USING (string_to_array(admin_emails, '\n- '))", default: []
add_index :locations, :admin_emails, using: 'gin'
Location.find_each do |loc|
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20141010171020_update_contact_fields.rb | Ruby | bsd-3-clause | 187 | master | 259 | class UpdateContactFields < ActiveRecord::Migration
def change
add_column :contacts, :department, :string
remove_column :contacts, :fax, :string
remove_column :contacts, :phone, :string
remove_column :contacts, :extension, :string
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140328034531_create_organizations.rb | Ruby | bsd-3-clause | 187 | master | 249 | class CreateOrganizations < ActiveRecord::Migration
def change
create_table :organizations do |t|
t.text :name
t.text :urls
t.text :slug
t.timestamps
end
add_index :organizations, :slug, unique: true
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140508194831_update_search_vector_migration.rb | Ruby | bsd-3-clause | 187 | master | 2,823 | require_relative '20140505011725_add_search_vector_to_locations'
class UpdateSearchVectorMigration < ActiveRecord::Migration
def change
revert AddSearchVectorToLocations
add_column :locations, :tsv_body, :tsvector
add_index :locations, :tsv_body, using: 'gin'
reversible do |dir|
dir.up do
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140328042108_create_faxes.rb | Ruby | bsd-3-clause | 187 | master | 236 | class CreateFaxes < ActiveRecord::Migration
def change
create_table :faxes do |t|
t.belongs_to :location
t.text :number
t.text :department
t.timestamps
end
add_index :faxes, :location_id
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20141108214741_add_website_index_to_locations.rb | Ruby | bsd-3-clause | 187 | master | 278 | class AddWebsiteIndexToLocations < ActiveRecord::Migration
def up
execute "CREATE INDEX locations_website_with_varchar_pattern_ops ON locations (website varchar_pattern_ops);"
end
def down
execute "DROP INDEX locations_website_with_varchar_pattern_ops"
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140328041859_create_contacts.rb | Ruby | bsd-3-clause | 187 | master | 320 | class CreateContacts < ActiveRecord::Migration
def change
create_table :contacts do |t|
t.belongs_to :location
t.text :name
t.text :title
t.text :email
t.text :fax
t.text :phone
t.text :extension
t.timestamps
end
add_index :contacts, :location_id
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | db/migrate/20140328042218_create_mail_addresses.rb | Ruby | bsd-3-clause | 187 | master | 318 | class CreateMailAddresses < ActiveRecord::Migration
def change
create_table :mail_addresses do |t|
t.belongs_to :location
t.text :attention
t.text :street
t.text :city
t.text :state
t.text :zip
t.timestamps
end
add_index :mail_addresses, :location_id
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/category_presenter.rb | Ruby | bsd-3-clause | 187 | master | 622 | CategoryPresenter = Struct.new(:row) do
def to_category
return Category.create(category_params) if row[:parent_id].blank?
return parent_category unless parent_category.valid?
child_category
end
def parent_category
@parent_category ||= Category.find_or_create_by(name: row[:parent_name],
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/organization_importer.rb | Ruby | bsd-3-clause | 187 | master | 666 | class OrganizationImporter < EntityImporter
def valid?
@valid ||= organizations.all?(&:valid?)
end
def errors
ImporterErrors.messages_for(organizations)
end
def import
ActiveRecord::Base.no_touching do
organizations.each(&:save)
end
end
def self.required_headers
%w[id accredit... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/program_presenter.rb | Ruby | bsd-3-clause | 187 | master | 233 | ProgramPresenter = Struct.new(:row) do
include ParentAssigner
def to_program
program = Program.find_or_initialize_by(id: row[:id].to_i)
program.attributes = row
assign_parents_for(program, row)
program
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/location_presenter.rb | Ruby | bsd-3-clause | 187 | master | 1,108 | LocationPresenter = Struct.new(:row, :addresses) do
include EntityPresenter
include ParentAssigner
def to_location
location = Location.find_or_initialize_by(id: row[:id].to_i)
transform_fields(location, row)
location.attributes = row
assign_parents_for(location, row)
location
end
def tra... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/mail_address_presenter.rb | Ruby | bsd-3-clause | 187 | master | 266 | MailAddressPresenter = Struct.new(:row) do
include ParentAssigner
def to_mail_address
mail_address = MailAddress.find_or_initialize_by(id: row[:id].to_i)
mail_address.attributes = row
assign_parents_for(mail_address, row)
mail_address
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/entity_importer.rb | Ruby | bsd-3-clause | 187 | master | 600 | require 'csv'
EntityImporter = Struct.new(:path) do
def self.import_file(path)
new(path).tap(&:import)
end
def self.check_and_import_file(path)
check = FileChecker.new(path, required_headers).validate
return if check == 'skip import'
Kernel.puts("\n===> Importing #{path.to_s.split('/').last}")... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/file_checker.rb | Ruby | bsd-3-clause | 187 | master | 1,530 | class FileChecker
def initialize(path, required_headers)
@path = path
@required_headers = required_headers
end
def validate
return 'skip import' if missing_or_empty_but_not_required?
if missing_or_empty?
abort "Aborting because #{filename} is required, but is missing or empty."
elsif i... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/asset_hosts.rb | Ruby | bsd-3-clause | 187 | master | 720 | class AssetHosts
def call(_source, request = nil)
return if request.nil?
@request = request
return asset_host_with_port if host_same_as_asset_host? || unauthorized_host?
"#{subdomain}#{asset_host_with_port}"
end
private
attr_reader :request
def asset_host_with_port
"#{asset_host}#{por... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/category_importer.rb | Ruby | bsd-3-clause | 187 | master | 541 | class CategoryImporter < EntityImporter
def valid?
@valid ||= categories.all?(&:valid?)
end
def errors
ImporterErrors.messages_for(categories)
end
def import
ActiveRecord::Base.no_touching do
categories.each(&:save)
end
end
def self.required_headers
%w[taxonomy_id name parent_... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/program_importer.rb | Ruby | bsd-3-clause | 187 | master | 528 | class ProgramImporter < EntityImporter
def valid?
@valid ||= programs.all?(&:valid?)
end
def errors
ImporterErrors.messages_for(programs)
end
def import
ActiveRecord::Base.no_touching do
programs.each(&:save)
end
end
def self.required_headers
%w[id organization_id name alterna... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/email_filter.rb | Ruby | bsd-3-clause | 187 | master | 843 | class EmailFilter
class << self
delegate :call, to: :new
end
def initialize(model_class = Location)
@model_class = model_class
end
def call(email)
return @model_class.all if email.blank?
return @model_class.none unless email.include?('@')
return match_generic_email(email) if SETTINGS[:ge... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/service_importer.rb | Ruby | bsd-3-clause | 187 | master | 706 | class ServiceImporter < EntityImporter
def valid?
@valid ||= services.all?(&:valid?)
end
def errors
ImporterErrors.messages_for(services)
end
def import
ActiveRecord::Base.no_touching do
services.each(&:save)
end
end
def self.required_headers
%w[id location_id program_id accep... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/contact_presenter.rb | Ruby | bsd-3-clause | 187 | master | 233 | ContactPresenter = Struct.new(:row) do
include ParentAssigner
def to_contact
contact = Contact.find_or_initialize_by(id: row[:id].to_i)
contact.attributes = row
assign_parents_for(contact, row)
contact
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/default_host.rb | Ruby | bsd-3-clause | 187 | master | 220 | class DefaultHost
def call(request)
host = request.host
return host if host.end_with?(default_host)
default_host
end
private
def default_host
@default_host ||= Figaro.env.domain_name
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/entity_presenter.rb | Ruby | bsd-3-clause | 187 | master | 229 | module EntityPresenter
def to_array(row, *fields)
fields.each do |field|
row[field] =
if row[field].blank?
[]
else
row[field].split(',').map(&:squish)
end
end
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/mail_address_importer.rb | Ruby | bsd-3-clause | 187 | master | 624 | class MailAddressImporter < EntityImporter
def valid?
@valid ||= mail_addresses.all?(&:valid?)
end
def errors
ImporterErrors.messages_for(mail_addresses)
end
def import
ActiveRecord::Base.no_touching do
mail_addresses.each(&:save)
end
end
def self.required_headers
%w[id locati... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/parent_assigner.rb | Ruby | bsd-3-clause | 187 | master | 300 | module ParentAssigner
private
def assign_parents_for(record, row)
foreign_keys_in(row).each do |key|
next if row[key].nil?
record[key] = row[key].to_i
end
end
def foreign_keys_in(row)
row.keys.select { |key| key.to_s == 'id' || key.to_s.include?('_id') }
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/phone_presenter.rb | Ruby | bsd-3-clause | 187 | master | 219 | PhonePresenter = Struct.new(:row) do
include ParentAssigner
def to_phone
phone = Phone.find_or_initialize_by(id: row[:id].to_i)
phone.attributes = row
assign_parents_for(phone, row)
phone
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/phone_importer.rb | Ruby | bsd-3-clause | 187 | master | 602 | class PhoneImporter < EntityImporter
def valid?
@valid ||= phones.all?(&:valid?)
end
def errors
ImporterErrors.messages_for(phones)
end
def import
ActiveRecord::Base.no_touching do
phones.each(&:save)
end
end
def self.required_headers
%w[id location_id organization_id service_... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/address_extractor.rb | Ruby | bsd-3-clause | 187 | master | 216 | AddressExtractor = Struct.new(:path) do
def self.extract_addresses(path)
new(path).csv_entries
end
def csv_entries
@csv_entries ||= SmarterCSV.process(path, convert_values_to_numeric: false)
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/location_importer.rb | Ruby | bsd-3-clause | 187 | master | 1,768 | LocationImporter = Struct.new(:path, :addresses) do
def self.import_file(path, addresses_path)
new(path, addresses_for(addresses_path)).tap(&:import)
end
def self.check_and_import_file(locations_path, addresses_path)
FileChecker.new(locations_path, required_headers).validate
process_import(locations... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/location_filter.rb | Ruby | bsd-3-clause | 187 | master | 1,130 | require 'exceptions'
class LocationFilter
class << self
delegate :call, to: :new
end
def initialize(model_class = Location)
@model_class = model_class
end
def call(location, lat_lng, radius)
return @model_class.all if location.blank? && lat_lng.blank? && radius.blank?
@model_class.near(coo... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/config_validator.rb | Ruby | bsd-3-clause | 187 | master | 675 | class ConfigValidator
KEYS_THAT_CANNOT_BE_EMPTY = %w[
ASSET_HOST
DEFAULT_PER_PAGE
DOMAIN_NAME
MAX_PER_PAGE
].freeze
def initialize(env = ENV)
@env = env
end
def validate
validate_non_empty_required_keys
end
private
attr_reader :env
def validate_non_empty_required_keys
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/holiday_schedule_importer.rb | Ruby | bsd-3-clause | 187 | master | 638 | class HolidayScheduleImporter < EntityImporter
def valid?
@valid ||= holiday_schedules.all?(&:valid?)
end
def errors
ImporterErrors.messages_for(holiday_schedules)
end
def import
ActiveRecord::Base.no_touching do
holiday_schedules.each(&:save)
end
end
def self.required_headers
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/api_constraints.rb | Ruby | bsd-3-clause | 187 | master | 444 | class ApiConstraints
def initialize(options)
@version = options[:version]
end
def matches?(request)
versioned_accept_header?(request) || @version == 1
end
private
def versioned_accept_header?(request)
accept = request.headers['Accept']
return false if accept.blank?
mime_type, version... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/regular_schedule_presenter.rb | Ruby | bsd-3-clause | 187 | master | 294 | RegularSchedulePresenter = Struct.new(:row) do
include ParentAssigner
def to_regular_schedule
regular_schedule = RegularSchedule.find_or_initialize_by(id: row[:id].to_i)
regular_schedule.attributes = row
assign_parents_for(regular_schedule, row)
regular_schedule
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/contact_importer.rb | Ruby | bsd-3-clause | 187 | master | 566 | class ContactImporter < EntityImporter
def valid?
@valid ||= contacts.all?(&:valid?)
end
def errors
ImporterErrors.messages_for(contacts)
end
def import
ActiveRecord::Base.no_touching do
contacts.each(&:save)
end
end
def self.required_headers
%w[id location_id organization_id ... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/service_presenter.rb | Ruby | bsd-3-clause | 187 | master | 719 | ServicePresenter = Struct.new(:row) do
include EntityPresenter
include ParentAssigner
include CategoryIdCollector
# rubocop:disable Metrics/AbcSize
def to_service
service = Service.find_or_initialize_by(id: row[:id].to_i)
to_array(row, :accepted_payments, :funding_sources, :keywords, :languages,
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/subdomain_constraints.rb | Ruby | bsd-3-clause | 187 | master | 274 | class SubdomainConstraints
def initialize(options)
@subdomain = options[:subdomain]
end
def matches?(request)
if @subdomain.present?
request.subdomain == @subdomain
else
request.subdomain.blank? || request.subdomain == 'www'
end
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/importer_errors.rb | Ruby | bsd-3-clause | 187 | master | 381 | ImporterErrors = Struct.new(:record, :line_number) do
def self.messages_for(records = [])
records.each_with_index.filter_map do |record, index|
new(record, index + 2).message
end
end
def message
"Line #{line_number}: #{error_messages}" unless record.valid?
end
protected
def error_messag... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/organization_presenter.rb | Ruby | bsd-3-clause | 187 | master | 282 | OrganizationPresenter = Struct.new(:row) do
include EntityPresenter
def to_org
org = Organization.find_or_initialize_by(id: row[:id].to_i)
to_array(row, :accreditations, :licenses, :funding_sources)
org.attributes = row
org.id = row[:id].to_i
org
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/holiday_schedule_presenter.rb | Ruby | bsd-3-clause | 187 | master | 294 | HolidaySchedulePresenter = Struct.new(:row) do
include ParentAssigner
def to_holiday_schedule
holiday_schedule = HolidaySchedule.find_or_initialize_by(id: row[:id].to_i)
holiday_schedule.attributes = row
assign_parents_for(holiday_schedule, row)
holiday_schedule
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/regular_schedule_importer.rb | Ruby | bsd-3-clause | 187 | master | 612 | class RegularScheduleImporter < EntityImporter
def valid?
@valid ||= regular_schedules.all?(&:valid?)
end
def errors
ImporterErrors.messages_for(regular_schedules)
end
def import
ActiveRecord::Base.no_touching do
regular_schedules.each(&:save)
end
end
def self.required_headers
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/tasks/import.rake | Ruby | bsd-3-clause | 187 | master | 2,885 | namespace :import do
task all: %i[organizations programs locations taxonomy services
mail_addresses contacts phones regular_schedules
holiday_schedules touch_locations]
desc 'Imports organizations'
task :organizations, [:path] => :environment do |_, args|
args.with_defaults(path... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/tasks/oe.rake | Ruby | bsd-3-clause | 187 | master | 828 | require 'json'
task create_categories: :environment do
Kernel.puts 'Creating categories based on OpenEligibility Taxonomy...'
json ||= JSON.parse(File.read('data/oe.json'))
top_levels ||= json['taxonomy']['top_level']
top_levels.each do |hash|
top_level = Category.create!(name: hash['@title'], taxonomy_... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/tasks/remove_test_users_and_admins.rake | Ruby | bsd-3-clause | 187 | master | 274 | task remove_test_users_and_admins: :environment do
User.includes(:api_applications).
where(email: %w[user@example.com user2@example.com]).destroy_all
Admin.
where(email: %w[ohana@samaritanhouse.com ohana@gmail.com masteradmin@ohanapi.org]).
destroy_all
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | lib/tasks/taxonomy.rake | Ruby | bsd-3-clause | 187 | master | 897 | require 'csv'
task oe_csv: :environment do
Kernel.puts 'Creating taxonomy.csv based on Open Eligibility...'
json ||= JSON.parse(File.read('data/oe.json'))
top_levels ||= json['taxonomy']['top_level']
CSV.open(
'data/taxonomy.csv',
'w',
write_headers: true,
headers: %w[taxonomy_id name parent... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/application.rb | Ruby | bsd-3-clause | 187 | master | 2,476 | require_relative 'boot'
# Pick the frameworks you want:
require 'active_record/railtie'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'sprockets/railtie'
require 'yaml'
SETTINGS = YAML.safe_load(File.read(File.expand_path('settings.yml', __dir__)))
SETTINGS.merge! SETTINGS.fetch(Rails.en... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/routes.rb | Ruby | bsd-3-clause | 187 | master | 3,827 | require 'api_constraints'
require 'subdomain_constraints'
Rails.application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
# See how all your routes lay out with 'rake routes'.
# Read more about routing: http://guides.rubyonrails.org/routing.html
devise_f... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/puma.rb | Ruby | bsd-3-clause | 187 | master | 1,501 | # Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/environments/production.rb | Ruby | bsd-3-clause | 187 | master | 4,763 | Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# This setting enables the use of subdomains on Heroku.
# See config/settings.yml for more details.
config.action_dispatch.tld_length = ENV['TLD_LENGTH'].to_i
# Code is not reloaded between req... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/environments/test.rb | Ruby | bsd-3-clause | 187 | master | 2,863 | Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suit... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/environments/development.rb | Ruby | bsd-3-clause | 187 | master | 2,898 | Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web serv... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/initializers/geocoder.rb | Ruby | bsd-3-clause | 187 | master | 329 | Geocoder.configure(
lookup: :google,
api_key: ENV.fetch('GOOGLE_GEOCODING_API_KEY', nil),
http_proxy: ENV.fetch('QUOTAGUARD_URL', nil),
use_https: true,
cache: Rails.cache,
always_raise: [
Geocoder::OverQueryLimitError,
Geocoder::RequestDenied,
Geocoder::InvalidRequest,
Geocoder::InvalidApiK... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/initializers/backtrace_silencers.rb | Ruby | bsd-3-clause | 187 | master | 408 | # Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't
# wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a pro... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/initializers/assets.rb | Ruby | bsd-3-clause | 187 | master | 617 | # Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path
# Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules ... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/initializers/kaminari.rb | Ruby | bsd-3-clause | 187 | master | 343 | module Kaminari
# Kaminar's built-in methods for getting the next page
# and determining if a page is the last page are wrong,
# so I'm overriding them.
module PageScopeMethods
def next_page
current_page < total_pages ? (current_page + 1) : nil
end
def last_page?
current_page == total_p... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/initializers/kaminari_config.rb | Ruby | bsd-3-clause | 187 | master | 271 | # See Kaminari README for more details about config options:
# https://github.com/amatsuda/kaminari#general-configuration-options
Kaminari.configure do |config|
config.default_per_page = ENV['DEFAULT_PER_PAGE'].to_i
config.max_per_page = ENV['MAX_PER_PAGE'].to_i
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/initializers/secret_token.rb | Ruby | bsd-3-clause | 187 | master | 1,080 | # Be sure to restart your server when you modify this file.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to diction... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/initializers/friendly_id.rb | Ruby | bsd-3-clause | 187 | master | 3,215 | # FriendlyId Global Configuration
#
# Use this to set up shared configuration options for your entire application.
# Any of the configuration options shown here can also be applied to single
# models by passing arguments to the `friendly_id` class method or defining
# methods in your model.
#
# To learn more, check out... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/initializers/devise.rb | Ruby | bsd-3-clause | 187 | master | 12,518 | # Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use yo... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/initializers/figaro.rb | Ruby | bsd-3-clause | 187 | master | 466 | require Rails.root.join('lib/config_validator.rb')
# Define the environment variables that should be set in config/application.yml.
# See config/application.example.yml if you don't have config/application.yml.
Figaro.require_keys('API_PATH') if ENV['API_SUBDOMAIN'].blank?
Figaro.require_keys('ADMIN_PATH') if ENV['ADM... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | config/initializers/filter_parameter_logging.rb | Ruby | bsd-3-clause | 187 | master | 237 | # Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += %i[
password password_confirmation api_token email
] |
github | yayugu/net-radio-archive | https://github.com/yayugu/net-radio-archive | Gemfile | Ruby | mit | 187 | master | 1,413 | source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.10'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use... |
github | yayugu/net-radio-archive | https://github.com/yayugu/net-radio-archive | test/models/onsen_program_test.rb | Ruby | mit | 187 | master | 365 | require 'test_helper'
class OnsenProgramTest < ActiveSupport::TestCase
test "save" do
p = OnsenProgram.new
p.title = 'onsen test title'
p.number = 1
p.date = DateTime.now
p.file_url = 'http://test.onsen_program.com'
p.personality = '花澤香菜'
p.state = OnsenProgram::STATE[:waiting]
assert... |
github | yayugu/net-radio-archive | https://github.com/yayugu/net-radio-archive | test/models/hibiki_program_test.rb | Ruby | mit | 187 | master | 356 | require 'test_helper'
class HibikiProgramTest < ActiveSupport::TestCase
test "save" do
p = HibikiProgram.new
p.title = 'hibiki test title'
p.comment = '第123回 1月23日更新!'
p.rtmp_url = 'rtmpe://test.hibiki_program'
p.state = HibikiProgram::STATE[:waiting]
p.retry_count = 0
assert p.save, p.er... |
github | yayugu/net-radio-archive | https://github.com/yayugu/net-radio-archive | test/models/job_test.rb | Ruby | mit | 187 | master | 295 | require 'test_helper'
class JobTest < ActiveSupport::TestCase
test "save ag" do
job = Job.new(
ch: Job::CH[:ag],
title: 'test ag',
start: Date.today,
end: Date.today + 1,
state: Job::STATE[:scheduled]
)
assert job.save, job.errors.messages
end
end |
github | yayugu/net-radio-archive | https://github.com/yayugu/net-radio-archive | niconico/niconico.gemspec | Ruby | mit | 187 | master | 696 | # -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "niconico/version"
Gem::Specification.new do |s|
s.name = "niconico"
s.version = Niconico::VERSION
s.authors = ["Shota Fukumori (sora_h)"]
s.email = ["her@sorah.jp"]
s.homepage = ""
s.summary = "wrapp... |
github | yayugu/net-radio-archive | https://github.com/yayugu/net-radio-archive | niconico/lib/niconico.rb | Ruby | mit | 187 | master | 2,885 | # -*- coding: utf-8 -*-
require 'mechanize'
require 'cgi'
require 'niconico/version'
class Niconico
URL = {
top: 'http://www.nicovideo.jp/',
login: 'https://secure.nicovideo.jp/secure/login?site=niconico',
watch: 'http://www.nicovideo.jp/watch/',
getflv: 'http://flapi.nicovideo.jp/api/getflv',
m... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.