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
displayful/turnstiled
https://github.com/displayful/turnstiled
lib/turnstiled/engine.rb
Ruby
mit
45
main
445
module Turnstiled class Engine < ::Rails::Engine initializer "turnstiled.controller" do ActiveSupport.on_load(:action_controller_base) { include Turnstiled::ControllerMethods } end initializer "turnstiled.view" do ActiveSupport.on_load(:action_view) { include Turnstiled::ViewHelper } end ...
github
displayful/turnstiled
https://github.com/displayful/turnstiled
lib/turnstiled/controller_methods.rb
Ruby
mit
45
main
352
# frozen_string_literal: true module Turnstiled module ControllerMethods extend ActiveSupport::Concern class_methods do def verify_turnstile_request(**) before_action(:verify_turnstile_request, **) end end def verify_turnstile_request head :bad_request unless Turnstiled.ve...
github
displayful/turnstiled
https://github.com/displayful/turnstiled
lib/turnstiled/verifier.rb
Ruby
mit
45
main
719
# frozen_string_literal: true module Turnstiled class Verifier def verify(request) return request.params["cf-turnstile-response"] == "1" if Turnstiled.mock response = client.post("siteverify", { secret: Turnstiled.site_secret, response: request.params["cf-turnstile-response"], ...
github
displayful/turnstiled
https://github.com/displayful/turnstiled
lib/turnstiled/view_helper.rb
Ruby
mit
45
main
925
# frozen_string_literal: true module Turnstiled module ViewHelper def turnstile_tag(size: "compact", **options) options = options.deep_merge( class: "cf-turnstile #{options[:class]}", data: { sitekey: Turnstiled.site_key, controller: "turnstile", turnstile_site...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
Rakefile
Ruby
bsd-3-clause
45
main
422
# frozen_string_literal: true # 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__) begin require 'rubocop/rake_task' RuboCop::RakeTask.new rescue LoadEr...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
Gemfile
Ruby
bsd-3-clause
45
main
869
# frozen_string_literal: true source 'https://rubygems.org' ruby '2.7.8' gem 'airbrake', '~> 10.0' gem 'devise', '~> 4.7' gem 'geokit', '~> 1.13' gem 'haml', '~> 5.1' gem 'http_accept_language', '~> 2.0' gem 'local_time', '~> 2.1' gem 'obscenity', '~> 1.0', '>= 1.0.2' gem 'pg' gem 'rails', '~> 5.2.3' gem 'rails_admin...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
db/schema.rb
Ruby
bsd-3-clause
45
main
4,253
# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # dat...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
db/seeds.rb
Ruby
bsd-3-clause
45
main
705
User.where(email: 'john@example.com').first_or_initialize.tap do |user| user.first_name = 'John' user.last_name = 'Doe' user.password = 'password' user.save! end User.where(email: 'admin@example.com').first_or_initialize.tap do |user| user.first_name = 'Jane' user.last_name = 'Doe' user.password = 'passw...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
db/migrate/00000000000003_create_things.rb
Ruby
bsd-3-clause
45
main
401
# frozen_string_literal: true class CreateThings < ActiveRecord::Migration[4.2] def change create_table :things do |t| t.timestamps t.string :name t.decimal :lat, null: false, precision: 16, scale: 14 t.decimal :lng, null: false, precision: 17, scale: 14 t.integer :city_id t.i...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
db/migrate/20180509181541_add_priority_to_thing.rb
Ruby
bsd-3-clause
45
main
330
# frozen_string_literal: true class AddPriorityToThing < ActiveRecord::Migration[5.2] def change # rubocop:disable Rails/BulkChangeTable add_column :things, :priority, :boolean, default: false, null: false change_column :things, :priority, :boolean, null: false # rubocop:enable Rails/BulkChangeTable ...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
db/migrate/00000000000002_add_devise_to_users.rb
Ruby
bsd-3-clause
45
main
1,808
# frozen_string_literal: true class AddDeviseToUsers < ActiveRecord::Migration[4.2] def up # rubocop:disable Rails/BulkChangeTable change_table(:users) do |t| ## Database authenticatable # t.string :email, null: false, default: "" t.string :encrypted_password, null: false, defa...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
db/migrate/20180515170343_create_active_storage_tables.active_storage.rb
Ruby
bsd-3-clause
45
main
930
# frozen_string_literal: true # This migration comes from active_storage (originally 20170806125915) class CreateActiveStorageTables < ActiveRecord::Migration[5.2] def change create_table :active_storage_blobs do |t| t.string :key, null: false t.string :filename, null: false t.stri...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
db/migrate/00000000000005_create_rails_admin_histories_table.rb
Ruby
bsd-3-clause
45
main
485
# frozen_string_literal: true class CreateRailsAdminHistoriesTable < ActiveRecord::Migration[4.2] def change create_table :rails_admin_histories do |t| t.string :message # title, name, or object_id t.string :username t.integer :item t.string :table t.integer :month, limit: 2 t...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
db/migrate/20160326200455_user_split_name.rb
Ruby
bsd-3-clause
45
main
795
# frozen_string_literal: true class UserSplitName < ActiveRecord::Migration[4.2] def up # rubocop:disable Rails/BulkChangeTable add_column :users, :first_name, :string add_column :users, :last_name, :string execute <<-SQL UPDATE users SET first_name = split_part(name, ' ', 1); UPDATE user...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
db/migrate/00000000000004_create_reminders.rb
Ruby
bsd-3-clause
45
main
477
# frozen_string_literal: true class CreateReminders < ActiveRecord::Migration[4.2] def change create_table :reminders do |t| t.timestamps t.integer :from_user_id, null: false t.integer :to_user_id, null: false t.integer :thing_id, null: false t.boolean :sent, default: false end ...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
db/migrate/20170926173203_add_adopted_name_to_things.rb
Ruby
bsd-3-clause
45
main
324
# frozen_string_literal: true class AddAdoptedNameToThings < ActiveRecord::Migration[4.2] def up add_column :things, :adopted_name, :string execute <<-SQL UPDATE things SET adopted_name = name WHERE user_id IS NOT NULL; SQL end def down remove_column :things, :adopted_name, :string end ...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
db/migrate/00000000000001_create_users.rb
Ruby
bsd-3-clause
45
main
513
# frozen_string_literal: true class CreateUsers < ActiveRecord::Migration[4.2] def change create_table :users do |t| t.timestamps t.string :name, null: false t.string :organization t.string :email, null: false t.string :voice_number t.string :sms_number t.string :address...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
config/puma.rb
Ruby
bsd-3-clause
45
main
2,036
# frozen_string_literal: true # 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 minim...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
config/unicorn.rb
Ruby
bsd-3-clause
45
main
338
# frozen_string_literal: true worker_processes 4 timeout 30 preload_app true before_fork do |_server, _worker| Signal.trap 'TERM' do Process.kill 'QUIT', Process.pid end ActiveRecord::Base.connection.disconnect! end after_fork do |_server, _worker| Signal.trap 'TERM' do end ActiveRecord::Base.establi...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
config/environment.rb
Ruby
bsd-3-clause
45
main
421
# frozen_string_literal: true # Load the Rails application. require File.expand_path('application', __dir__) ActionMailer::Base.smtp_settings = { address: 'smtp.sendgrid.net', port: '587', authentication: :plain, user_name: ENV['SENDGRID_USERNAME'], password: ENV['SENDGRID_PASSWORD'], domain: 'heroku.com'...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
config/routes.rb
Ruby
bsd-3-clause
45
main
652
# frozen_string_literal: true Rails.application.routes.draw do devise_for :users, controllers: { passwords: 'passwords', registrations: 'users', sessions: 'sessions', } get '/address', to: 'addresses#show', as: 'address' get '/info_window', to: 'info_window#index', as: 'info_window' get '/sitema...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
config/application.rb
Ruby
bsd-3-clause
45
main
1,469
# frozen_string_literal: true require File.expand_path('boot', __dir__) require 'rails/all' require 'obscenity/active_model' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module AdoptAThing class Application < Rails...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
config/initializers/new_framework_defaults.rb
Ruby
bsd-3-clause
45
main
918
# frozen_string_literal: true # Be sure to restart your server when you modify this file. # # This file contains migration options to ease your Rails 5.0 upgrade. # # Once upgraded flip defaults one by one to migrate to the new default. # # Read the Guide for Upgrading Ruby on Rails for more info on each option. # En...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
config/initializers/devise.rb
Ruby
bsd-3-clause
45
main
12,429
# frozen_string_literal: true # 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| # The secret key used by Devise. Devise uses this key to generate # random tokens. Changing this key will render inv...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
config/initializers/rails_admin.rb
Ruby
bsd-3-clause
45
main
1,107
# frozen_string_literal: true RailsAdmin.config do |config| # rubocop:disable Metrics/BlockLength # internal models # https://github.com/sferik/rails_admin/issues/3014 config.excluded_models = ['ActiveStorage::Blob', 'ActiveStorage::Attachment'] config.authenticate_with do redirect_to(main_app.root_path, ...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
config/initializers/airbrake.rb
Ruby
bsd-3-clause
45
main
2,823
# frozen_string_literal: true # Airbrake is an online tool that provides robust exception tracking in your Rails # applications. In doing so, it allows you to easily review errors, tie an error # to an individual piece of code, and trace the cause back to recent # changes. Airbrake enables for easy categorization, sea...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
config/initializers/geokit.rb
Ruby
bsd-3-clause
45
main
207
# frozen_string_literal: true if ENV['GOOGLE_GEOCODER_API_KEY'] Geokit::Geocoders::GoogleGeocoder.api_key = ENV['GOOGLE_GEOCODER_API_KEY'] else Rails.logger.warn('$GOOGLE_GEOCODER_API_KEY not set') end
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
config/environments/production.rb
Ruby
bsd-3-clause
45
main
3,851
# frozen_string_literal: true Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # asset host config.action_controller.asset_host = 'https://adoptadrain.sfwater.org' config...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
config/environments/development.rb
Ruby
bsd-3-clause
45
main
2,059
# frozen_string_literal: true 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...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
config/environments/staging.rb
Ruby
bsd-3-clause
45
main
3,937
# frozen_string_literal: true Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # asset host # $HEROKU_APP_NAME is used for review apps config.action_controller.asset_host...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
config/environments/test.rb
Ruby
bsd-3-clause
45
main
1,970
# frozen_string_literal: true 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 "s...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/test_helper.rb
Ruby
bsd-3-clause
45
main
891
# frozen_string_literal: true ENV['RAILS_ENV'] ||= 'test' require 'simplecov' require 'minitest/mock' SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter] SimpleCov.start('rails') do minimum_coverage(97) end require File.expand_path('../config/environment', __dir__) require 'rails/test_help' require 'webm...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/mailers/thing_mailer_test.rb
Ruby
bsd-3-clause
45
main
1,899
# frozen_string_literal: true require 'test_helper' class ThingMailerTest < ActionMailer::TestCase test 'first_adopted_confirmation' do @user = users(:erik) @thing = things(:thing_1) @thing.user = @user email = ThingMailer.first_adoption_confirmation(@thing).deliver_now assert_not ActionMailer...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/mailers/devise_mailer_test.rb
Ruby
bsd-3-clause
45
main
503
# frozen_string_literal: true require 'test_helper' class DeviseMailerTest < ActionMailer::TestCase test 'reset_password_instructions' do @user = users(:erik) email = DeviseMailer.reset_password_instructions(@user, '1234').deliver_now assert_not ActionMailer::Base.deliveries.empty? assert_equal ['...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/integration/login_test.rb
Ruby
bsd-3-clause
45
main
759
# frozen_string_literal: true require 'test_helper' class LoginTest < ActionDispatch::IntegrationTest setup do @user = users(:erik) end test 'login with remembering' do post '/users/sign_in.json', params: {user: {email: @user.email, password: 'correct', remember_me: 1}, format: :json} assert_not_em...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/system/adoptions_test.rb
Ruby
bsd-3-clause
45
main
436
require "application_system_test_case" class AdoptionsTest < ApplicationSystemTestCase test "signing up to adopt a drain" do visit root_path click_on "Register / Sign in" fill_in "Email address (private)", with: "user@example.com" fill_in "First name", with: "Example" fill_in "Last name", with: ...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/lib/adopted_mover_test.rb
Ruby
bsd-3-clause
45
main
3,149
# frozen_string_literal: true require 'test_helper' require 'adoption_mover' class AdoptionMoverTest < ActiveSupport::TestCase test 'moves deleted adoptions to close by unadopted things' do deleted_adoption_to_be_moved = things(:thing_1).tap do |thing| thing.update!(user_id: users(:erik).id, adopted_name...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/lib/thing_importer_test.rb
Ruby
bsd-3-clause
45
main
2,613
# frozen_string_literal: true require 'test_helper' require 'thing_importer' class ThingImporterTest < ActiveSupport::TestCase test 'import does not modify data if endpoint fails' do thing1 = things(:thing_1) fake_url = 'http://sf-drain-data.org' stub_request(:get, fake_url).to_return(status: [500, 'I...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/models/user_test.rb
Ruby
bsd-3-clause
45
main
933
# frozen_string_literal: true require 'test_helper' class UserTest < ActiveSupport::TestCase test 'removing non digits from phone numbers' do user = users(:erik) user.sms_number = '1234croehu567890' user.voice_number = '109876oecruh4321' user.remove_non_digits_from_phone_numbers assert_equal '12...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/models/thing_test.rb
Ruby
bsd-3-clause
45
main
653
# frozen_string_literal: true require 'test_helper' class ThingTest < ActiveSupport::TestCase test 'name profanity filter' do t = things(:thing_1) t.name = 'profane aids' assert_raises ActiveRecord::RecordInvalid do t.save! end end test 'adopted scope' do t = things(:thing_1) asse...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/controllers/passwords_controller_test.rb
Ruby
bsd-3-clause
45
main
2,063
# frozen_string_literal: true require 'test_helper' class PasswordsControllerTest < ActionDispatch::IntegrationTest setup do @user = users(:erik) end test 'should send password reset instructions if email address is found' do num_deliveries = ActionMailer::Base.deliveries.size post user_password_ur...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/controllers/things_controller_test.rb
Ruby
bsd-3-clause
45
main
3,252
# frozen_string_literal: true require 'test_helper' class ThingsControllerTest < ActionDispatch::IntegrationTest setup do stub_request(:get, 'https://maps.google.com/maps/api/geocode/json'). with(query: {latlng: '42.383339,-71.049226', sensor: 'false'}). to_return(body: File.read(File.expand_path('....
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/controllers/users_controller_test.rb
Ruby
bsd-3-clause
45
main
1,759
# frozen_string_literal: true require 'test_helper' class UsersControllerTest < ActionDispatch::IntegrationTest setup do @user = users(:erik) end test 'should render edit form' do sign_in @user get edit_user_registration_url assert_response :success assert_select 'form#edit_form' do a...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/controllers/reminders_controller_test.rb
Ruby
bsd-3-clause
45
main
1,319
# frozen_string_literal: true require 'test_helper' class RemindersControllerTest < ActionDispatch::IntegrationTest setup do @thing = things(:thing_1) @dan = users(:dan) @user = users(:erik) @admin = users(:admin) @thing.user = @dan @thing.save! stub_request(:get, 'https://maps.google.co...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/controllers/sessions_controller_test.rb
Ruby
bsd-3-clause
45
main
1,055
# frozen_string_literal: true require 'test_helper' class SessionsControllerTest < ActionDispatch::IntegrationTest setup do @user = users(:erik) end test 'should redirect to root path' do get new_user_session_url assert_response :redirect end test 'should redirect if user is already authentica...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/controllers/sidebar_controller_test.rb
Ruby
bsd-3-clause
45
main
377
# frozen_string_literal: true require 'test_helper' class SidebarControllerTest < ActionDispatch::IntegrationTest setup do @user = users(:erik) end # required by application.js to get the current user test 'search form should include current user id' do sign_in @user get search_url assert_sel...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/controllers/info_window_controller_test.rb
Ruby
bsd-3-clause
45
main
3,112
# frozen_string_literal: true require 'test_helper' class InfoWindowControllerTest < ActionDispatch::IntegrationTest setup do @thing = things(:thing_1) @user = users(:erik) end test 'should thank the user if the drain is adopted by the user' do sign_in @user @thing.user_id = @user.id @thing...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/controllers/main_controller_test.rb
Ruby
bsd-3-clause
45
main
988
# frozen_string_literal: true require 'test_helper' class MainControllerTest < ActionDispatch::IntegrationTest setup do @user = users(:erik) end test 'should return the home page' do get '/' assert_response :success assert_select 'title', 'Adopt-a-Drain San Francisco' assert_select 'button#...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/controllers/addresses_controller_test.rb
Ruby
bsd-3-clause
45
main
1,151
# frozen_string_literal: true require 'test_helper' class AddressesControllerTest < ActionDispatch::IntegrationTest test 'should return latitude and longitude for a valid address' do stub_request(:get, 'https://maps.google.com/maps/api/geocode/json'). with(query: {address: 'City Hall, Boston, MA', sensor:...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
test/controllers/sitemaps_controller_test.rb
Ruby
bsd-3-clause
45
main
242
# frozen_string_literal: true require 'test_helper' class SitemapsControllerTest < ActionDispatch::IntegrationTest test 'should return an XML sitemap' do get sitemap_url, params: {format: 'xml'} assert_response :success end end
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
lib/adoption_mover.rb
Ruby
bsd-3-clause
45
main
2,499
# frozen_string_literal: true # class for rectifying adoptions of invalid data class AdoptionMover class << self # Move adoptions deleted later than `from` to close by unadopted things # within `maximum_movement_in_feet` away # # Returns a hash of {to_id: from_id} # # rubocop:disable Metrics...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
lib/thing_importer.rb
Ruby
bsd-3-clause
45
main
4,626
# frozen_string_literal: true require 'net/http' require 'uri' LOCATION_REGEX = /POINT \((?<lng>-?\d+\.\d+) (?<lat>-?\d+\.\d+)\)/.freeze # class for importing things from CSV datasource # is currently very specific to drains from DataSF # # Dataset: # https://data.sfgov.org/City-Infrastructure/Stormwater-inlets-drai...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
lib/tasks/data.rake
Ruby
bsd-3-clause
45
main
1,384
# frozen_string_literal: true require 'rake' namespace :data do task load_things: :environment do require 'thing_importer' ThingImporter.load('https://data.sfgov.org/api/views/jtgq-b7c5/rows.csv?accessType=DOWNLOAD') end # move adoptions to closeby things # useful for rectifying adoptions of inconsi...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
app/controllers/application_controller.rb
Ruby
bsd-3-clause
45
main
731
# frozen_string_literal: true class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception before_action :set_flash_from_params before_action :set_locale force_ssl if: :ssl_...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
app/controllers/reminders_controller.rb
Ruby
bsd-3-clause
45
main
581
# frozen_string_literal: true class RemindersController < ApplicationController respond_to :json before_action :require_admin def create @reminder = Reminder.new(reminder_params) @reminder.from_user = current_user if @reminder.save ThingMailer.reminder(@reminder.thing).deliver_later @re...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
app/controllers/info_window_controller.rb
Ruby
bsd-3-clause
45
main
393
# frozen_string_literal: true class InfoWindowController < ApplicationController def index @thing = Thing.find_by(id: params[:thing_id]) view = begin if @thing.adopted? user_signed_in? && current_user == @thing.user ? 'users/thank_you' : 'users/profile' else user_signed_in? ? 'thi...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
app/controllers/sessions_controller.rb
Ruby
bsd-3-clause
45
main
746
# frozen_string_literal: true class SessionsController < Devise::SessionsController skip_before_action :verify_authenticity_token, only: [:destroy] def new redirect_to(root_path) end def create self.resource = warden.authenticate!(auth_options) if resource sign_in(resource_name, resource) ...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
app/controllers/passwords_controller.rb
Ruby
bsd-3-clause
45
main
1,174
# frozen_string_literal: true class PasswordsController < Devise::PasswordsController def create self.resource = resource_class.send_reset_password_instructions(resource_params) yield resource if block_given? if successfully_sent?(resource) render(json: {success: true}) else render(json: ...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
app/controllers/users_controller.rb
Ruby
bsd-3-clause
45
main
1,477
# frozen_string_literal: true class UsersController < Devise::RegistrationsController def edit render('sidebar/edit_profile', layout: 'sidebar') end def update # rubocop:disable Metrics/AbcSize self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key) if update_resourc...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
app/controllers/addresses_controller.rb
Ruby
bsd-3-clause
45
main
383
# frozen_string_literal: true class AddressesController < ApplicationController respond_to :json def show @address = Address.geocode("#{params[:address]}, #{params[:city_state]}") if @address.blank? render(json: {errors: {address: [t('errors.not_found', thing: t('defaults.address'))]}}, status: :not...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
app/controllers/things_controller.rb
Ruby
bsd-3-clause
45
main
991
# frozen_string_literal: true class ThingsController < ApplicationController respond_to :json def show @things = Thing.find_closest(params[:lat], params[:lng], params[:limit] || 10) if @things.blank? render(json: {errors: {address: [t('errors.not_found', thing: t('defaults.thing'))]}}, status: :not_...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
app/helpers/application_helper.rb
Ruby
bsd-3-clause
45
main
1,666
# frozen_string_literal: true module ApplicationHelper # rubocop:disable Metrics/MethodLength # rubocop:disable Style/WordArray def us_states [ ['Massachusetts', 'MA'], ['Alabama', 'AL'], ['Alaska', 'AK'], ['Arizona', 'AZ'], ['Arkansas', 'AR'], ['California', 'CA'], ...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
app/mailers/devise_mailer.rb
Ruby
bsd-3-clause
45
main
290
# frozen_string_literal: true class DeviseMailer < Devise::Mailer def reset_password_instructions(record, token, opts = {}) mail = super mail.subject = t('devise.mailer.reset_password_instructions.subject', title: t('titles.main', thing: t('defaults.thing'))) mail end end
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
app/mailers/thing_mailer.rb
Ruby
bsd-3-clause
45
main
1,641
# frozen_string_literal: true class ThingMailer < ApplicationMailer def first_adoption_confirmation(thing) @thing = thing @user = thing.user mail(to: @user.email, subject: ["Thanks for adopting a drain, #{@user.name.split.first}!"]) end def second_adoption_confirmation(thing) @thing = thing ...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
app/models/reminder.rb
Ruby
bsd-3-clause
45
main
340
# frozen_string_literal: true class Reminder < ApplicationRecord include ActiveModel::ForbiddenAttributesProtection belongs_to :from_user, class_name: 'User' belongs_to :thing belongs_to :to_user, class_name: 'User' validates :from_user, presence: true validates :thing, presence: true validates :to_user,...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
app/models/thing.rb
Ruby
bsd-3-clause
45
main
1,337
# frozen_string_literal: true require 'open-uri' require 'csv' class Thing < ApplicationRecord acts_as_paranoid extend Forwardable include ActiveModel::ForbiddenAttributesProtection VALID_DRAIN_TYPES = ['Storm Water Inlet Drain', 'Catch Basin Drain'].freeze belongs_to :user def_delegators :reverse_geoco...
github
sfbrigade/adopt-a-drain
https://github.com/sfbrigade/adopt-a-drain
app/models/user.rb
Ruby
bsd-3-clause
45
main
1,274
# frozen_string_literal: true class User < ApplicationRecord include ActiveModel::ForbiddenAttributesProtection devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable before_validation :remove_non_digits_from_phone_numbers has_many :reminders_from, class...
github
antirez/Gitan
https://github.com/antirez/Gitan
app.rb
Ruby
bsd-3-clause
45
master
999
require 'rubygems' require 'sinatra' require 'httpauth' require 'uri' require 'gitan' require 'gitan_config' before do # Nothing to do so far end helpers do include Sinatra::Authorization end get '/' do require_administrative_privileges @repos = Dir.open($reporoot).to_a erb :repolist end get '/in...
github
antirez/Gitan
https://github.com/antirez/Gitan
httpauth.rb
Ruby
bsd-3-clause
45
master
1,008
# This code is adapted from http://www.gittr.com/index.php/archive/sinatra-basic-authentication-selectively-applied/ module Sinatra module Authorization def auth @auth ||= Rack::Auth::Basic::Request.new(request.env) end def unauthorized!(realm="myApp.com") response['WWW-Authenticate'] = %(Basic rea...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
Gemfile
Ruby
mit
45
master
275
gemspec group :test do source 'https://rubygems.org' do gem 'minitest' gem 'rake', '~> 12.3' gem 'travis' gem 'codecov', :require => false, :group => :test end end group :development do source 'https://rubygems.org' do gem 'gem-release' end end
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
aws-dev-utils.gemspec
Ruby
mit
45
master
774
# encoding: utf-8 $:.unshift File.expand_path('../lib', __FILE__) require 'aws-dev-utils/version' Gem::Specification.new do |s| s.name = 'aws-dev-utils' s.version = AwsDevUtils::VERSION s.authors = ['Amobee BI Infrastructure'] s.email = ['infra@amobee.com'] s.homepage = 'ht...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
lib/aws-dev-utils.rb
Ruby
mit
45
master
576
module AwsDevUtils autoload :Refinements, "aws-dev-utils/refinements" autoload :NextTokenWrapper, "aws-dev-utils/next_token_wrapper" autoload :ClientWrapper, "aws-dev-utils/client_wrapper" autoload :RetryWrapper, "aws-dev-utils/retry_wrapper" autoload :CacheWrapper, "aws-dev-utils/cache_wrapper" autoload :M...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
lib/aws-dev-utils/cache_wrapper.rb
Ruby
mit
45
master
748
require 'deepsort' module AwsDevUtils class CacheWrapper include AwsDevUtils::Utils # Initialize a new CacheWrapper, internal use only. # @param client [Aws client, NextTokenWrapper, RetryWrapper] # @param exp [Integer] - the key-value timeout def initialize client, exp=60, client_name: nil @clien...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
lib/aws-dev-utils/utils.rb
Ruby
mit
45
master
1,229
module AwsDevUtils module Utils module_function # Transforms an object to a nested struct. # @return [OpenStruct] def nested_struct obj case obj when Hash obj.each_with_object(OpenStruct.new) do |(k,v), acc| acc[k]= case v when Hash then send(__method_...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
lib/aws-dev-utils/next_token_wrapper.rb
Ruby
mit
45
master
1,651
module AwsDevUtils class NextTokenWrapper DEFAULT_MAX=100 # Initialize a new NextTokenWrapper, internal use only # @params client [Aws client / NextTokenWrapper / RetryWrapper] # @param max [Integer] - max number of requests def initialize client, max=DEFAULT_MAX @client = client @ma...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
lib/aws-dev-utils/retry_wrapper.rb
Ruby
mit
45
master
757
module AwsDevUtils class RetryWrapper # Initialize a new RetryWrapper, internal use only # @params client [Aws client, NextTokenWrapper, RetryWrapper] # @param max_tries [Integer] - max number of retries def initialize client, max_tries=5 @client = client @max_tries = max_tries end ...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
lib/aws-dev-utils/refinements.rb
Ruby
mit
45
master
344
require 'aws-sdk-core' module AwsDevUtils module Refinements refine Seahorse::Client::Base do def with_next_token *args c = AwsDevUtils::ClientWrapper.new(self) c.send(__callee__, *args) end alias_method :with_retry, :with_next_token alias_method :with_cache, :with_next_t...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
lib/aws-dev-utils/cache.rb
Ruby
mit
45
master
1,412
require 'singleton' require 'forwardable' module AwsDevUtils class Cache include Singleton # Injectable backend. attr_writer :backend class << self extend Forwardable def_delegators :fetch end # Returns a value from the cache for the given key. # If the key can't be found,...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
lib/aws-dev-utils/client_wrapper.rb
Ruby
mit
45
master
1,504
module AwsDevUtils class ClientWrapper include AwsDevUtils::Utils # Initialize a new ClientWrapper, internal use only # @params [Seahorse::Client::Base] client # @param [Hash] options # @option options [String] next_token max number of requests # @option options [String] retry max number of r...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
lib/aws-dev-utils/backends/redis.rb
Ruby
mit
45
master
703
require 'redis' module AwsDevUtils module Backend class Redis # :nocov: # Initialize a new redis client. # @params url [String] - specify redis url connection def initialize url='redis://localhost:6379' @redis = ::Redis.new(url: url) end # Get the value of key, if not...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
lib/aws-dev-utils/backends/memory.rb
Ruby
mit
45
master
748
module AwsDevUtils module Backend class Memory def initialize @hash = {} end # Get the value of key, if not found, returns nil. def get key clean_cache! @hash[key][1] end # Set key to hold the value and set key to timeout after the a given expiration ...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
tests/minitest_helper.rb
Ruby
mit
45
master
645
require 'simplecov' SimpleCov.start do add_filter "/tests/" end $:.unshift File.expand_path("../../lib",__FILE__) require 'aws-dev-utils' require 'minitest' require 'minitest/autorun' if ENV['CODECOV_TOKEN'] require 'codecov' SimpleCov.formatter = SimpleCov::Formatter::Codecov end module AwsDevUtils class Te...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
tests/unit/cache_test.rb
Ruby
mit
45
master
862
require_relative '../minitest_helper' require 'ostruct' module AwsDevUtils class CacheTester < TestCase def test_serialize_deserialize r = OpenStruct.new(a: 1,b: 2, c: 3) s = cache.send(:deserialize, cache.send(:serialize, r)) assert_equal r,s end def test_serialize_throw_exceptions ...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
tests/unit/next_token_wrapper_test.rb
Ruby
mit
45
master
4,861
require_relative '../minitest_helper' require 'ostruct' module AwsDevUtils class NextTokenWrapperTester < TestCase def test_no_value_with_token client = client_setup assert_equal({vals: nil}, client.mock_next_token) assert_equal 1, client.counters[:mock_next_token] end def test_no_v...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
tests/unit/refinements_test.rb
Ruby
mit
45
master
769
require_relative '../minitest_helper' require 'ostruct' require 'aws-sdk-core' using AwsDevUtils::Refinements module AwsDevUtils class RefinementsTester < TestCase def test_retry_wrapper client = Aws::STS::Client.new(region: "foo") assert_instance_of ClientWrapper, client.with_retry end de...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
tests/unit/cache_wrapper_test.rb
Ruby
mit
45
master
2,410
require_relative '../minitest_helper' require 'ostruct' require 'aws-sdk-core' require 'deepsort' module AwsDevUtils class CacheWrapperTester < TestCase def setup cache.backend = Backend::Memory.new end def teardown cache.backend = nil end def test_with_cache_set_value_without_arg...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
tests/unit/utils_test.rb
Ruby
mit
45
master
2,488
require_relative '../minitest_helper' require 'ostruct' module AwsDevUtils class UtilsTester < TestCase include AwsDevUtils::Utils def test_nested_struct_no_argument assert_raises(ArgumentError) {nested_struct} end def test_nested_struct_empty_hash h = {} s = OpenStruct.new ...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
tests/unit/client_wrapper_test.rb
Ruby
mit
45
master
3,942
require_relative '../minitest_helper' require 'ostruct' require 'aws-sdk-core' module AwsDevUtils class ClientWrapperTester < TestCase using AwsDevUtils::Refinements def test_with_cache client = Aws::STS::Client.new(region: "foo") a = client.with_cache assert_instance_of ClientWrapper, a ...
github
kontera-technologies/aws-dev-utils
https://github.com/kontera-technologies/aws-dev-utils
tests/unit/retry_wrapper_test.rb
Ruby
mit
45
master
1,459
require_relative '../minitest_helper' require 'ostruct' module AwsDevUtils class RetryWrapperTester < TestCase def test_no_retry client = client_setup 0 assert_equal :mock_value, client.mock_func assert_equal 1, client.counters[:mock_func] end def test_successful_retry_with_default_ma...
github
openfoodfacts/openfoodfacts-ruby
https://github.com/openfoodfacts/openfoodfacts-ruby
Rakefile
Ruby
mit
44
main
394
# frozen_string_literal: true require 'bundler/gem_tasks' require 'rake/testtask' Rake::TestTask.new do |task| task.libs << 'lib' task.libs << 'test' task.pattern = 'test/test_*.rb' end task default: :test desc 'Load gem inside irb console' task :console do require 'irb' require 'irb/completion' require...
github
openfoodfacts/openfoodfacts-ruby
https://github.com/openfoodfacts/openfoodfacts-ruby
openfoodfacts.gemspec
Ruby
mit
44
main
1,403
# frozen_string_literal: true lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'openfoodfacts/version' Gem::Specification.new do |spec| spec.name = 'openfoodfacts' spec.version = Openfoodfacts::VERSION spec.authors = ['Nicolas Leger', 'P...
github
openfoodfacts/openfoodfacts-ruby
https://github.com/openfoodfacts/openfoodfacts-ruby
test/minitest_helper.rb
Ruby
mit
44
main
485
# frozen_string_literal: true $LOAD_PATH.unshift File.expand_path('../lib', __dir__) require 'openfoodfacts' require 'minitest/autorun' require 'webmock/minitest' require 'vcr' # Avoid OpenSSL certificate verify failed error if ENV.key?('APPVEYOR') && Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.4') requi...
github
openfoodfacts/openfoodfacts-ruby
https://github.com/openfoodfacts/openfoodfacts-ruby
test/test_openfoodfacts.rb
Ruby
mit
44
main
13,847
# frozen_string_literal: true require_relative 'minitest_helper' class TestOpenfoodfacts < Minitest::Test # Gem def test_that_it_has_a_version_number refute_nil ::Openfoodfacts::VERSION end # Locale def test_it_fetches_locales VCR.use_cassette('index') do locales = ::Openfoodfacts::Locale.a...
github
openfoodfacts/openfoodfacts-ruby
https://github.com/openfoodfacts/openfoodfacts-ruby
lib/openfoodfacts.rb
Ruby
mit
44
main
2,233
# frozen_string_literal: true require_relative 'openfoodfacts/additive' require_relative 'openfoodfacts/brand' require_relative 'openfoodfacts/category' require_relative 'openfoodfacts/city' require_relative 'openfoodfacts/contributor' require_relative 'openfoodfacts/country' require_relative 'openfoodfacts/entry_date...
github
openfoodfacts/openfoodfacts-ruby
https://github.com/openfoodfacts/openfoodfacts-ruby
lib/openfoodfacts/additive.rb
Ruby
mit
44
main
1,212
# frozen_string_literal: true require 'hashie' module Openfoodfacts class Additive < Hashie::Mash # TODO: Add more locales LOCALE_PATHS = { 'fr' => 'additifs', 'uk' => 'additives', 'us' => 'additives', 'world' => 'additives' }.freeze class << self # Get additives ...
github
openfoodfacts/openfoodfacts-ruby
https://github.com/openfoodfacts/openfoodfacts-ruby
lib/openfoodfacts/product_state.rb
Ruby
mit
44
main
708
# frozen_string_literal: true require 'hashie' module Openfoodfacts class ProductState < Hashie::Mash # TODO: Add more locales LOCALE_PATHS = { 'fr' => 'etats', 'uk' => 'states', 'us' => 'states', 'world' => 'states' }.freeze class << self # Get product states # ...
github
openfoodfacts/openfoodfacts-ruby
https://github.com/openfoodfacts/openfoodfacts-ruby
lib/openfoodfacts/purchase_place.rb
Ruby
mit
44
main
748
# frozen_string_literal: true require 'hashie' module Openfoodfacts class PurchasePlace < Hashie::Mash # TODO: Add more locales LOCALE_PATHS = { 'fr' => 'lieux-de-vente', 'uk' => 'purchase-places', 'us' => 'purchase-places', 'world' => 'purchase-places' }.freeze class << sel...
github
openfoodfacts/openfoodfacts-ruby
https://github.com/openfoodfacts/openfoodfacts-ruby
lib/openfoodfacts/ingredient_that_may_be_from_palm_oil.rb
Ruby
mit
44
main
911
# frozen_string_literal: true require 'hashie' module Openfoodfacts class IngredientThatMayBeFromPalmOil < Hashie::Mash # TODO: Add more locales LOCALE_PATHS = { 'fr' => 'ingredients-pouvant-etre-issus-de-l-huile-de-palme', 'uk' => 'ingredients-that-may-be-from-palm-oil', 'us' => 'ingredie...
github
openfoodfacts/openfoodfacts-ruby
https://github.com/openfoodfacts/openfoodfacts-ruby
lib/openfoodfacts/faq.rb
Ruby
mit
44
main
1,292
# frozen_string_literal: true require 'hashie' require 'nokogiri' module Openfoodfacts class Faq < Hashie::Mash # TODO: Add more locales LOCALE_PATHS = { 'fr' => 'questions-frequentes', 'uk' => 'faq', 'us' => 'faq', 'world' => 'faq' }.freeze class << self def items(loc...
github
openfoodfacts/openfoodfacts-ruby
https://github.com/openfoodfacts/openfoodfacts-ruby
lib/openfoodfacts/language.rb
Ruby
mit
44
main
713
# frozen_string_literal: true require 'hashie' module Openfoodfacts class Language < Hashie::Mash # TODO: Add more locales LOCALE_PATHS = { 'fr' => 'langues', 'uk' => 'languages', 'us' => 'languages', 'world' => 'languages' }.freeze class << self # Get languages ...