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
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/rabarber/inputs/boolean_spec.rb
Ruby
mit
193
main
859
# frozen_string_literal: true require "spec_helper" RSpec.describe Rabarber::Inputs::Boolean do describe "#process" do subject { described_class.new(value, error: Rabarber::Error, message: "Error").process } context "when the given value is valid" do [true, false].each do |valid_value| contex...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/rabarber/inputs/non_empty_symbol_spec.rb
Ruby
mit
193
main
890
# frozen_string_literal: true require "spec_helper" RSpec.describe Rabarber::Inputs::NonEmptySymbol do describe "#process" do subject { described_class.new(value, error: Rabarber::Error, message: "Error").process } context "when the given value is valid" do context "when a string is given" do ...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/rabarber/inputs/role_spec.rb
Ruby
mit
193
main
1,007
# frozen_string_literal: true require "spec_helper" RSpec.describe Rabarber::Inputs::Role do describe "#process" do subject { described_class.new(role, error: Rabarber::InvalidArgumentError, message: "Error").process } context "when the given role is valid" do context "when a symbol is given" do ...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/rabarber/inputs/dynamic_rule_spec.rb
Ruby
mit
193
main
1,133
# frozen_string_literal: true require "spec_helper" RSpec.describe Rabarber::Inputs::DynamicRule do describe "#process" do subject { described_class.new(dynamic_rule, error: Rabarber::InvalidArgumentError, message: "Error").process } context "when the given dynamic rule is valid" do context "when a s...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/rabarber/inputs/contexts/authorizational_spec.rb
Ruby
mit
193
main
1,875
# frozen_string_literal: true require "spec_helper" RSpec.describe Rabarber::Inputs::Contexts::Authorizational do describe "#resolve" do subject { described_class.new(context, error: Rabarber::InvalidArgumentError, message: "Error").resolve } context "when the given context is valid" do context "when...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/rabarber/helpers/migration_helpers_spec.rb
Ruby
mit
193
main
2,261
# frozen_string_literal: true RSpec.describe Rabarber::MigrationHelpers do let(:dummy_migration) { Class.new { include Rabarber::MigrationHelpers }.new } before do User.create!.assign_roles(:manager, context: User) User.create!.assign_roles(:admin, context: User.create!) User.create!.assign_roles(:adm...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/rabarber/helpers/helpers_spec.rb
Ruby
mit
193
main
2,932
# frozen_string_literal: true RSpec.describe Rabarber::Helpers do let(:dummy_helper) { DummyHelper.new(nil, {}, nil) } before { allow(dummy_helper).to receive(:current_user).and_return(user) } describe "#visible_to" do subject { dummy_helper.visible_to(*roles, context:) { "foo" } } let(:user) { User.c...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/rabarber/core/cache_spec.rb
Ruby
mit
193
main
3,096
# frozen_string_literal: true RSpec.describe Rabarber::Core::Cache do include ActiveSupport::Testing::TimeHelpers around do |example| cache_store_was = Rails.cache cache_store_setting_was = Rails.application.config.cache_store Rails.cache = ActiveSupport::Cache::MemoryStore.new Rails.application....
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/rabarber/core/roleable_spec.rb
Ruby
mit
193
main
1,014
# frozen_string_literal: true RSpec.describe Rabarber::Core::Roleable do let(:user) { User.create! } before { allow_any_instance_of(DummyController).to receive(:current_user).and_return(user) } describe "#roleable" do subject { DummyController.new.roleable } it { is_expected.to eq(user) } end des...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/rabarber/core/access_spec.rb
Ruby
mit
193
main
4,714
# frozen_string_literal: true RSpec.describe Rabarber::Core::Access do let(:permissions) { Class.new(Rabarber::Core::Permissions) } before { permissions.extend(described_class) } describe ".access_granted?" do subject { permissions.access_granted?(user, :index, controller_instance) } let(:user) { User...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/rabarber/core/rule_spec.rb
Ruby
mit
193
main
6,896
# frozen_string_literal: true RSpec.describe Rabarber::Core::Rule do describe "#verify_access" do subject { rule.verify_access(roleable, DummyController) } let(:roleable) { double } let(:rule) { described_class.new(:admin, -> { Project }, -> { true }, nil) } context "if all conditions are met" do ...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/rabarber/core/permissions_spec.rb
Ruby
mit
193
main
2,880
# frozen_string_literal: true RSpec.describe Rabarber::Core::Permissions do let(:permissions) { Class.new(described_class) } describe ".add" do let(:rule) { instance_double(Rabarber::Core::Rule) } let(:dynamic_rule) { -> (foo) { foo } } context "when action is given" do before do allow(...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/support/id_schema.rb
Ruby
mit
193
main
1,542
# frozen_string_literal: true ActiveRecord::Schema.define do self.verbose = false create_table "rabarber_roles", force: :cascade do |t| t.string "name", null: false t.string "context_type" t.integer "context_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.in...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/support/controllers.rb
Ruby
mit
193
main
3,261
# frozen_string_literal: true require "action_controller" require "action_view" class DummyPagesController < ActionController::Base def home = head(:ok) end class ApplicationController < ActionController::Base include Rabarber::Authorization with_authorization end class DummyAuthController < ApplicationContr...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/support/models.rb
Ruby
mit
193
main
225
# frozen_string_literal: true class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end class User < ApplicationRecord; end class Client < ApplicationRecord; end class Project < ApplicationRecord; end
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/support/uuid_schema.rb
Ruby
mit
193
main
1,860
# frozen_string_literal: true ActiveRecord::Schema.define do self.verbose = false create_table "rabarber_roles", id: false, force: :cascade do |t| t.string "id", primary_key: true, null: false, limit: 36 t.string "name", null: false t.string "context_type" t.string "context_id", limit: 36 t.da...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/support/application.rb
Ruby
mit
193
main
1,454
# frozen_string_literal: true class DummyApplication < Rails::Application config.eager_load = true config.cache_store = :null_store end DummyApplication.initialize! DummyApplication.routes.draw do root to: "dummy_pages#home" resources :dummy, only: [] do collection do get :multiple_roles pos...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
spec/generators/roles_generator_spec.rb
Ruby
mit
193
main
2,116
# frozen_string_literal: true require "rails/generators" require "generators/rabarber/roles_generator" RSpec.describe Rabarber::RolesGenerator do subject { described_class.start(args) } let(:migration_file) { "db/migrate/20221201201056_create_rabarber_roles.rb" } let(:migration_content) do <<~MIGRATION ...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber.rb
Ruby
mit
193
main
1,500
# frozen_string_literal: true require_relative "rabarber/version" require "active_record" require "active_support" require_relative "rabarber/inputs/base" require_relative "rabarber/inputs/boolean" require_relative "rabarber/inputs/context" require_relative "rabarber/inputs/contexts/authorizational" require_relative...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/generators/rabarber/roles_generator.rb
Ruby
mit
193
main
614
# frozen_string_literal: true require "rails/generators/migration" module Rabarber class RolesGenerator < Rails::Generators::Base include Rails::Generators::Migration source_root File.expand_path("templates", __dir__) argument :table_name, type: :string, required: true class_option :uuid, type: :...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/railtie.rb
Ruby
mit
193
main
1,277
# frozen_string_literal: true require "rails/railtie" module Rabarber class Railtie < Rails::Railtie def self.server_running? !!defined?(Rails::Server) end def self.table_exists? ActiveRecord::Base.connection.data_source_exists?("rabarber_roles") rescue ActiveRecord::NoDatabaseError, Ac...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/configuration.rb
Ruby
mit
193
main
1,851
# frozen_string_literal: true require "singleton" module Rabarber class Configuration include Singleton attr_reader :cache_enabled, :current_user_method, :user_model_name def initialize reset_to_defaults! end def cache_enabled=(value) @cache_enabled = Rabarber::Inputs::Boolean.new...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/helpers/migration_helpers.rb
Ruby
mit
193
main
1,066
# frozen_string_literal: true module Rabarber module MigrationHelpers def migrate_authorization_context!(old_context, new_context) roles = Rabarber::Role.where(context_type: old_context.to_s) raise Rabarber::InvalidArgumentError, "No roles exist in context #{old_context.inspect}" unless roles.exists...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/helpers/helpers.rb
Ruby
mit
193
main
336
# frozen_string_literal: true module Rabarber module Helpers include Rabarber::Core::Roleable def visible_to(*roles, context: nil, &) capture(&) if roleable.has_role?(*roles, context:) end def hidden_from(*roles, context: nil, &) capture(&) unless roleable.has_role?(*roles, context:) ...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/inputs/roles.rb
Ruby
mit
193
main
313
# frozen_string_literal: true module Rabarber module Inputs class Roles < Rabarber::Inputs::Base private def validate_and_normalize Array(@value).map do |role| Rabarber::Inputs::Role.new(role, error: @error, message: @message).process end end end end end
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/inputs/base.rb
Ruby
mit
193
main
574
# frozen_string_literal: true module Rabarber module Inputs class Base def initialize(value, optional: false, error: Rabarber::InvalidArgumentError, message: nil) @value = value @optional = optional @error = error @message = message end def process retur...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/inputs/non_empty_string.rb
Ruby
mit
193
main
260
# frozen_string_literal: true module Rabarber module Inputs class NonEmptyString < Rabarber::Inputs::Base private def validate_and_normalize @value.is_a?(String) && @value.present? ? @value : raise_error end end end end
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/inputs/model.rb
Ruby
mit
193
main
317
# frozen_string_literal: true module Rabarber module Inputs class Model < Rabarber::Inputs::Base private def validate_and_normalize model = @value.try(:safe_constantize) raise_error unless model.is_a?(Class) && model < ActiveRecord::Base model end end end end
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/inputs/context.rb
Ruby
mit
193
main
878
# frozen_string_literal: true module Rabarber module Inputs class Context < Rabarber::Inputs::Base def resolve case context = process when nil { context_type: nil, context_id: nil } when Class { context_type: context.to_s, context_id: nil } when ActiveRec...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/inputs/role.rb
Ruby
mit
193
main
316
# frozen_string_literal: true module Rabarber module Inputs class Role < Rabarber::Inputs::Base private def validate_and_normalize raise_error unless (@value.is_a?(String) || @value.is_a?(Symbol)) && @value.to_s.match?(/\A[a-z0-9_]+\z/) @value.to_sym end end end end
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/inputs/boolean.rb
Ruby
mit
193
main
231
# frozen_string_literal: true module Rabarber module Inputs class Boolean < Rabarber::Inputs::Base private def validate_and_normalize = @value == true || @value == false ? @value : raise_error end end end
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/inputs/non_empty_symbol.rb
Ruby
mit
193
main
305
# frozen_string_literal: true module Rabarber module Inputs class NonEmptySymbol < Rabarber::Inputs::Base private def validate_and_normalize raise_error unless (@value.is_a?(String) || @value.is_a?(Symbol)) && @value.present? @value.to_sym end end end end
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/inputs/dynamic_rule.rb
Ruby
mit
193
main
326
# frozen_string_literal: true module Rabarber module Inputs class DynamicRule < Rabarber::Inputs::Base private def validate_and_normalize return @value if @value.is_a?(Proc) Rabarber::Inputs::NonEmptySymbol.new(@value, error: @error, message: @message).process end end en...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/inputs/contexts/authorizational.rb
Ruby
mit
193
main
541
# frozen_string_literal: true module Rabarber module Inputs module Contexts class Authorizational < Rabarber::Inputs::Context def resolve result = process return result if result.is_a?(Symbol) || result.is_a?(Proc) super end private def valid...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/core/roleable.rb
Ruby
mit
193
main
632
# frozen_string_literal: true module Rabarber module Core module Roleable def roleable current_roleable = send(Rabarber::Configuration.current_user_method) unless current_roleable.is_a?(Rabarber::Configuration.user_model) raise( Rabarber::Error, "Expected ...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/core/cache.rb
Ruby
mit
193
main
1,219
# frozen_string_literal: true require "digest/md5" require "securerandom" module Rabarber module Core module Cache extend self def fetch(roleable_id, scope, &) return yield unless enabled? Rails.cache.fetch(prepare_key(roleable_id, scope), expires_in: 1.hour, race_condition_ttl: 5....
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/core/access.rb
Ruby
mit
193
main
741
# frozen_string_literal: true module Rabarber module Core module Access def access_granted?(roleable, action, controller_instance) controller_accessible?(roleable, controller_instance) || action_accessible?(roleable, action, controller_instance) end def controller_accessible?(roleable,...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/core/permissions.rb
Ruby
mit
193
main
1,079
# frozen_string_literal: true require_relative "access" require_relative "rule" require "singleton" module Rabarber module Core class Permissions include Singleton extend Access attr_reader :storage def initialize @storage = { controller_rules: Hash.new { |h, k| h[k] ...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/core/rule.rb
Ruby
mit
193
main
1,788
# frozen_string_literal: true module Rabarber module Core class Rule DEFAULT_DYNAMIC_RULE = -> { true }.freeze DEFAULT_NEGATED_DYNAMIC_RULE = -> { false }.freeze private_constant :DEFAULT_DYNAMIC_RULE, :DEFAULT_NEGATED_DYNAMIC_RULE def initialize(roles, context, dynamic_rule, negated_dyn...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/models/role.rb
Ruby
mit
193
main
3,640
# frozen_string_literal: true module Rabarber class Role < ActiveRecord::Base self.table_name = "rabarber_roles" belongs_to :context, polymorphic: true, optional: true has_and_belongs_to_many :roleables, class_name: Rabarber::Configuration.user_model_name, associ...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/models/role_management.rb
Ruby
mit
193
main
566
# frozen_string_literal: true module Rabarber module RoleManagement def roles(context: nil) = Rabarber::Role.list(context:) def all_roles = Rabarber::Role.list_all def create_role(name, context: nil) = Rabarber::Role.register(name, context:) def rename_role(old_name, new_name, context: nil, force: fa...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/models/concerns/roleable.rb
Ruby
mit
193
main
3,790
# frozen_string_literal: true module Rabarber module Roleable extend ActiveSupport::Concern included do raise Rabarber::Error, "Rabarber::Roleable can only be included once" if defined?(@@included) && @@included != name @@included = name has_and_belongs_to_many :rabarber_roles, class_nam...
github
enjaku4/rabarber
https://github.com/enjaku4/rabarber
lib/rabarber/controllers/concerns/authorization.rb
Ruby
mit
193
main
2,237
# frozen_string_literal: true module Rabarber module Authorization extend ActiveSupport::Concern include Rabarber::Core::Roleable class_methods do def with_authorization(options = {}) before_action :with_authorization, **options rescue ArgumentError => e raise Rabarber::Inval...
github
rspec/rspec-collection_matchers
https://github.com/rspec/rspec-collection_matchers
Gemfile
Ruby
mit
193
main
1,782
source 'https://rubygems.org' gemspec %w[rspec-metagem rspec-support rspec-core rspec-expectations rspec-mocks].each do |lib| gem_name = lib.sub('rspec-metagem', 'rspec') library_path = File.expand_path("../../#{lib}", __FILE__) if File.exist?(library_path) && !ENV['USE_GIT_REPOS'] gem gem_name, :path => li...
github
rspec/rspec-collection_matchers
https://github.com/rspec/rspec-collection_matchers
rspec-collection_matchers.gemspec
Ruby
mit
193
main
1,627
# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'rspec/collection_matchers/version' Gem::Specification.new do |spec| spec.name = "rspec-collection_matchers" spec.version = RSpec::CollectionMatchers::VERSION spec.authors ...
github
rspec/rspec-collection_matchers
https://github.com/rspec/rspec-collection_matchers
Rakefile
Ruby
mit
193
main
337
require "bundler" Bundler.setup Bundler::GemHelper.install_tasks require "rake" require "rspec/core/rake_task" require "rspec/core/version" require "cucumber/rake/task" Cucumber::Rake::Task.new(:cucumber) desc "Run all examples" RSpec::Core::RakeTask.new(:spec) do |t| t.ruby_opts = %w[-w] end task :default => [:...
github
rspec/rspec-collection_matchers
https://github.com/rspec/rspec-collection_matchers
features/support/env.rb
Ruby
mit
193
main
829
unless defined?(RSpec::Matchers.all) module RSpec module Matchers # aruba assumes this is defined def all end # aruba doesn't alias this itself on 2.99 def an_output_string_including(partial) match partial end end end end require 'aruba/cucumber' Before do if...
github
rspec/rspec-collection_matchers
https://github.com/rspec/rspec-collection_matchers
lib/rspec/collection_matchers.rb
Ruby
mit
193
main
211
require 'rspec/expectations' require 'rspec/collection_matchers/version' require 'rspec/collection_matchers/matchers' require 'rspec/collection_matchers/have' require 'rspec/collection_matchers/rails_extensions'
github
rspec/rspec-collection_matchers
https://github.com/rspec/rspec-collection_matchers
lib/rspec/collection_matchers/matchers.rb
Ruby
mit
193
main
1,956
require 'rspec/matchers' module RSpec module Matchers # Passes if receiver is a collection with the submitted number of items OR # if the receiver OWNS a collection with the submitted number of items. # # If the receiver OWNS the collection, you must use the name of the # collection. So if a `Tea...
github
rspec/rspec-collection_matchers
https://github.com/rspec/rspec-collection_matchers
lib/rspec/collection_matchers/rails_extensions.rb
Ruby
mit
193
main
921
if defined?(::ActiveModel) module ::ActiveModel::Validations # Extension to enhance `to have` on AR Model instances. Calls # model.valid? in order to prepare the object's errors object. Accepts # a :context option to specify the validation context. # # You can also use this to specify the content...
github
rspec/rspec-collection_matchers
https://github.com/rspec/rspec-collection_matchers
lib/rspec/collection_matchers/have.rb
Ruby
mit
193
main
7,221
module RSpec module CollectionMatchers class Have include RSpec::Matchers::Composable unless RSpec::Expectations::Version::STRING.to_f < 3.0 QUERY_METHODS = [:size, :length, :count].freeze IGNORED_CLASSES = [Integer].freeze def initialize(expected, relativity=:exactly) @expected ...
github
rspec/rspec-collection_matchers
https://github.com/rspec/rspec-collection_matchers
spec/spec_helper.rb
Ruby
mit
193
main
504
require 'active_model' # to avoid deprecation warning: # [deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message. I18n.enforce_available_locales = false require 'rspec/...
github
rspec/rspec-collection_matchers
https://github.com/rspec/rspec-collection_matchers
spec/rspec/collection_matchers/have_spec.rb
Ruby
mit
193
main
21,687
require 'spec_helper' require 'stringio' RSpec.describe "have matcher" do let(:inflector) do Class.new do def self.pluralize(string) string.to_s + 's' end end end before(:each) { stub_const("ActiveSupport::Inflector", inflector) } def create_collection_owner_with(n) owner = RS...
github
rspec/rspec-collection_matchers
https://github.com/rspec/rspec-collection_matchers
spec/rspec/collection_matchers/rails_extensions_spec.rb
Ruby
mit
193
main
2,719
require "spec_helper" require 'active_model' module RSpec::CollectionMatchers RSpec.describe "Have extensions for rails" do describe "error_on" do it "provides a description including the name of what the error is on" do expect(have(1).error_on(:whatever).description).to eq "have 1 error on :whatev...
github
rspec/rspec-collection_matchers
https://github.com/rspec/rspec-collection_matchers
spec/support/classes.rb
Ruby
mit
193
main
1,630
# various classes used by the specs module RSpec module Expectations module Helper class CollectionWithSizeMethod def initialize; @list = []; end def size; @list.size; end def push(item); @list.push(item); end end class CollectionWithLengthMethod def initialize; ...
github
rspec/rspec-collection_matchers
https://github.com/rspec/rspec-collection_matchers
spec/support/matchers.rb
Ruby
mit
193
main
503
RSpec::Matchers.define :include_method do |expected| match do |actual| actual.map { |m| m.to_s }.include?(expected.to_s) end end module RSpec module Matchers def fail raise_error(RSpec::Expectations::ExpectationNotMetError) end def fail_with(message) raise_error(RSpec::Expectations::...
github
rspec/rspec-collection_matchers
https://github.com/rspec/rspec-collection_matchers
spec/support/shared_examples.rb
Ruby
mit
193
main
418
RSpec.shared_examples_for "an RSpec matcher" do |options| let(:valid_value) { options.fetch(:valid_value) } let(:invalid_value) { options.fetch(:invalid_value) } it 'matches a valid value when using #== so it can be composed' do expect(matcher).to eq(valid_value) end it 'does not match an invalid valu...
github
elorest/petergate
https://github.com/elorest/petergate
Gemfile
Ruby
mit
193
master
1,368
source 'https://rubygems.org' ruby '3.2.0' # Specify your gem's dependencies in petergate.gemspec gemspec # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 6.0.3.4' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0.4' # Us...
github
elorest/petergate
https://github.com/elorest/petergate
petergate.gemspec
Ruby
mit
193
master
1,246
# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'petergate/version' Gem::Specification.new do |spec| spec.name = "petergate" spec.version = Petergate::VERSION spec.authors = ["Isaac Sloan"] spec.email = ["is...
github
elorest/petergate
https://github.com/elorest/petergate
lib/generators/petergate/install_generator.rb
Ruby
mit
193
master
1,860
require 'securerandom' module Petergate module Generators class InstallGenerator < Rails::Generators::Base include Rails::Generators::Migration source_root File.expand_path("../templates", __FILE__) class_option :orm desc "Sets up rails project for Petergate Authorizations" def sel...
github
elorest/petergate
https://github.com/elorest/petergate
lib/petergate/railtie.rb
Ruby
mit
193
master
235
module Petergate class Railtie < Rails::Railtie config.app_generators do |g| g.scaffold_controller :scaffold_controller g.templates.unshift File::expand_path("../templates", File.dirname(__FILE__)) end end end
github
elorest/petergate
https://github.com/elorest/petergate
lib/petergate/active_record/base.rb
Ruby
mit
193
master
2,327
module Petergate module ActiveRecord module Base def self.included(base) base.extend(ClassMethods) end module ClassMethods def petergate(roles: [:admin], multiple: true) if multiple serialize :roles, coder: YAML after_initialize do ...
github
elorest/petergate
https://github.com/elorest/petergate
lib/petergate/action_controller/base.rb
Ruby
mit
193
master
4,289
module Petergate module ActionController module Base module ClassMethods def const_missing(const_name) if [:AllRest, :ALLREST].include?(const_name) warn "`AllRest` and `ALLREST` has been deprecated. Use :all instead." return ALLRESTDEP else ret...
github
elorest/petergate
https://github.com/elorest/petergate
lib/templates/rails/scaffold_controller/controller.rb
Ruby
mit
193
master
2,053
<% if namespaced? -%> require_dependency "<%= namespaced_file_path %>/application_controller" <% end -%> <% module_namespacing do -%> class <%= controller_class_name %>Controller < ApplicationController before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy] access all: [:index, :sho...
github
elorest/petergate
https://github.com/elorest/petergate
dummy/Rakefile
Ruby
mit
193
master
269
# 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__) Rails.application.load_tasks task default: :test
github
elorest/petergate
https://github.com/elorest/petergate
dummy/app/models/user.rb
Ruby
mit
193
master
937
class User < ActiveRecord::Base ############################################################################################ ## PeterGate Roles ## ## The :user role is added by default and shouldn't be included in this list. ## #...
github
elorest/petergate
https://github.com/elorest/petergate
dummy/app/controllers/blogs_controller.rb
Ruby
mit
193
master
1,868
class BlogsController < InheritanceController before_action :set_blog, only: [:show, :edit, :update, :destroy] # access all: [:index], user: [:index, :show], company_admin: {except: [:destroy]} # GET /blogs # GET /blogs.json def index @blogs = Blog.all end # GET /blogs/1 # GET /blogs/1.json def ...
github
elorest/petergate
https://github.com/elorest/petergate
dummy/db/schema.rb
Ruby
mit
193
master
1,693
# 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
elorest/petergate
https://github.com/elorest/petergate
dummy/db/migrate/20141117064643_devise_create_users.rb
Ruby
mit
193
master
1,349
class DeviseCreateUsers < ActiveRecord::Migration[5.2] def change create_table(:users) do |t| ## Database authenticatable t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: "" ## Recoverable t.string :reset_password_token ...
github
elorest/petergate
https://github.com/elorest/petergate
dummy/test/test_helper.rb
Ruby
mit
193
master
1,374
ENV['RAILS_ENV'] = 'test' require File.expand_path("../../config/environment", __FILE__) require "rails/test_help" require "minitest/rails" # To add Capybara feature tests add `gem "minitest-rails-capybara"` # to the test group in the Gemfile and uncomment the following: # require "minitest/rails/capybara" require "m...
github
elorest/petergate
https://github.com/elorest/petergate
dummy/test/controllers/test_controller_test.rb
Ruby
mit
193
master
1,296
require "test_helper" class TestController < ApplicationController skip_before_action :verify_authenticity_token def index forbidden! params[:msg] end end describe TestController, '#forbidden!' do let(:admin) { users(:admin) } before do User.petergate(roles: [:root_admin, :company_admin], multiple...
github
elorest/petergate
https://github.com/elorest/petergate
dummy/test/controllers/blogs_singular_controller_test.rb
Ruby
mit
193
master
5,313
require "test_helper" describe BlogsController do ################################################################################ # ADMIN ROLE ################################################################################ describe "Singular: Test that everything works if admin is logged in" do before do...
github
elorest/petergate
https://github.com/elorest/petergate
dummy/test/controllers/blogs_multiple_controller_test.rb
Ruby
mit
193
master
7,011
require "test_helper" describe BlogsController do ################################################################################ # ADMIN ROLE ################################################################################ describe "Multiple: Test that everything works if admin is logged in" do before do ...
github
elorest/petergate
https://github.com/elorest/petergate
dummy/test/models/user_test.rb
Ruby
mit
193
master
327
require "test_helper" describe Blog do let(:user) { User.petergate(roles: [:root_admin, :company_admin], multiple: false) User.create(email: "company_admin2@example.com", password: "password1", password_confirmation: "password1", role: :company_admin) } it "must be valid" do user.must_be :valid? e...
github
elorest/petergate
https://github.com/elorest/petergate
dummy/config/application.rb
Ruby
mit
193
master
1,208
require File.expand_path('../boot', __FILE__) require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) require "petergate" module Dummy class Application < Rails::Application config.generators do |g| ...
github
elorest/petergate
https://github.com/elorest/petergate
dummy/config/routes.rb
Ruby
mit
193
master
1,676
Rails.application.routes.draw do devise_for :users resources :blogs get 'test_forbidden' => 'test#index' # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". # You can have the root of your site routed with "root" root '...
github
elorest/petergate
https://github.com/elorest/petergate
dummy/config/environments/test.rb
Ruby
mit
193
master
1,746
Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suit...
github
elorest/petergate
https://github.com/elorest/petergate
dummy/config/initializers/devise.rb
Ruby
mit
193
master
12,753
# 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 invalid all existing # confirmat...
github
mperham/bayes_motel
https://github.com/mperham/bayes_motel
Rakefile
Ruby
mit
193
master
407
require 'bundler/gem_tasks' require 'rake/testtask' require 'rdoc/task' Rake::TestTask.new(:test) do |test| test.libs << 'test' test.pattern = 'test/**/test_*.rb' test.verbose = true end task :default => :test Rake::RDocTask.new do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = "bayes_motel #{BayesMotel::VERSI...
github
mperham/bayes_motel
https://github.com/mperham/bayes_motel
bayes_motel.gemspec
Ruby
mit
193
master
923
lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'bayes_motel' Gem::Specification.new do |gem| gem.name = "bayes_motel" gem.summary = %Q{Bayesian classification engine} gem.description = %Q{http://www.mikeperham.com/2010/04/28/bayes_mote...
github
mperham/bayes_motel
https://github.com/mperham/bayes_motel
test/helper.rb
Ruby
mit
193
master
243
require 'rubygems' require 'shoulda' require 'simplecov' require 'test/unit' require 'zlib' $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) SimpleCov.start require 'bayes_motel'
github
mperham/bayes_motel
https://github.com/mperham/bayes_motel
test/test_persistence.rb
Ruby
mit
193
master
620
require 'helper' require 'fileutils' class TestPersistence < Test::Unit::TestCase should "persist" do c1 = BayesMotel::Corpus.new('test1') c1.train({ :something => 'foo', :kids => { :bar => 'whiz', :id => 123 } }, :ham) c1.train({ :something => 'foo', :kids => { :bar => 'gee', :id => 145 } }, :spam) ...
github
mperham/bayes_motel
https://github.com/mperham/bayes_motel
test/test_training.rb
Ruby
mit
193
master
1,743
require 'helper' class TestTraining < Test::Unit::TestCase should "handle basic training" do c = BayesMotel::Corpus.new('test') c.train({ :something => 'foo' }, :ham) c.train({ :something => 'foo' }, :spam) results = c.score({ :something => 'foo' }) assert results assert_equal 2, resu...
github
mperham/bayes_motel
https://github.com/mperham/bayes_motel
test/test_bayes_motel.rb
Ruby
mit
193
master
828
require 'helper' class TestBayesMotel < Test::Unit::TestCase should "allow basic training" do c = BayesMotel::Corpus.new('email') tweets.each do |tweet| c.train(tweet, :ham) end c.cleanup assert_equal tweets.size, c.total_count end should "allow big training" do c = BayesMotel...
github
mperham/bayes_motel
https://github.com/mperham/bayes_motel
lib/bayes_motel/persistence.rb
Ruby
mit
193
master
353
module BayesMotel module Persistence # TODO Make this a little more Ruby idiomatic and pluggable # for filesystems, databases, etc. def self.write(corpus) File.open("#{corpus.name}", 'w') do |file| Marshal.dump(corpus, file) end end def self.read(name) Marshal.load(File.r...
github
mperham/bayes_motel
https://github.com/mperham/bayes_motel
lib/bayes_motel/corpus.rb
Ruby
mit
193
master
2,142
module BayesMotel class Corpus attr_reader :name attr_reader :total_count attr_reader :data def initialize(name) @name = name @total_count = 0 @data = {} end def train(doc, category) @total_count += 1 _training(doc, category) end def score(doc) ...
github
yabeda-rb/yabeda-rails
https://github.com/yabeda-rb/yabeda-rails
yabeda-rails.gemspec
Ruby
mit
192
master
1,379
# frozen_string_literal: true lib = File.expand_path("lib", __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "yabeda/rails/version" Gem::Specification.new do |spec| spec.name = "yabeda-rails" spec.version = Yabeda::Rails::VERSION spec.authors = ["Andrey Novikov"] s...
github
yabeda-rb/yabeda-rails
https://github.com/yabeda-rb/yabeda-rails
Gemfile
Ruby
mit
192
master
741
# frozen_string_literal: true source "https://rubygems.org" git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } # Specify your gem's dependencies in yabeda-rails.gemspec gemspec rails_version = ENV.fetch("RAILS_VERSION", "~> 8.0") case rails_version when "HEAD" git "https://github.com/rails/rail...
github
yabeda-rb/yabeda-rails
https://github.com/yabeda-rb/yabeda-rails
lib/yabeda/rails.rb
Ruby
mit
192
master
3,217
# frozen_string_literal: true require "yabeda" require "active_support" require "rails/railtie" require "yabeda/rails/railtie" require "yabeda/rails/config" require "yabeda/rails/event" module Yabeda # Minimal set of Rails-specific metrics for using with Yabeda module Rails LONG_RUNNING_REQUEST_BUCKETS = [ ...
github
yabeda-rb/yabeda-rails
https://github.com/yabeda-rb/yabeda-rails
lib/yabeda/rails/config.rb
Ruby
mit
192
master
341
# frozen_string_literal: true require "anyway" module Yabeda module Rails # yabeda-rails configuration class Config < ::Anyway::Config config_name :yabeda_rails attr_config :apdex_target attr_config :buckets attr_config controller_name_case: :snake attr_config ignore_actions: ...
github
yabeda-rb/yabeda-rails
https://github.com/yabeda-rb/yabeda-rails
lib/yabeda/rails/railtie.rb
Ruby
mit
192
master
775
# frozen_string_literal: true # Explicitly require yabeda's railtie in case if its require was skipped there. # See https://github.com/yabeda-rb/yabeda/issues/15 require "yabeda/railtie" module Yabeda module Rails class Railtie < ::Rails::Railtie # :nodoc: def rails_server? ::Rails.const_defined?(...
github
yabeda-rb/yabeda-rails
https://github.com/yabeda-rb/yabeda-rails
lib/yabeda/rails/event.rb
Ruby
mit
192
master
1,552
# frozen_string_literal: true module Yabeda module Rails # ActiveSupport Event with added logic for Yabeda tags formatting class Event < ActiveSupport::Notifications::Event def labels @labels ||= begin labels = { controller: controller, action: action, ...
github
yabeda-rb/yabeda-rails
https://github.com/yabeda-rb/yabeda-rails
spec/spec_helper.rb
Ruby
mit
192
master
657
# frozen_string_literal: true ENV["RAILS_ENV"] = "test" require "bundler/setup" require "logger" require "debug" require "yabeda/rails" require "yabeda/rspec" require_relative "support/rails_app" require "rspec/rails" RSpec.configure do |config| # Enable flags like --only-failures and --next-failure config.exa...
github
yabeda-rb/yabeda-rails
https://github.com/yabeda-rb/yabeda-rails
spec/support/rails_app.rb
Ruby
mit
192
master
898
# frozen_string_literal: true require "rails" require "action_controller/railtie" require "active_support/railtie" class TestApplication < Rails::Application config.logger = Logger.new($stdout) config.log_level = :fatal config.consider_all_requests_local = true config.eager_load = true routes.append do ...
github
yabeda-rb/yabeda-rails
https://github.com/yabeda-rb/yabeda-rails
spec/yabeda/rails_spec.rb
Ruby
mit
192
master
3,500
# frozen_string_literal: true require "action_controller/test_case" RSpec.describe Yabeda::Rails, type: :integration do include ActionDispatch::Integration::Runner include ActionDispatch::IntegrationTest::Behavior def app TestApplication end it "increments counters for every request" do expect { g...
github
rubymonolith/fixturebot
https://github.com/rubymonolith/fixturebot
fixturebot-rails.gemspec
Ruby
mit
192
main
1,815
# frozen_string_literal: true require_relative "lib/fixturebot/version" Gem::Specification.new do |spec| spec.name = "fixturebot-rails" spec.version = FixtureBot::VERSION spec.authors = ["Brad Gessler"] spec.email = ["bradgessler@gmail.com"] spec.summary = "Define Rails fixtures with a Ruby DSL instead of ...
github
rubymonolith/fixturebot
https://github.com/rubymonolith/fixturebot
Gemfile
Ruby
mit
192
main
236
# frozen_string_literal: true source "https://rubygems.org" # Specify your gem's dependencies in fixturebot.gemspec gemspec gem "irb" gem "rake", "~> 13.0" gem "rspec", "~> 3.0" gem "rails", ">= 7.0" gem "simplecov", require: false
github
rubymonolith/fixturebot
https://github.com/rubymonolith/fixturebot
lib/fixturebot.rb
Ruby
mit
192
main
1,650
# frozen_string_literal: true require_relative "fixturebot/version" require_relative "fixturebot/schema" require_relative "fixturebot/key" require_relative "fixturebot/default" require_relative "fixturebot/row" require_relative "fixturebot/definition" require_relative "fixturebot/key_registry" require_relative "fixtur...
github
rubymonolith/fixturebot
https://github.com/rubymonolith/fixturebot
lib/generators/fixturebot/install_generator.rb
Ruby
mit
192
main
891
# frozen_string_literal: true require "rails/generators" module Fixturebot class InstallGenerator < ::Rails::Generators::Base source_root File.expand_path("templates", __dir__) desc "Set up FixtureBot in your Rails application" def create_fixtures_file if rspec? template "fixtures.rb.tt"...
github
rubymonolith/fixturebot
https://github.com/rubymonolith/fixturebot
lib/fixturebot/default.rb
Ruby
mit
192
main
1,173
# frozen_string_literal: true module FixtureBot module Default class Definition def initialize(table, defaults) @defaults = defaults define_column_methods(table) end private def define_column_methods(table) table.columns.each do |col| define_singleton_m...