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 | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | config/initializers/inflections.rb | Ruby | mit | 47 | master | 436 | # Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'p... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | config/initializers/secret_token.rb | Ruby | mit | 47 | master | 500 | # Be sure to restart your server when you modify this file.
# Your secret key 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 dictionary attac... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | config/initializers/i18n.rb | Ruby | mit | 47 | master | 223 | module I18n
module Globalizable
def t(options = {})
I18n.t(self, options.merge(default: self.split('.').last))
end
end
end
String.send :include, I18n::Globalizable
Symbol.send :include, I18n::Globalizable |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | config/initializers/session_store.rb | Ruby | mit | 47 | master | 423 | # Be sure to restart your server when you modify this file.
ConnectOp::Application.config.session_store :cookie_store, :key => '_connect-op_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with ... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | config/initializers/mime_types.rb | Ruby | mit | 47 | master | 254 | # Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
Mime::Type.register 'application/jrd+json', :jrd |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | config/environments/test.rb | Ruby | mit | 47 | master | 1,515 | ConnectOp::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 tes... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | config/environments/production.rb | Ruby | mit | 47 | master | 1,858 | ConnectOp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned ... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | config/environments/development.rb | Ruby | mit | 47 | master | 941 | ConnectOp::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... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/models/client.rb | Ruby | mit | 47 | master | 2,076 | class Client < ActiveRecord::Base
[:contacts, :redirect_uris, :raw_registered_json].each do |serializable|
serialize serializable, JSON
end
belongs_to :account
has_many :access_tokens
has_many :authorizations
before_validation :setup, on: :create
validates :account, presence: {unless: :dynamic?}... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/models/request_object.rb | Ruby | mit | 47 | master | 490 | class RequestObject < ActiveRecord::Base
has_one :access_token_request_object
has_one :access_token, through: :access_token_request_object
has_one :authorization_request_object
has_one :authorization, through: :authorization_request_object
has_one :id_token_request_object
has_one :id_token, through: :id_tok... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/models/access_token.rb | Ruby | mit | 47 | master | 1,133 | class AccessToken < ActiveRecord::Base
belongs_to :account
belongs_to :client
has_many :access_token_scopes
has_many :scopes, through: :access_token_scopes
has_one :access_token_request_object
has_one :request_object, through: :access_token_request_object
before_validation :setup, on: :create
validate... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/models/authorization_request_object.rb | Ruby | mit | 47 | master | 204 | class AuthorizationRequestObject < ActiveRecord::Base
belongs_to :authorization
belongs_to :request_object
validates :authorization, presence: true
validates :request_object, presence: true
end |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/models/scope.rb | Ruby | mit | 47 | master | 315 | class Scope < ActiveRecord::Base
has_many :access_token_scopes
has_many :access_tokens, through: :access_token_scopes
has_many :authorization_scopes
has_many :authorizations, through: :authorization_scopes
validates :name, presence: true, uniqueness: true
include ConstantCache
caches_constants
end |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/models/authorization.rb | Ruby | mit | 47 | master | 1,079 | class Authorization < ActiveRecord::Base
belongs_to :account
belongs_to :client
has_many :authorization_scopes
has_many :scopes, through: :authorization_scopes
has_one :authorization_request_object
has_one :request_object, through: :authorization_request_object
before_validation :setup, on: :create
va... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/models/pairwise_pseudonymous_identifier.rb | Ruby | mit | 47 | master | 413 | class PairwisePseudonymousIdentifier < ActiveRecord::Base
belongs_to :account
belongs_to :client
before_validation :setup, on: :create
validates :account, presence: true
validates :sector_identifier, presence: true, uniqueness: {scope: :account_id}
validates :identifier, presence: true, u... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/models/account.rb | Ruby | mit | 47 | master | 1,463 | class Account < ActiveRecord::Base
has_one :facebook, class_name: 'Connect::Facebook'
has_one :google, class_name: 'Connect::Google'
has_one :fake, class_name: 'Connect::Fake'
has_many :clients
has_many :access_tokens
has_many :authorizations
has_many :id_tokens
has_many :pairwise_pseudonymous_ide... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/models/id_token.rb | Ruby | mit | 47 | master | 2,772 | class IdToken < ActiveRecord::Base
belongs_to :account
belongs_to :client
has_one :id_token_request_object
has_one :request_object, through: :id_token_request_object
before_validation :setup, on: :create
validates :account, presence: true
validates :client, presence: true
scope :valid, lambda {
... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/models/access_token_request_object.rb | Ruby | mit | 47 | master | 201 | class AccessTokenRequestObject < ActiveRecord::Base
belongs_to :access_token
belongs_to :request_object
validates :access_token, presence: true
validates :request_object, presence: true
end |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/models/connect/fake.rb | Ruby | mit | 47 | master | 493 | class Connect::Fake < ActiveRecord::Base
belongs_to :account
def userinfo
OpenIDConnect::ResponseObject::UserInfo.new(
name: 'Fake Account',
email: 'fake@example.com',
address: 'Shibuya, Tokyo, Japan',
profile: 'http://example.com/fake',
locale: 'ja_... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/models/connect/facebook.rb | Ruby | mit | 47 | master | 1,433 | class Connect::Facebook < ActiveRecord::Base
belongs_to :account
validates :identifier, presence: true, uniqueness: true
validates :access_token, presence: true, uniqueness: true
def me
@me ||= FbGraph::User.me(self.access_token).fetch
end
def userinfo
attributes = {
id: identifier,... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/models/connect/google.rb | Ruby | mit | 47 | master | 2,655 | class Connect::Google < ActiveRecord::Base
serialize :id_token
belongs_to :account
validates :identifier, presence: true, uniqueness: true
validates :access_token, presence: true, uniqueness: true
def userinfo
unless @userinfo
hash = call_api self.class.config[:userinfo_endpoint]
@userinf... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/controllers/clients_controller.rb | Ruby | mit | 47 | master | 938 | class ClientsController < ApplicationController
before_filter :require_authentication
def new
@client = current_account.clients.new
end
def create
@client = current_account.clients.new params[:client]
if @client.save
redirect_to dashboard_url, flash: {
notice: "Registered #{@client.n... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/controllers/authorizations_controller.rb | Ruby | mit | 47 | master | 1,454 | class AuthorizationsController < ApplicationController
rescue_from Rack::OAuth2::Server::Authorize::BadRequest do |e|
@error = e
logger.info e.backtrace[0,10].join("\n")
render :error, status: e.status
end
def new
call_authorization_endpoint
end
def create
call_authorization_endpoint :al... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/controllers/application_controller.rb | Ruby | mit | 47 | master | 337 | class ApplicationController < ActionController::Base
include Authentication
include Notification
rescue_from HttpError do |e|
render status: e.status, nothing: true
end
rescue_from FbGraph::Exception, Rack::OAuth2::Client::Error do |e|
redirect_to root_url, flash: {error: e.message}
end
protect_... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/controllers/user_info_controller.rb | Ruby | mit | 47 | master | 729 | class UserInfoController < ApplicationController
before_filter :require_user_access_token
rescue_from FbGraph::Exception, Rack::OAuth2::Client::Error do |e|
provider = case e
when FbGraph::Exception
'Facebook'
when Rack::OAuth2::Client::Error
'Google'
end
raise Rack::OAuth2::Server:... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/controllers/discovery_controller.rb | Ruby | mit | 47 | master | 1,491 | class DiscoveryController < ApplicationController
def show
case params[:id]
when 'webfinger'
webfinger_discovery
when 'openid-configuration'
openid_configuration
else
raise HttpError::NotFound
end
end
private
def webfinger_discovery
jrd = {
links: [{
rel... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/controllers/connect/google_controller.rb | Ruby | mit | 47 | master | 454 | class Connect::GoogleController < ApplicationController
before_filter :require_anonymous_access
def show
if params[:code].blank? || session[:state] != params[:state]
raise AuthenticationRequired.new
end
authenticate Connect::Google.authenticate(params[:code])
logged_in!
end
def new
s... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | app/controllers/connect/clients_controller.rb | Ruby | mit | 47 | master | 742 | class Connect::ClientsController < ApplicationController
skip_before_filter :verify_authenticity_token
rescue_from HttpError do |e|
render json: {
error: :invalid_request,
error_description: e.message
}, status: 400
end
rescue_from OpenIDConnect::ValidationFailed do |e|
logger.info e.ob... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/schema.rb | Ruby | mit | 47 | master | 5,422 | # encoding: UTF-8
# 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 sou... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20110829023820_create_accounts.rb | Ruby | mit | 47 | master | 294 | class CreateAccounts < ActiveRecord::Migration
def self.up
create_table :accounts do |t|
t.string :identifier
t.datetime :last_logged_in_at
t.timestamps
end
add_index :accounts, :identifier, unique: true
end
def self.down
drop_table :accounts
end
end |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20110829023936_create_access_token_scopes.rb | Ruby | mit | 47 | master | 252 | class CreateAccessTokenScopes < ActiveRecord::Migration
def self.up
create_table :access_token_scopes do |t|
t.belongs_to :access_token, :scope
t.timestamps
end
end
def self.down
drop_table :access_token_scopes
end
end |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20110829024031_create_connect_facebooks.rb | Ruby | mit | 47 | master | 275 | class CreateConnectFacebooks < ActiveRecord::Migration
def self.up
create_table :connect_facebook do |t|
t.belongs_to :account
t.string :identifier, :access_token
t.timestamps
end
end
def self.down
drop_table :connect_facebooks
end
end |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20110910061828_create_connect_fakes.rb | Ruby | mit | 47 | master | 222 | class CreateConnectFakes < ActiveRecord::Migration
def self.up
create_table :connect_fakes do |t|
t.belongs_to :account
t.timestamps
end
end
def self.down
drop_table :connect_fakes
end
end |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20120228164610_create_access_token_request_objects.rb | Ruby | mit | 47 | master | 218 | class CreateAccessTokenRequestObjects < ActiveRecord::Migration
def change
create_table :access_token_request_objects do |t|
t.belongs_to :access_token, :request_object
t.timestamps
end
end
end |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20110829024010_create_id_tokens.rb | Ruby | mit | 47 | master | 270 | class CreateIdTokens < ActiveRecord::Migration
def self.up
create_table :id_tokens do |t|
t.belongs_to :account, :client
t.string :nonce
t.datetime :expires_at
t.timestamps
end
end
def self.down
drop_table :id_tokens
end
end |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20110829023826_create_clients.rb | Ruby | mit | 47 | master | 523 | class CreateClients < ActiveRecord::Migration
def self.up
create_table :clients do |t|
t.belongs_to :account
t.string(
:identifier,
:secret,
:name,
:jwks_uri,
:sector_identifier,
:redirect_uris
)
t.boolean :dynamic, :native, :ppid, default: f... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20120228164626_create_authorization_request_objects.rb | Ruby | mit | 47 | master | 222 | class CreateAuthorizationRequestObjects < ActiveRecord::Migration
def change
create_table :authorization_request_objects do |t|
t.belongs_to :authorization, :request_object
t.timestamps
end
end
end |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20110829023928_create_scopes.rb | Ruby | mit | 47 | master | 238 | class CreateScopes < ActiveRecord::Migration
def self.up
create_table :scopes do |t|
t.string :name
t.timestamps
end
add_index :scopes, :name, unique: true
end
def self.down
drop_table :scopes
end
end |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20110829023837_create_access_tokens.rb | Ruby | mit | 47 | master | 333 | class CreateAccessTokens < ActiveRecord::Migration
def self.up
create_table :access_tokens do |t|
t.belongs_to :account, :client
t.string :token
t.datetime :expires_at
t.timestamps
end
add_index :access_tokens, :token, unique: true
end
def self.down
drop_table :access_toke... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20120229153919_create_id_token_request_objects.rb | Ruby | mit | 47 | master | 206 | class CreateIdTokenRequestObjects < ActiveRecord::Migration
def change
create_table :id_token_request_objects do |t|
t.belongs_to :id_token, :request_object
t.timestamps
end
end
end |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20110829023844_create_authorizations.rb | Ruby | mit | 47 | master | 359 | class CreateAuthorizations < ActiveRecord::Migration
def self.up
create_table :authorizations do |t|
t.belongs_to :account, :client
t.string :code, :nonce, :redirect_uri
t.datetime :expires_at
t.timestamps
end
add_index :authorizations, :code, unique: true
end
def self.down
... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20110829024041_create_connect_googles.rb | Ruby | mit | 47 | master | 292 | class CreateConnectGoogles < ActiveRecord::Migration
def self.up
create_table :connect_google do |t|
t.belongs_to :account
t.string :identifier, :access_token
t.text :id_token
t.timestamps
end
end
def self.down
drop_table :connect_googles
end
end |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20110829024140_create_pairwise_pseudonymous_identifiers.rb | Ruby | mit | 47 | master | 328 | class CreatePairwisePseudonymousIdentifiers < ActiveRecord::Migration
def self.up
create_table :pairwise_pseudonymous_identifiers do |t|
t.belongs_to :account
t.string :identifier, :sector_identifier
t.timestamps
end
end
def self.down
drop_table :pairwise_pseudonymous_identifiers
... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | db/migrate/20110829023945_create_authorization_scopes.rb | Ruby | mit | 47 | master | 257 | class CreateAuthorizationScopes < ActiveRecord::Migration
def self.up
create_table :authorization_scopes do |t|
t.belongs_to :authorization, :scope
t.timestamps
end
end
def self.down
drop_table :authorization_scopes
end
end |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | lib/authorization_endpoint.rb | Ruby | mit | 47 | master | 3,159 | class AuthorizationEndpoint
attr_accessor :app, :account, :client, :redirect_uri, :response_type, :scopes, :_request_, :request_uri, :request_object
delegate :call, to: :app
def initialize(current_account, allow_approval = false, approved = false)
@account = current_account
@app = Rack::OAuth2::Server::A... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | lib/authentication.rb | Ruby | mit | 47 | master | 2,577 | module Authentication
class AuthenticationRequired < StandardError; end
class AnonymousAccessRequired < StandardError; end
def self.included(klass)
klass.send :include, Authentication::Helper
klass.send :before_filter, :optional_authentication
klass.send :rescue_from, AuthenticationRequired, with: ... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | lib/notification.rb | Ruby | mit | 47 | master | 393 | module Notification
def self.included(klass)
klass.send :after_filter, :flash_to_cookie
end
def flash_to_cookie
[:notice, :warn, :error].each do |key|
if (_flash_ = flash[key]).present?
if _flash_.is_a?(String)
_flash_ = {text: _flash_}
end
cookies["flash.#{key}"] ... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | lib/http_error.rb | Ruby | mit | 47 | master | 459 | class HttpError < StandardError
attr_reader :status
def initialize(status, message = nil)
super message
@status = status
end
class BadRequest < HttpError
def initialize(message = nil)
super 400, message
end
end
class Unauthorized < HttpError
def initialize(message = nil)
su... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | lib/token_endpoint.rb | Ruby | mit | 47 | master | 1,445 | class TokenEndpoint
attr_accessor :app
delegate :call, to: :app
def initialize
@app = Rack::OAuth2::Server::Token.new do |req, res|
client = Client.find_by_identifier(req.client_id) || req.invalid_client!
client.secret == req.client_secret || req.invalid_client!
case req.grant_type
wh... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | lib/mobile_helper.rb | Ruby | mit | 47 | master | 489 | module MobileHelper
include MetaDataHelper
module Apple
def apple_app_capable_meta_tag
meta_tag 'apple-mobile-web-app-capable', 'yes'
end
def apple_app_icon_link_tag
link_tag 'apple-touch-icon', image_path('icon.png')
end
end
include Apple
def viewport_meta_tag
meta_tag :vie... |
github | nov/openid_connect_sample | https://github.com/nov/openid_connect_sample | lib/meta_data_helper.rb | Ruby | mit | 47 | master | 232 | module MetaDataHelper
def meta_tag(name, content, options = {})
tag :meta, options.merge(name: name, content: content)
end
def link_tag(rel, href, options = {})
tag :link, options.merge(rel: rel, href: href)
end
end |
github | hopsoft/bg | https://github.com/hopsoft/bg | Rakefile | Ruby | mit | 47 | master | 245 | require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new do |t|
t.test_files = FileList["tests/**/test_*.rb"]
t.libs.push "test"
t.pattern = "test/**/*_test.rb"
t.warning = true
t.verbose = true
end
task default: :test |
github | hopsoft/bg | https://github.com/hopsoft/bg | bg.gemspec | Ruby | mit | 47 | master | 873 | require_relative "lib/bg/version"
Gem::Specification.new do |gem|
gem.name = "bg"
gem.license = "MIT"
gem.version = Bg::VERSION
gem.authors = ["Nathan Hopkins"]
gem.email = ["natehop@gmail.com"]
gem.homepage = "https://github.com/hopsoft/bg"
gem.summary = ""
gem.files ... |
github | hopsoft/bg | https://github.com/hopsoft/bg | Gemfile | Ruby | mit | 47 | master | 557 | source "https://rubygems.org"
# Declare your gem's dependencies in bg.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
# Declare any dependencies that are still in development here instead of in
# your... |
github | hopsoft/bg | https://github.com/hopsoft/bg | test/backgroundable_object.rb | Ruby | mit | 47 | master | 348 | require "globalid"
class Bg::BackgroundableObject
include ::GlobalID::Identification
def self.find(id)
new id
end
attr_accessor :id
def initialize(id)
@id = id
end
def update(attrs={})
true
end
def wait(seconds=0)
sleep seconds.to_i
true
end
def eigen
class << self
... |
github | hopsoft/bg | https://github.com/hopsoft/bg | test/test_helper.rb | Ruby | mit | 47 | master | 429 | require "coveralls"
Coveralls.wear!
require_relative "../lib/bg"
require_relative "backgroundable_object"
require "minitest/autorun"
require "purdytest"
require "pry"
require "pry-nav"
require "pry-stack_explorer"
::ActiveSupport::TestCase.test_order = :random
::GlobalID.app = "test"
::ActiveRecord::Base = Class.new d... |
github | hopsoft/bg | https://github.com/hopsoft/bg | test/bg/deferrable_test.rb | Ruby | mit | 47 | master | 2,469 | require_relative "../test_helper"
class Bg::DeferrableTest < ::ActiveSupport::TestCase
setup do
@deferrable = ::Bg::Deferrable.new(::Bg::BackgroundableObject.new(:example))
end
test ".make_enqueable with Symbol" do
value = ::Bg::Deferrable.make_enqueable(:foo)
assert value == "foo"
end
test ".... |
github | hopsoft/bg | https://github.com/hopsoft/bg | test/bg/deferred_method_call_test.rb | Ruby | mit | 47 | master | 1,541 | require_relative "../test_helper"
require "active_job/test_helper"
class Bg::DeferredMethodCallJobTest < ::ActiveJob::TestCase
test "enqueues with no args" do
assert_enqueued_with job: ::Bg::DeferredMethodCallJob do
obj = ::Bg::BackgroundableObject.new(:example)
obj.eigen.send :include, ::Bg::Deferr... |
github | hopsoft/bg | https://github.com/hopsoft/bg | test/bg/asyncable_test.rb | Ruby | mit | 47 | master | 358 | require_relative "../test_helper"
class Bg::AsyncableTest < ::ActiveSupport::TestCase
test "slow io bound method invocations run in parallel" do
obj = ::Bg::BackgroundableObject.new(:example)
obj.eigen.send :include, ::Bg::Asyncable::Behavior
start = Time.now
10.times { obj.async.wait 1 }
assert... |
github | hopsoft/bg | https://github.com/hopsoft/bg | lib/bg/deferrable.rb | Ruby | mit | 47 | master | 1,717 | require "globalid"
require "bg/deferred_method_call_job"
module Bg
class Deferrable
module Behavior
# Enqueues the method call to be executed by a DeferredMethodCallJob background worker.
def defer(queue: :default, wait: 0)
::Bg::Deferrable.new self, queue: queue, wait: wait
end
end... |
github | hopsoft/bg | https://github.com/hopsoft/bg | lib/bg/asyncable.rb | Ruby | mit | 47 | master | 1,476 | require "active_record"
require "concurrent"
module Bg
class Asyncable
class Wrapper
include ::Concurrent::Async
def initialize(object, wait: 0)
# IMPORTANT: call super without any arguments
# https://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Async.html
super()
... |
github | dohliam/gdcl | https://github.com/dohliam/gdcl | gdcl.rb | Ruby | mit | 47 | master | 11,107 | #!/usr/bin/ruby -KuU
# encoding: utf-8
# invoke with:
# ruby gdcl.rb
# (for interactive search)
# OR
# ruby gdcl.rb [group] [keyword]
# (for non-interactive search)
########################
require 'yaml'
require 'fileutils'
require 'zlib'
require 'optparse'
require 'nokogiri'
require 'open-uri'
config_dir = Dir.ho... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | Vagrantfile | Ruby | mit | 47 | master | 2,008 | # -*- mode: ruby -*-
# vi: set ft=ruby :
defaults = {
count: 1,
flavor: /2GB/,
image: /Trusty/,
run_list: [
'recipe[chef_certificates]'
]
}
nodesets = [
{
name: 'certs',
count: 2,
chef_env: 'certs-prod'
},
{
name: 'stg_certs',
chef_env: 'certs-stg'
}
]
require "yaml"
y = YAM... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | Gemfile | Ruby | mit | 47 | master | 3,302 | source "https://rubygems.org"
ruby "2.2.7"
gem 'rails', '~> 3.2'
gem 'rake', '< 12.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# gem "mongoid", "~> 3.0.0"
# gem 'bson_ext'
gem 'mysql2', '~> 0.3.10' # limit to this version for Rails 3.2
# For some reason this is needed... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | Rakefile | Ruby | mit | 47 | master | 487 | #!/usr/bin/env rake
# 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', __FILE__)
OpenDataCertificate::Application.load_tasks
Rake::Task["default"].clear
task de... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | Guardfile | Ruby | mit | 47 | master | 908 | # A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard :test, all_after_pass: false, all_on_start: false do
watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
watch(%r{^test/.+_test\.rb$})
watch('test/test_helper.rb') { "test" }
# Rails example
watch(%r{^app/models/(.+)\.... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | features/support/helper.rb | Ruby | mit | 47 | master | 1,310 | require 'webmock/cucumber'
require 'sidekiq/testing'
require 'vcr'
begin
require 'pry'
rescue LoadError
end
if ENV['COVERAGE']
require 'coveralls'
Coveralls.wear_merged! 'rails'
end
ENV['CERTIFICATE_HOSTNAME'] = 'test.host'
Sidekiq::Testing.inline!
def load_fixture(file)
File.read( File.join( File.dirname(Fi... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | features/step_definitions/autogeneration_steps.rb | Ruby | mit | 47 | master | 870 | Given(/^my URL autocompletes via DataKitten$/) do
KittenData.any_instance.stubs(:fields).returns(@autocomplete || @body[:dataset])
@autocomplete = @body[:dataset] # Keep this around for the purposes of regeneration
@body[:dataset] = {
documentationUrl: @documentationURL
}
end
Given(/^the field "(.*?)" is... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | features/step_definitions/user_details.rb | Ruby | mit | 47 | master | 1,742 | Given(/^I visit the home page$/) do
visit '/'
end
Given(/^I visit the edit account page$/) do
visit edit_user_registration_path(@user)
end
When(/^I enter an organization of "(.*?)"$/) do |organization|
@organization = organization
first('#user_organization').set(organization)
end
When(/^I agree to the terms$... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | features/step_definitions/certificate_steps.rb | Ruby | mit | 47 | master | 1,228 | def get_user(email)
User.find_or_create_by_email(email) do |u|
u.password = "password"
end
end
When(/^I am signed in as "(.*?)"$/) do |email|
@user = get_user(email)
visit '/users/sign_in'
first('#main #sign_in_user_form_user_email').set(email)
first('#main #sign_in_user_form_user_password').set("passw... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | features/step_definitions/factory_steps.rb | Ruby | mit | 47 | master | 3,395 | Given(/^I have a a dataset at the URL "(.*?)"$/) do |url|
@url = url
end
Given(/^I create a single certificate$/) do
CertificateFactory::Certificate.new(@url, @api_user.id, jurisdiction: 'cert-generator').generate
end
Then(/^there should be (\d+) certificates?$/) do |count|
assert_equal count.to_i, Certificate.... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | features/step_definitions/campaign_steps.rb | Ruby | mit | 47 | master | 3,265 | When(/^I visit the campaigns page$/) do
visit campaigns_path
end
Then(/^I should see "(.*?)"$/) do |text|
assert_match text, page.body
end
Then(/^I should not see "(.*?)"$/) do |text|
refute_match /#{text}/, page.body
end
When(/^I visit the campaign page for "(.*?)"$/) do |name|
campaign = CertificationCamp... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | features/step_definitions/api_steps.rb | Ruby | mit | 47 | master | 6,430 | Given(/^I want to create a certificate via the API$/) do
@documentationURL = 'http://example.com/dataset'
stub_request(:any, /http:\/\/.*example.com\/.*/).
to_return(:status => 200, :body => "", :headers => {})
@body = {
jurisdiction: 'cert-generator',
dataset: {
dataTitle: 'Example Datase... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/user_export.rb | Ruby | mit | 47 | master | 592 | class UserExport
def self.perform
file = upload
file.public_url
end
def self.users
User.engaged_users
end
def self.csv
CSV.generate do |csv|
csv << ['Name', 'Email']
users.each { |u| csv << [u.name, u.email] }
end
end
def self.write_file
tmp = Tempfile.new('users.cs... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/odibot.rb | Ruby | mit | 47 | master | 2,564 | class ODIBot
include HTTParty
USER_AGENT = "ODICertCheck 1.1 (+https://certificates.theodi.org/)"
NETWORK_ERRORS = [
EOFError,
SocketError,
Errno::ETIMEDOUT,
Errno::ECONNREFUSED,
Errno::ECONNRESET,
Errno::EHOSTUNREACH,
OpenSSL::SSL::SSLError,
Timeout::Error,
... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/flow.rb | Ruby | mit | 47 | master | 4,756 | class Flow
# will generate a flow chart based on the path that can be navigated through the
# entire scope of the certificates (legal and practical)
attr_accessor :xml, :xml_copy
def initialize(jurisdiction, type, path_param = false)
if path_param.present?
path = path_param
else
path = get... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/email_logger.rb | Ruby | mit | 47 | master | 335 | class EmailLogger
def delivering_email(mail)
title = " YOU HAVE MAIL "
width = 80
puts title.rjust((width+title.length)/2, "=").ljust(width, "=")
puts "To: #{mail.to.join(', ')}"
puts "From: #{mail.from.join(', ')}"
puts "Subject: #{mail.subject}"
puts
puts mail.body
puts "=" * wi... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/translations.rb | Ruby | mit | 47 | master | 958 | module Translations
module Merge
module_function
def merge(out_file, input_files)
merged_output = input_files.reduce({}) do |memo, input_file|
yaml = if File.exist?(input_file)
YAML.load_file(input_file) || {}
else
{}
end
deep_merge!(memo, yaml)
... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/tasks/odc.rake | Ruby | mit | 47 | master | 3,864 | require File.join(Rails.root, 'lib/tasks/overloading_rake_tasks.rb')
override_task :surveyor => :environment do
# overloading the default 'surveyor' task to update the SurveyParsing record
Rake::Task["surveyor:original"].invoke
survey_parsing = SurveyParsing.find_or_create_by_file_name(ENV['FILE'])
raise "Cou... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/tasks/cache_missing_responses.rake | Ruby | mit | 47 | master | 432 | namespace :cache do
desc "Caches uncached missing_responses"
task :missing_responses => :environment do
# We're only caching those response sets that have campaigns because caching them all would take an age
CertificationCampaign.all.each do |campaign|
campaign.certificate_generators.includes(:datase... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/tasks/overloading_rake_tasks.rb | Ruby | mit | 47 | master | 609 | # Ability to overload rake-tasks
# Gleaned from : http://metaskills.net/2010/05/26/the-alias_method_chain-of-rake-override-rake-task/
Rake::TaskManager.class_eval do
def alias_task(fq_name)
new_name = "#{fq_name}:original"
@tasks[new_name] = @tasks.delete(fq_name)
end
end
def alias_task(fq_name)
Rake.app... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/tasks/translations.rake | Ruby | mit | 47 | master | 3,972 | require 'fileutils'
require 'translations'
namespace :translations do
# Translation Steps
#
# Start with
# surveys/definition/questionnaire.general.xml
# surveys/definition/questionnaire.jurisdiction.GB.xml
#
# rake surveys/generated/surveyor/odc_questionnaire.GB.rb
#
# generates:
# surveys/gen... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/tasks/cucumber.rake | Ruby | mit | 47 | master | 2,402 | # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
# It is recommended to regenerate this file in the future when you upgrade to a
# newer version of cucumber-rails. Consider adding your own code to a new file
# instead of editing this one. Cucumber will automatically load all features/**/*... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/extra/stats_dump.rb | Ruby | mit | 47 | master | 1,508 | require 'csv'
require 'rackspace'
module StatsDump
extend RecurringJob
FILENAME = "statistics.csv"
def self.perform
reenqueue_job do
file = Rackspace.dir.files.head FILENAME
if file.nil?
setup
else
latest
end
end
end
def self.next_run_date
1.day.from_no... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/extra/rackspace.rb | Ruby | mit | 47 | master | 812 | require 'fog'
module Rackspace
def self.service
Fog::Storage.new({
:provider => 'Rackspace',
:rackspace_username => ENV['RACKSPACE_USERNAME'],
:rackspace_api_key => ENV['RACKSPACE_API_KEY'],
:rackspace_auth_url => Fog::Rackspace::UK_AUTH_ENDPOINT,
:rackspace... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/extra/survey_builder.rb | Ruby | mit | 47 | master | 1,870 | # for building surveys from delayed job
class SurveyBuilder < Struct.new(:dir, :basename)
def perform
survey_parsing = SurveyParsing.find_or_create_by_file_name(path)
survey_parsing.compute_digest!
changed = survey_parsing.changed? && survey_parsing.save
rebuild = changed || ENV['FORCE_REBUILD'].pre... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/extra/certificate_factory.rb | Ruby | mit | 47 | master | 306 | $:.unshift File.dirname(__FILE__)
require 'httparty'
require 'dotenv'
require 'sidekiq'
Sidekiq.hook_rails!
Dotenv.load
require 'certificate_factory/api'
require 'certificate_factory/certificate'
require 'certificate_factory/factory'
require 'certificate_factory/runner'
module CertificateFactory
end |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/extra/upload_usage_data.rb | Ruby | mit | 47 | master | 1,496 | require 'google_drive'
module UploadUsageData
extend RecurringJob
def self.perform
reenqueue_job do
[
"published",
"all"
].each do |type|
data = certificate_data_by_type(type)
unless data.empty?
csv = create_csv(data)
upload_csv(csv, "#{type.huma... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/extra/certificate_dump.rb | Ruby | mit | 47 | master | 1,715 | require 'rackspace'
module CertificateDump
FILENAME = "certificates.json"
def self.perform
file = Rackspace.dir.files.head FILENAME
if file.nil?
current
else
latest
end
Delayed::Job.enqueue CertificateDump, { :priority => 5, :run_at => 1.day.from_now }
end
def self.... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/extra/csv_export.rb | Ruby | mit | 47 | master | 714 | module CSVExport
extend RecurringJob
FILENAME = 'open-data-certificates.csv'
METADATA = {
content_type: 'text/csv',
content_disposition: 'attachment',
public: true
}
def self.perform
reenqueue_job do
begin
tmp = Tempfile.new('datasets.csv')
DatasetsCSV.new(Dataset.visib... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/extra/recurring_job.rb | Ruby | mit | 47 | master | 487 | module RecurringJob
def reenqueue_job
yield
ensure
enqueue_next_run
end
def enqueue_next_run
# This is disgusting but Delayed::Job has no decent way to query outstanding jobs
# We don't want to enqueue next weeks job more than once if it has to retry due to failures
if Delayed::Job.where(["... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/extra/certificate_factory/factory.rb | Ruby | mit | 47 | master | 5,030 | module CertificateFactory
class HTTPFactory
include Enumerable
include HTTParty
attr_reader :count
def initialize(options)
options.symbolize_keys!
# starting options
if options.fetch(:is_prefetch, false)
@campaign = options[:campaign]
else
@campaign = Certifi... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/extra/certificate_factory/api.rb | Ruby | mit | 47 | master | 230 | module CertificateFactory
class API
include HTTParty
format :json
def initialize(url)
@url = url
@response = self.class.get(@url)
end
def ckan_url
@response['ckan_url']
end
end
end |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/extra/certificate_factory/certificate.rb | Ruby | mit | 47 | master | 1,065 | module CertificateFactory
class Certificate
def initialize(url, user_id, options = {})
@url = url
@user = User.find(user_id)
@dataset_url = options[:dataset_url]
@campaign = options[:campaign]
@jurisdiction = options[:jurisdiction] || "gb"
@create_user = options[:create_user] ... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | lib/extra/certificate_factory/runner.rb | Ruby | mit | 47 | master | 207 | module CertificateFactory
class FactoryRunner
include Sidekiq::Worker
def perform(options)
factory = options.delete('factory').constantize
factory.new(options).build
end
end
end |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | app/helpers/surveyor_helper.rb | Ruby | mit | 47 | master | 1,577 | module SurveyorHelper
include Surveyor::Helpers::SurveyorHelperMethods
include ActionView::Helpers::TagHelper
include ActionView::Helpers::TranslationHelper
include ActionView::Helpers::OutputSafetyHelper
def q_text(q, context=nil, locale=nil)
"#{q.text_for(nil, context, locale)}"
end
# Debug respon... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | app/helpers/devise_helper.rb | Ruby | mit | 47 | master | 680 | module DeviseHelper
def devise_error_messages!
return "" if resource.errors.empty?
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
if resource.errors.include?(:password)
unless resource.errors.include?(:password_confirmation)
resource.errors.add(:password_c... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | app/helpers/application_helper.rb | Ruby | mit | 47 | master | 4,622 | # encoding: utf-8
module ApplicationHelper
def admin?
current_user && current_user.admin?
end
def embed_protocol
Rails.env.production? ? 'https://' : request.protocol
end
# renders an item in the kittenData data
def kitten_value value
case value
when Array
safe_join(value.map {|v| ... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | app/helpers/pages_helper.rb | Ruby | mit | 47 | master | 538 | module PagesHelper
def faq_content(title, &block)
content_for(:faq_navigation, content_tag(:li, link_to(title, anchor: title.parameterize)))
content_for(:faq_body) do
content_tag(:div, id: title.parameterize, class: 'faq') do
concat content_tag(:h2, title)
block.call
end
end
... |
github | theodi/open-data-certificate | https://github.com/theodi/open-data-certificate | app/helpers/campaigns_helper.rb | Ruby | mit | 47 | master | 478 | module CampaignsHelper
def missing_responses(generator, seperator = "\r\n")
generator.response_set.missing_responses
.split(",")
.join(seperator)
end
def report_heading(level)
case(level)
when "uncertified"
return "Missing metadata report"
else
return "Certi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.