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 | a-chacon/oas_rails | https://github.com/a-chacon/oas_rails | lib/oas_rails/builders/esquema_builder.rb | Ruby | mit | 187 | main | 2,477 | module OasRails
module Builders
module EsquemaBuilder
class << self
# Builds a schema for a class when it is used as incoming API data.
#
# @param klass [Class] The class for which the schema is built.
# @return [Hash] The schema as a JSON-compatible hash.
def build_i... |
github | a-chacon/oas_rails | https://github.com/a-chacon/oas_rails | lib/oas_rails/extractors/render_response_extractor.rb | Ruby | mit | 187 | main | 6,605 | module OasRails
module Extractors
# Extracts and processes render responses from a given source.
module RenderResponseExtractor
class << self
# Extracts responses from the provided source string.
#
# @param source [String] The source string containing render calls.
# @ret... |
github | a-chacon/oas_rails | https://github.com/a-chacon/oas_rails | lib/oas_rails/extractors/route_extractor.rb | Ruby | mit | 187 | main | 3,902 | module OasRails
module Extractors
class RouteExtractor
RAILS_DEFAULT_CONTROLLERS = %w[
rails
action_mailbox
action_cable
active_storage
turbo/native
].freeze
class << self
def host_routes_by_path(path)
@host_routes ||= extract_host_route... |
github | a-chacon/oas_rails | https://github.com/a-chacon/oas_rails | app/helpers/oas_rails/oas_rails_helper.rb | Ruby | mit | 187 | main | 4,053 | module OasRails
module OasRailsHelper # rubocop:disable Metrics/ModuleLength
def rapidoc_configuration_defaults
{
"spec-url" => "#{OasRails::Engine.routes.find_script_name(params.permit!.to_h.symbolize_keys)}.json",
"show-header" => "false",
"font-size" => "largest",
"show-me... |
github | a-chacon/oas_rails | https://github.com/a-chacon/oas_rails | app/controllers/oas_rails/oas_rails_controller.rb | Ruby | mit | 187 | main | 419 | module OasRails
class OasRailsController < ApplicationController
# Include URL help if the layout is a user-customized layout.
include Rails.application.routes.url_helpers
def index
respond_to do |format|
format.html { render "index", layout: OasRails.config.layout }
format.json do
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | Rakefile | Ruby | bsd-3-clause | 187 | master | 247 | # Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically
# be available to Rake.
require File.expand_path('config/application', __dir__)
Rails.application.load_tasks |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | Gemfile | Ruby | bsd-3-clause | 187 | master | 1,749 | source 'https://rubygems.org'
ruby '2.7.5'
gem 'active_model_serializers', '~> 0.8.0'
gem 'ancestry'
gem 'auto_strip_attributes', '~> 2.0'
gem 'bootstrap-sass', '~> 3.4.0'
gem 'coffee-rails', '~> 4.1'
gem 'csv_shaper'
gem 'dalli', '~> 2.7'
gem 'devise', '~> 4.1'
gem 'enumerize'
gem 'figaro', '~> 1.0'
gem 'friendly_id'... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/mailers/admin_mailer.rb | Ruby | bsd-3-clause | 187 | master | 1,543 | class AdminMailer < ApplicationMailer
default from: SETTINGS[:confirmation_email]
def existing_email_signup(resource)
@portal = portal_for(resource)
@sign_in_url = sign_in_url_for(resource)
@sign_up_url = sign_up_url_for(resource)
@password_url = password_url_for(resource)
mail(to: resource.ema... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/mailers/custom_mailer.rb | Ruby | bsd-3-clause | 187 | master | 451 | class CustomMailer < Devise::Mailer
def confirmation_instructions(record, token, options = {})
options[:template_path] = template_path(record)
super
end
def reset_password_instructions(record, token, options = {})
options[:template_path] = template_path(record)
super
end
private
def templ... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/policies/organization_policy.rb | Ruby | bsd-3-clause | 187 | master | 251 | class OrganizationPolicy < ApplicationPolicy
class Scope < Scope
def resolve
return scope.pluck(:id, :name, :slug).sort_by(&:second) if user.super_admin?
scope.with_locations(location_ids).pluck(:id, :name, :slug)
end
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/policies/application_policy.rb | Ruby | bsd-3-clause | 187 | master | 851 | class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
@user = user
@record = record
end
def create?
return true if user.super_admin?
scope.flatten.include?(record.id)
end
def scope
Pundit.policy_scope!(user, record.class)
end
alias new? create?
alias ... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/policies/program_policy.rb | Ruby | bsd-3-clause | 187 | master | 537 | class ProgramPolicy < ApplicationPolicy
delegate :create?, to: :organization_policy
def new?
can_access_at_least_one_organization?
end
private
def organization_policy
@organization_policy ||= Pundit.policy!(user, record.organization)
end
class Scope < Scope
def resolve
return scope.p... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/policies/contact_policy.rb | Ruby | bsd-3-clause | 187 | master | 234 | class ContactPolicy < ApplicationPolicy
delegate :create?, :destroy?, :edit?, :update?, to: :organization_policy
private
def organization_policy
@organization_policy ||= Pundit.policy!(user, record.organization)
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/policies/location_policy.rb | Ruby | bsd-3-clause | 187 | master | 378 | class LocationPolicy < ApplicationPolicy
def new?
return true if user.super_admin?
return super if record.id.present?
can_access_at_least_one_organization?
end
class Scope < Scope
def resolve
return scope.pluck(:id, :name, :slug).sort_by(&:second) if user.super_admin?
scope.with_ema... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/policies/service_policy.rb | Ruby | bsd-3-clause | 187 | master | 259 | class ServicePolicy < ApplicationPolicy
class Scope < Scope
def resolve
return scope.pluck(:location_id, :id, :name).sort_by(&:third) if user.super_admin?
scope.with_locations(location_ids).pluck(:location_id, :id, :name)
end
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/validators/regex_validator.rb | Ruby | bsd-3-clause | 187 | master | 229 | class RegexValidator < ActiveModel::EachValidator
def regex_validate_each(regex, err_msg, record, attribute, value)
return if value&.match?(regex)
record.errors.add(attribute, (options[:message] || err_msg))
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/validators/weekday_validator.rb | Ruby | bsd-3-clause | 187 | master | 1,321 | class WeekdayValidator < ActiveModel::EachValidator
WEEKDAY_ABBREVIATIONS = %w[Sun Mon Tue Wed Thu Fri Sat].freeze
WEEKDAY_STRING_NUMS = %w[1 2 3 4 5 6 7].freeze
def validate_each(record, attribute, _value)
value = record.read_attribute_before_type_cast(attribute)
default_message = "#{value} #{I18n.t('e... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/validators/state_province_validator.rb | Ruby | bsd-3-clause | 187 | master | 432 | class StateProvinceValidator < ActiveModel::EachValidator
COUNTRIES_NEEDING_VALIDATION = %w[US CA].freeze
def validate_each(record, attribute, value)
return unless COUNTRIES_NEEDING_VALIDATION.include?(record.country)
default_message = I18n.t('errors.messages.invalid_state_province')
return if value.... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/validators/url_validator.rb | Ruby | bsd-3-clause | 187 | master | 352 | class UrlValidator < RegexValidator
def validate_each(record, attribute, value)
default_message = "#{value} #{I18n.t('errors.messages.invalid_url')}"
regex = %r{\Ahttps?:\/\/([^\s:@]+:[^\s:@]*@)?[A-Za-z\d\-]+(\.[A-Za-z\d\-]+)+\.?(:\d{1,5})?([\/?]\S*)?\z}i
regex_validate_each(regex, default_message, reco... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/validators/date_validator.rb | Ruby | bsd-3-clause | 187 | master | 2,005 | class DateValidator < ActiveModel::EachValidator
def validate_each(record, attribute, _value)
value = record.read_attribute_before_type_cast(attribute)
return if value.blank? || value.is_a?(Date)
default_message = "#{value} #{I18n.t('errors.messages.invalid_date')}"
unless date_valid?(value)
r... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/validators/zip_validator.rb | Ruby | bsd-3-clause | 187 | master | 275 | class ZipValidator < RegexValidator
def validate_each(record, attribute, value)
default_message = "#{value} #{I18n.t('errors.messages.invalid_zip')}"
regex = /\A\d{5}(-\d{4})?\z/
regex_validate_each(regex, default_message, record, attribute, value)
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/validators/pg_array_validator.rb | Ruby | bsd-3-clause | 187 | master | 870 | class PgArrayValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if value.nil?
attr = record.read_attribute_before_type_cast(attribute)
return if does_not_need_validation?(attr)
default_message = "#{attr} #{I18n.t('errors.messages.not_an_array')}"
unless att... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/validators/service_area_validator.rb | Ruby | bsd-3-clause | 187 | master | 400 | class ServiceAreaValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if value.blank? || SETTINGS[:valid_service_areas].blank?
default_message = "#{value} #{I18n.t('errors.messages.invalid_service_area')}"
return if SETTINGS[:valid_service_areas].include?(value)
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/validators/email_validator.rb | Ruby | bsd-3-clause | 187 | master | 315 | class EmailValidator < RegexValidator
def validate_each(record, attribute, value)
default_message = "#{value} #{I18n.t('errors.messages.invalid_email')}"
regex = /\A([^@\s]+)@((?:(?!-)[-a-z0-9]+(?<!-)\.)+[a-z]{2,})\z/i
regex_validate_each(regex, default_message, record, attribute, value)
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/validators/phone_validator.rb | Ruby | bsd-3-clause | 187 | master | 316 | class PhoneValidator < RegexValidator
def validate_each(record, attribute, value)
default_message = "#{value} #{I18n.t('errors.messages.invalid_phone')}"
regex = /\A(\((\d{3})\)|\d{3})[ |\.\-]?(\d{3})[ |\.\-]?(\d{4})\z/
regex_validate_each(regex, default_message, record, attribute, value)
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/validators/array_validator.rb | Ruby | bsd-3-clause | 187 | master | 1,729 | # This custom validator allows you to validate each element in an Array field.
# Source: https://gist.github.com/ssimeonov/6519423
# See app/models/location.rb for usage. Here's an example:
# validates :admin_emails, array: {
# format: { with: /some regex/,
# message... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/serializers/locations_serializer.rb | Ruby | bsd-3-clause | 187 | master | 542 | class LocationsSerializer < ActiveModel::Serializer
attributes :id, :active, :admin_emails, :alternate_name, :coordinates,
:description, :latitude, :longitude, :name, :short_desc, :slug,
:website, :updated_at, :url
has_one :address
has_one :organization, serializer: LocationsOrganizatio... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/serializers/service_serializer.rb | Ruby | bsd-3-clause | 187 | master | 545 | class ServiceSerializer < ActiveModel::Serializer
attributes :id, :accepted_payments, :alternate_name, :audience, :description,
:eligibility, :email, :fees, :funding_sources, :application_process,
:interpretation_services, :keywords, :languages, :name,
:required_documents, :serv... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/serializers/location_serializer.rb | Ruby | bsd-3-clause | 187 | master | 378 | class LocationSerializer < LocationsSerializer
attributes :accessibility, :email, :languages, :transportation
has_many :contacts
has_one :mail_address
has_many :regular_schedules
has_many :holiday_schedules
has_many :services
has_one :organization, serializer: SummarizedOrganizationSerializer
def acc... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/serializers/locations_organization_serializer.rb | Ruby | bsd-3-clause | 187 | master | 373 | class LocationsOrganizationSerializer < ActiveModel::Serializer
attributes :id, :accreditations, :alternate_name, :date_incorporated,
:description, :email, :funding_sources, :licenses, :name,
:website, :slug, :url, :locations_url
def url
api_organization_url(object)
end
def locat... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/api_applications_controller.rb | Ruby | bsd-3-clause | 187 | master | 1,466 | class ApiApplicationsController < ApplicationController
before_action :authenticate_user!
# GET /api_applications
def index
@api_applications = current_user.api_applications
end
# GET /api_applications/new
def new
@api_application = current_user.api_applications.new
end
# GET /api_application... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/application_controller.rb | Ruby | bsd-3-clause | 187 | master | 1,455 | require Rails.root.join('lib/default_host.rb')
class ApplicationController < ActionController::Base
include Pundit::Authorization
# Prevent CSRF attacks by raising an exception (with: :exception),
protect_from_forgery with: :exception
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
unles... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/admin/organizations_controller.rb | Ruby | bsd-3-clause | 187 | master | 2,063 | class Admin
class OrganizationsController < ApplicationController
before_action :authenticate_admin!
layout 'admin'
include Taggable
def index
@all_orgs = policy_scope(Organization)
@orgs = Kaminari.paginate_array(@all_orgs).page(params[:page])
respond_to do |format|
forma... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/admin/programs_controller.rb | Ruby | bsd-3-clause | 187 | master | 1,315 | class Admin
class ProgramsController < ApplicationController
before_action :authenticate_admin!
layout 'admin'
def index
@programs = Kaminari.paginate_array(policy_scope(Program)).
page(params[:page]).per(params[:per_page])
end
def edit
@program = Program.find(param... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/admin/registrations_controller.rb | Ruby | bsd-3-clause | 187 | master | 542 | class Admin
class RegistrationsController < Devise::RegistrationsController
before_action :configure_permitted_parameters
include PrivateRegistration
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
devise_parameter_sanitizer.permit... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/admin/services_controller.rb | Ruby | bsd-3-clause | 187 | master | 4,076 | class Admin
class ServicesController < ApplicationController
include Taggable
before_action :authenticate_admin!
layout 'admin'
def index
@services = Kaminari.paginate_array(policy_scope(Service)).
page(params[:page]).per(params[:per_page])
end
def edit
assign_... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/admin/service_contacts_controller.rb | Ruby | bsd-3-clause | 187 | master | 1,841 | class Admin
class ServiceContactsController < ApplicationController
before_action :authenticate_admin!
layout 'admin'
def edit
@service = service_from_params
@contact = Contact.find(params[:id])
authorize @service.location
end
def update
@contact = Contact.find(params[:i... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/admin/contacts_controller.rb | Ruby | bsd-3-clause | 187 | master | 1,663 | class Admin
class ContactsController < ApplicationController
before_action :authenticate_admin!
layout 'admin'
def edit
@location = Location.find(params[:location_id])
@contact = Contact.find(params[:id])
authorize @location
end
def update
@contact = Contact.find(params[... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/admin/locations_controller.rb | Ruby | bsd-3-clause | 187 | master | 2,261 | class Admin
class LocationsController < ApplicationController
before_action :authenticate_admin!
layout 'admin'
def index
@locations = Kaminari.paginate_array(policy_scope(Location)).
page(params[:page]).per(params[:per_page])
end
def edit
@location = Location.find... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/admin/organization_contacts_controller.rb | Ruby | bsd-3-clause | 187 | master | 1,720 | class Admin
class OrganizationContactsController < ApplicationController
before_action :authenticate_admin!
layout 'admin'
def edit
@organization = Organization.find(params[:organization_id])
@contact = Contact.find(params[:id])
authorize @contact
end
def update
@contact... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/admin/dashboard_controller.rb | Ruby | bsd-3-clause | 187 | master | 273 | class Admin
class DashboardController < ApplicationController
layout 'admin'
def index
redirect_to new_admin_session_url unless admin_signed_in?
@orgs = policy_scope(Organization) if current_admin
@version = OHANA_API_VERSION
end
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/admin/csv_controller.rb | Ruby | bsd-3-clause | 187 | master | 720 | class Admin
class CsvController < ApplicationController
before_action :authorize_admin
# The CSV content for each action is defined in
# app/views/admin/csv/{action_name}.csv.shaper
def addresses; end
def contacts; end
def holiday_schedules; end
def locations; end
def mail_address... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/concerns/pagination_headers.rb | Ruby | bsd-3-clause | 187 | master | 1,300 | module PaginationHeaders
# Set Link and pagination-related HTTP headers
#
# @param coll ActiveRecord::Relation
# @return various pagination-related HTTP Headers
def generate_pagination_headers(coll)
pages = pages(coll)
links = links(pages)
links.delete_if(&:blank?)
response.headers['Link'] ... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/concerns/private_registration.rb | Ruby | bsd-3-clause | 187 | master | 1,636 | module PrivateRegistration
def create
build_resource(sign_up_params)
if resource.save
process_successful_registration
elsif resource_valid_except_for_duplicate_email?
process_private_registration
else
email_error = resource.errors[:email]
resource.errors.delete(:email) if emai... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/concerns/token_validator.rb | Ruby | bsd-3-clause | 187 | master | 541 | module TokenValidator
extend ActiveSupport::Concern
included do
before_action :validate_token!, only: %i[update destroy create]
end
def validate_token!
render_401 unless valid_api_token?
end
def valid_api_token?
token = request.env['HTTP_X_API_TOKEN'].to_s
token.present? && token == ENV['... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/concerns/custom_errors.rb | Ruby | bsd-3-clause | 187 | master | 1,569 | require 'exceptions'
module CustomErrors
extend ActiveSupport::Concern
included do
include ActiveSupport::Rescuable
unless Rails.application.config.consider_all_requests_local
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
rescue_from ActiveRecord::RecordInvalid, with: :ren... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/api/v1/locations_controller.rb | Ruby | bsd-3-clause | 187 | master | 1,997 | module Api
module V1
class LocationsController < ApplicationController
include TokenValidator
include PaginationHeaders
include CustomErrors
include Cacheable
after_action :set_cache_control, only: %i[index show]
def index
locations = Location.includes(:organization, ... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/api/v1/services_controller.rb | Ruby | bsd-3-clause | 187 | master | 1,705 | module Api
module V1
class ServicesController < ApplicationController
include TokenValidator
include CustomErrors
include CategoryIdCollector
before_action :validate_token!, only: %i[update destroy create update_categories]
def index
location = Location.includes(
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/api/v1/mail_address_controller.rb | Ruby | bsd-3-clause | 187 | master | 1,064 | module Api
module V1
class MailAddressController < ApplicationController
include TokenValidator
include CustomErrors
def update
mail_address = MailAddress.find(params[:id])
mail_address.update!(mail_address_params)
render json: mail_address, status: :ok
end
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/api/v1/root_controller.rb | Ruby | bsd-3-clause | 187 | master | 863 | module Api
module V1
class RootController < ApplicationController
def index
json_for_root_endpoint = {
organizations_url: "#{api_organizations_url}{?page,per_page}",
organization_url: "#{api_organizations_url}/{organization}",
organization_locations_url: "#{api_url}/org... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/api/v1/contacts_controller.rb | Ruby | bsd-3-clause | 187 | master | 905 | module Api
module V1
class ContactsController < ApplicationController
include TokenValidator
include CustomErrors
def index
location = Location.find(params[:location_id])
contacts = location.contacts
render json: contacts, status: :ok
end
def update
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/api/v1/organizations_controller.rb | Ruby | bsd-3-clause | 187 | master | 1,579 | module Api
module V1
class OrganizationsController < ApplicationController
include TokenValidator
include PaginationHeaders
include CustomErrors
def index
orgs = Organization.includes(:contacts, :phones).
page(params[:page]).per(params[:per_page])
render jso... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/api/v1/address_controller.rb | Ruby | bsd-3-clause | 187 | master | 1,032 | module Api
module V1
class AddressController < ApplicationController
include TokenValidator
include CustomErrors
def update
location = Location.find(params[:location_id])
location.update!(address_attributes: address_params.merge!(id: params[:id]))
render json: location.a... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/api/v1/contact_phones_controller.rb | Ruby | bsd-3-clause | 187 | master | 765 | module Api
module V1
class ContactPhonesController < ApplicationController
include TokenValidator
include CustomErrors
def update
phone = Phone.find(params[:id])
phone.update!(phone_params)
render json: phone, status: :ok
end
def create
contact = Con... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/api/v1/categories_controller.rb | Ruby | bsd-3-clause | 187 | master | 354 | module Api
module V1
class CategoriesController < ApplicationController
def index
categories = Category.all
render json: categories, status: :ok
end
def children
children = Category.find_by(taxonomy_id: params[:taxonomy_id]).children
render json: children, status... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/api/v1/errors_controller.rb | Ruby | bsd-3-clause | 187 | master | 248 | module Api
module V1
class ErrorsController < ApplicationController
def raise_not_found!
message = "No route matches #{params[:unmatched_route]}"
raise ActionController::RoutingError, message
end
end
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/api/v1/search_controller.rb | Ruby | bsd-3-clause | 187 | master | 1,304 | module Api
module V1
class SearchController < ApplicationController
include PaginationHeaders
include CustomErrors
include Cacheable
after_action :set_cache_control, only: :index
def index
locations = Location.search(params).page(params[:page]).
per(para... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/api/v1/location_phones_controller.rb | Ruby | bsd-3-clause | 187 | master | 926 | module Api
module V1
class LocationPhonesController < ApplicationController
include TokenValidator
include CustomErrors
def index
location = Location.find(params[:location_id])
phones = location.phones
render json: phones, status: :ok
end
def update
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/api/v1/status_controller.rb | Ruby | bsd-3-clause | 187 | master | 765 | module Api
module V1
class StatusController < ApplicationController
def check_status
response_hash = {}
response_hash[:dependencies] = %w[SendGrid Postgres]
response_hash[:status] = everything_ok? ? 'ok' : 'NOT OK'
response_hash[:updated] = Time.zone.now.to_i
render ... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/controllers/user/registrations_controller.rb | Ruby | bsd-3-clause | 187 | master | 453 | class User
class RegistrationsController < Devise::RegistrationsController
before_action :configure_permitted_parameters
include PrivateRegistration
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
devise_parameter_sanitizer.permit(... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/user.rb | Ruby | bsd-3-clause | 187 | master | 443 | class User < ApplicationRecord
has_many :api_applications, dependent: :destroy
accepts_nested_attributes_for :api_applications
# Devise checks for presence of email and password by default
validates :name, presence: true
validates :email, email: true, uniqueness: { case_sensitive: false }
devise :database... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/api_application.rb | Ruby | bsd-3-clause | 187 | master | 523 | class ApiApplication < ApplicationRecord
belongs_to :user
validates :name, :api_token, uniqueness: true
validates :name, :main_url, presence: true
validates :main_url, url: true
validates :callback_url, url: true, allow_blank: true
auto_strip_attributes :name, squish: true
before_create :generate_api_t... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/admin.rb | Ruby | bsd-3-clause | 187 | master | 341 | class Admin < ApplicationRecord
# Devise already checks for presence of email and password.
validates :name, presence: true
validates :email, email: true, uniqueness: { case_sensitive: false }
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/service.rb | Ruby | bsd-3-clause | 187 | master | 2,696 | class Service < ApplicationRecord
belongs_to :location, touch: true, optional: false
belongs_to :program, optional: true
has_and_belongs_to_many :categories,
after_add: :touch_location,
after_remove: :touch_location
has_many :regular_schedules, dependent: :d... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/phone.rb | Ruby | bsd-3-clause | 187 | master | 949 | class Phone < ApplicationRecord
include ParentPresenceValidatable
default_scope { order('id ASC') }
belongs_to :location, optional: true, touch: true, inverse_of: :phones
belongs_to :contact, optional: true, touch: true, inverse_of: :phones
belongs_to :service, optional: true, touch: true, inverse_of: :phon... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/mail_address.rb | Ruby | bsd-3-clause | 187 | master | 626 | class MailAddress < ApplicationRecord
belongs_to :location, touch: true, inverse_of: :mail_address, optional: false
validates :address_1,
:city,
:postal_code,
:country,
presence: { message: I18n.t('errors.messages.blank_for_mail_address') }
validates :state_provin... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/category.rb | Ruby | bsd-3-clause | 187 | master | 380 | class Category < ApplicationRecord
has_and_belongs_to_many :services
validates :name, :taxonomy_id,
presence: { message: I18n.t('errors.messages.blank_for_category') }
validates :taxonomy_id,
uniqueness: {
message: I18n.t('errors.messages.duplicate_taxonomy_id'),
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/address.rb | Ruby | bsd-3-clause | 187 | master | 724 | class Address < ApplicationRecord
belongs_to :location, optional: true, touch: true
validates :address_1,
:city,
:postal_code,
:country,
presence: { message: I18n.t('errors.messages.blank_for_address') }
validates :state_province, state_province: true
validates... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/regular_schedule.rb | Ruby | bsd-3-clause | 187 | master | 466 | class RegularSchedule < ApplicationRecord
include ParentPresenceValidatable
default_scope { order('weekday ASC') }
belongs_to :location, optional: true, touch: true, inverse_of: :regular_schedules
belongs_to :service, optional: true, touch: true, inverse_of: :regular_schedules
validates :weekday, :opens_at... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/organization.rb | Ruby | bsd-3-clause | 187 | master | 1,376 | class Organization < ApplicationRecord
default_scope { order('id DESC') }
has_many :locations, dependent: :destroy
has_many :programs, dependent: :destroy
has_many :contacts, dependent: :destroy
has_many :phones, dependent: :destroy, inverse_of: :organization
accepts_nested_attributes_for :phones,
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/holiday_schedule.rb | Ruby | bsd-3-clause | 187 | master | 530 | class HolidaySchedule < ApplicationRecord
include ParentPresenceValidatable
belongs_to :location, optional: true, touch: true, inverse_of: :holiday_schedules
belongs_to :service, optional: true, touch: true, inverse_of: :holiday_schedules
validates :start_date, :end_date,
date: true,
p... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/location.rb | Ruby | bsd-3-clause | 187 | master | 3,994 | class Location < ApplicationRecord
belongs_to :organization, optional: false
has_one :address, dependent: :destroy
accepts_nested_attributes_for :address, allow_destroy: true
has_many :contacts, dependent: :destroy
has_one :mail_address, dependent: :destroy, inverse_of: :location
accepts_nested_attribute... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/contact.rb | Ruby | bsd-3-clause | 187 | master | 662 | class Contact < ApplicationRecord
include ParentPresenceValidatable
default_scope { order('id ASC') }
belongs_to :location, optional: true, touch: true
belongs_to :organization, optional: true
belongs_to :service, optional: true, touch: true
has_many :phones, dependent: :destroy, inverse_of: :contact
a... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/nested_categories.rb | Ruby | bsd-3-clause | 187 | master | 1,452 | class NestedCategories
include ActionView::Helpers
def initialize(taxonomy_ids:, view:, categories: Category.arrange(order: :taxonomy_id))
@taxonomy_ids = taxonomy_ids
@view = view
@categories = categories
end
delegate :concat, :content_tag, :checkbox_tag, :label_tag, to: :view
def call
saf... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/program.rb | Ruby | bsd-3-clause | 187 | master | 366 | class Program < ApplicationRecord
belongs_to :organization, optional: false
has_many :services, dependent: :destroy
validates :name,
presence: { message: I18n.t('errors.messages.blank_for_program') }
auto_strip_attributes :alternate_name, :name
def self.with_orgs(ids)
joins(:organization).w... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/concerns/search.rb | Ruby | bsd-3-clause | 187 | master | 2,015 | require 'email_filter'
require 'location_filter'
module Search
extend ActiveSupport::Concern
included do
def nearbys(radius)
r = LocationFilter.new(self.class).validated_radius(radius, 0.5)
super(r)
end
scope :category, (lambda do |category|
joins(services: :categories).where(catego... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/models/concerns/parent_presence_validatable.rb | Ruby | bsd-3-clause | 187 | master | 604 | module ParentPresenceValidatable
def self.included(base)
base.class_eval do
validate :parent_presence
end
end
private
def parent_presence
return if parents.any?(&:present?)
errors.add(:base, "#{self.class.name.titleize} is missing a parent: #{list_of_parents}")
end
def parents
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/helpers/admin/form_helper.rb | Ruby | bsd-3-clause | 187 | master | 2,193 | class Admin
module FormHelper
def link_to_add_fields(name, form, association)
new_object = form.object.class.reflect_on_association(association).klass.new
id = new_object.object_id
fields = form.fields_for(association, new_object, child_index: id) do |builder|
render("admin/locations/for... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | app/helpers/admin/csv_download_helper.rb | Ruby | bsd-3-clause | 187 | master | 214 | class Admin
module CsvDownloadHelper
def csv_tables
%w[addresses contacts holiday_schedules locations mail_addresses
organizations phones programs regular_schedules services]
end
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/active_record_spec_helper.rb | Ruby | bsd-3-clause | 187 | master | 313 | require 'active_record'
connection_info = YAML.load_file('config/database.yml')['test']
ActiveRecord::Base.establish_connection(connection_info)
RSpec.configure do |config|
config.around do |example|
ActiveRecord::Base.transaction do
example.run
raise ActiveRecord::Rollback
end
end
end |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/rails_helper.rb | Ruby | bsd-3-clause | 187 | master | 2,197 | require 'spec_helper'
require File.expand_path('../config/environment', __dir__)
require 'rspec/rails'
require 'rspec/its'
require 'shoulda/matchers'
Rails.logger.level = 4
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/spec_helper.rb | Ruby | bsd-3-clause | 187 | master | 2,725 | if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start 'rails'
end
ENV['RAILS_ENV'] ||= 'test'
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/controllers/api_applications_controller_spec.rb | Ruby | bsd-3-clause | 187 | master | 5,357 | require 'rails_helper'
describe ApiApplicationsController do
before do
@user = create(:user)
sign_in @user
end
# This should return the minimal set of attributes required to create a valid
# ApiApplication. As you add validations to ApiApplication, be sure to
# adjust the attributes here as well.
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/controllers/admin/services_controller_spec.rb | Ruby | bsd-3-clause | 187 | master | 7,761 | require 'rails_helper'
describe Admin::ServicesController do
describe 'GET edit' do
before do
@loc = create(:location_with_admin)
@service = @loc.services.create!(attributes_for(:service))
end
context 'when admin is super admin' do
it 'allows access to edit service' do
log_in_a... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/controllers/admin/programs_controller_spec.rb | Ruby | bsd-3-clause | 187 | master | 5,822 | require 'rails_helper'
describe Admin::ProgramsController do
describe 'GET edit' do
before do
location = create(:location_with_admin)
org = location.organization
@program = org.programs.create!(attributes_for(:program))
end
context 'when admin is super admin' do
it 'allows access... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/controllers/admin/organization_contacts_controller_spec.rb | Ruby | bsd-3-clause | 187 | master | 6,583 | require 'rails_helper'
describe Admin::OrganizationContactsController do
describe 'GET edit' do
before do
location = create(:location_with_admin)
@org = location.organization
@contact = @org.contacts.create!(attributes_for(:contact))
end
context 'when admin is super admin' do
it ... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/controllers/admin/service_contacts_controller_spec.rb | Ruby | bsd-3-clause | 187 | master | 7,810 | require 'rails_helper'
describe Admin::ServiceContactsController do
describe 'GET edit' do
before do
@location = create(:location_with_admin)
@service = @location.services.create!(attributes_for(:service))
@contact = @service.contacts.create!(attributes_for(:contact))
end
context 'when... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/controllers/admin/csv_controller_spec.rb | Ruby | bsd-3-clause | 187 | master | 1,359 | require 'rails_helper'
describe Admin::CsvController do
describe 'GET [table]' do
it 'denies access if not a super admin' do
log_in_as_admin(:admin)
actions = %i[
addresses contacts holiday_schedules locations mail_addresses
organizations phones programs regular_schedules services
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/controllers/admin/locations_controller_spec.rb | Ruby | bsd-3-clause | 187 | master | 6,132 | require 'rails_helper'
describe Admin::LocationsController do
describe 'create' do
before do
location = create(:location_with_admin)
@org = location.organization
end
context 'when admin is super admin' do
it 'allows access to create location' do
log_in_as_admin(:super_admin)
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/controllers/admin/organizations_controller_spec.rb | Ruby | bsd-3-clause | 187 | master | 5,268 | require 'rails_helper'
describe Admin::OrganizationsController do
describe 'create' do
let(:attrs) do
{
name: 'New org',
description: 'New description',
licenses: [''],
accreditations: ['']
}
end
context 'when admin is super admin' do
it 'allows access t... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/controllers/admin/contacts_controller_spec.rb | Ruby | bsd-3-clause | 187 | master | 5,982 | require 'rails_helper'
describe Admin::ContactsController do
describe 'GET edit' do
before do
@loc = create(:location_with_admin)
@contact = @loc.contacts.create!(attributes_for(:contact))
end
context 'when admin is super admin' do
it 'allows access to edit contact' do
log_in_a... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/requests/api_applications_spec.rb | Ruby | bsd-3-clause | 187 | master | 676 | require 'rails_helper'
describe 'ApiApplications' do
describe 'GET /api_applications' do
context 'when not signed in' do
it "redirects to 'users/sign_in'" do
get api_applications_path
expect(response.status).to be(302)
expect(response).to redirect_to(new_user_session_path)
end... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/requests/status_spec.rb | Ruby | bsd-3-clause | 187 | master | 1,264 | require 'rails_helper'
describe 'GET /api/.well-known/status' do
context 'when everything is ok' do
before do
create(:loc_with_nil_fields)
get '/api/.well-known/status'
end
it 'returns a 200 HTTP status' do
expect(response).to have_http_status(:ok)
end
it 'lists all dependenci... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/routing/api_applications_routing_spec.rb | Ruby | bsd-3-clause | 187 | master | 993 | require 'rails_helper'
describe ApiApplicationsController do
describe 'routing' do
it 'routes to #index' do
expect(get('/api_applications')).to route_to('api_applications#index')
end
it 'routes to #new' do
expect(get('/api_applications/new')).to route_to('api_applications#new')
end
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/support/admin_controller_helper.rb | Ruby | bsd-3-clause | 187 | master | 325 | module AdminControllerHelper
def log_in_as_admin(admin)
@request.env['devise.mapping'] = Devise.mappings[:admin]
sign_in FactoryBot.create(admin)
end
end
RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :controller
config.include AdminControllerHelper, type: :controller... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/support/shared_examples_for_schedules.rb | Ruby | bsd-3-clause | 187 | master | 555 | shared_examples 'validating opens_at and closes_at values' do |model, attribute|
it 'converts 18:00' do
rs = build(model, attribute => '18:00')
rs.valid?
expect(rs.send(attribute)).to eq(Time.utc(2000, 1, 1, 18, 00, 0))
end
it 'converts 5am' do
rs = build(model, attribute => '5am')
rs.valid?
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/support/webmock.rb | Ruby | bsd-3-clause | 187 | master | 247 | require 'webmock/rspec'
WebMock.disable_net_connect!(
allow: [
/localhost/,
/127\.0\.0\.1/,
/codeclimate.com/, # For uploading coverage reports
/chromedriver\.storage\.googleapis\.com/ # For fetching a chromedriver binary
]
) |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/support/mailer_macros.rb | Ruby | bsd-3-clause | 187 | master | 332 | RSpec.configure do |config|
config.before(:each, email: true) do
ActionMailer::Base.deliveries = []
end
end
module MailerMacros
def first_email
ActionMailer::Base.deliveries.first
end
def last_email
ActionMailer::Base.deliveries.last
end
def reset_email
ActionMailer::Base.deliveries = [... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/support/default_headers.rb | Ruby | bsd-3-clause | 187 | master | 1,303 | module DefaultHeaders
def post(uri, params = {}, session = {})
super(
uri,
params: params.to_json,
headers: {
'HTTP_USER_AGENT' => 'Rspec',
'HTTP_X_API_TOKEN' => ENV.fetch('ADMIN_APP_TOKEN', nil),
'Content-Type' => 'application/json'
}.merge!(session)
)
end
... |
github | codeforamerica/ohana-api | https://github.com/codeforamerica/ohana-api | spec/support/shoulda_matchers.rb | Ruby | bsd-3-clause | 187 | master | 241 | Shoulda::Matchers.configure do |config|
config.integrate do |with|
# Choose a test framework:
with.test_framework :rspec
# Choose one or more libraries:
with.library :active_record
with.library :active_model
end
end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.