repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/html_parser/textarea_scope.rb
lib/volt/server/html_parser/textarea_scope.rb
module Volt class TextareaScope < ViewScope def initialize(handler, path, attributes) super(handler, path) @attributes = attributes end def add_binding(content) @html << "{{#{content}}}" end def close_scope(pop = true) # Remove from the scope @handler.scope.pop ...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/html_parser/if_view_scope.rb
lib/volt/server/html_parser/if_view_scope.rb
module Volt class IfViewScope < ViewScope def initialize(handler, path, content) super(handler, path) @original_path = @path @last_content = content @branches = [] # We haven't added the if yet @if_binding_number = @handler.last.bi...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/html_parser/component_view_scope.rb
lib/volt/server/html_parser/component_view_scope.rb
module Volt class ComponentViewScope < ViewScope # The path passed in is the path used to lookup view's. The path from the tag is passed in # as tag_name def initialize(handler, path, tag_name, attributes, unary) super(handler, path) @binding_in_path = path component_name = tag_name[1...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/html_parser/attribute_scope.rb
lib/volt/server/html_parser/attribute_scope.rb
module Volt # Included into ViewScope to provide processing for attributes module AttributeScope module ClassMethods def methodize_string(str) # Convert the string passed in to the binding so it returns a ruby Method # instance parts = str.split('.') end_call = parts.last....
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/html_parser/view_parser.rb
lib/volt/server/html_parser/view_parser.rb
require 'volt/server/html_parser/sandlebars_parser' require 'volt/server/html_parser/view_scope' require 'volt/server/html_parser/if_view_scope' require 'volt/server/html_parser/component_view_scope' require 'volt/server/html_parser/view_handler' require 'volt/server/html_parser/each_scope' require 'volt/server/html_pa...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/html_parser/view_scope.rb
lib/volt/server/html_parser/view_scope.rb
require 'volt/server/html_parser/attribute_scope' module Volt class ViewScope include AttributeScope attr_reader :html, :bindings attr_accessor :path, :binding_number def initialize(handler, path) @handler = handler @path = path @html = '' @bindings = {} ...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/html_parser/view_handler.rb
lib/volt/server/html_parser/view_handler.rb
module Volt class ViewHandler attr_reader :templates, :scope, :links def html last.html end def last @scope.last end # @param [String] - the path to the template file being processed # @param - the sprockets context, used for asset_url bindings # @param [Boolean] - if th...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/template_handlers/sprockets_component_handler.rb
lib/volt/server/template_handlers/sprockets_component_handler.rb
require 'volt/server/template_handlers/view_processor' require 'sprockets' # This file Monkeypatches sprockets to provide custom file loading (from volt # instead disk) for component root files. These files then require in all parts # or include generated ruby for templates, routes, and tasks. module Volt class Sta...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/template_handlers/view_processor.rb
lib/volt/server/template_handlers/view_processor.rb
require 'volt/server/component_templates' require 'opal/sprockets/processor' require 'sprockets' require 'tilt' require 'opal/sprockets/processor' require 'sprockets/uri_utils' module Volt class ViewProcessor < ::Opal::TiltTemplate def initialize(client) @client = client end def app_reference ...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/template_handlers/preprocessors.rb
lib/volt/server/template_handlers/preprocessors.rb
module Volt class ComponentTemplates module Preprocessors #:nodoc: # Setup default handler on extend def self.extended(base) base.register_template_handler :html, BasicHandler.new base.register_template_handler :email, BasicHandler.new end @@template_handlers = {} d...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/websocket/rack_server_adaptor.rb
lib/volt/server/websocket/rack_server_adaptor.rb
begin require 'puma' RUNNING_SERVER = 'puma' rescue LoadError => e begin require 'thin' RUNNING_SERVER = 'thin' rescue LoadError => e Volt.logger.error('Unable to find a compatible rack server, please make sure your Gemfile includes one of the following: thin or puma') end end module Volt class...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/server/websocket/websocket_handler.rb
lib/volt/server/websocket/websocket_handler.rb
require 'faye/websocket' require 'volt/server/socket_connection_handler' # Load websocket options once at boot # The ENV['DYNO'] option lets it kick in automatically if we're on heroku. WEBSOCKET_OPTIONS = if !ENV['NO_WEBSOCKET_PING'] && (ENV['WEBSOCKET_PING_TIME'] || ENV['DYNO']) {ping: (ENV['WEBSOCKET_PING_TIME'...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/router/routes.rb
lib/volt/router/routes.rb
require 'volt' module Volt # The Routes class takes a set of routes and sets up methods to go from # a url to params, and params to url. # routes do # client "/about", _view: 'about' # client "/blog/{{ id }}/edit", view: 'blog/edit', action: 'edit' # client "/blog/{{ id }}", view: 'blog/show', action...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/cli/bundle.rb
lib/volt/cli/bundle.rb
module Volt module Bundle # Run bundle from inside of cli, borrowed from rails: # https://github.com/rails/rails/blob/21f7bcbaa7709ed072bb2e1273d25c09eeaa26d9/railties/lib/rails/generators/app_base.rb def bundle_command(command) say_status :run, "bundle #{command}" # We are going to shell out...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/cli/generate.rb
lib/volt/cli/generate.rb
class Generate < Thor include Generators end
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/cli/new_gem.rb
lib/volt/cli/new_gem.rb
require 'net/http' require 'uri' require 'fileutils' # Creates a new "volt" gem, which can be used to easily repackage # components. class NewGem def initialize(thor, name, options) @thor = thor @component_name = name.chomp('/') @name = 'volt-' + @component_name # remove trailing slash if present @sh...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/cli/generators.rb
lib/volt/cli/generators.rb
module Generators def self.included(base) base.class_eval do include Thor::Actions desc 'model NAME COMPONENT', 'Creates a model named NAME in the component named COMPONENT' method_option :name, type: :string, banner: 'The name of the model.' method_option :component, type: :string, defau...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/cli/console.rb
lib/volt/cli/console.rb
require 'pry' class Pry class REPL # To make the console more useful, we make it so we flush the event registry # after each line. This makes it so events are triggered after each line. # To accomplish this we monkey-patch pry. def repl loop do case val = read when :control_c ...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/cli/runner.rb
lib/volt/cli/runner.rb
require 'volt/boot' module Volt class CLI class Runner # Runs the ruby file at the path def self.run_file(path) app = Volt.boot(Dir.pwd) # Require in the file at path require './' + path # disconnect from the message bus and flush all messages app.message_bus...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/cli/destroy.rb
lib/volt/cli/destroy.rb
class Destroy < Thor include Generators def initialize(*) super self.behavior = :revoke end end
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/cli/base_index_renderer.rb
lib/volt/cli/base_index_renderer.rb
# Render the config/base/index.html when precompiling. Here we only render # one js and one css file. module Volt class BaseIndexRenderer def initialize(volt_app, manifest) @volt_app = volt_app @manifest = manifest end def html index_path = File.expand_path(File.join(Volt.root, 'confi...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/cli/asset_compile.rb
lib/volt/cli/asset_compile.rb
module Volt class CLI desc 'precompile', 'precompile all application assets' def precompile move_to_root compile end private def compile say "Starting Precompile...", :red require 'fileutils' ENV['SERVER'] = 'true' ENV['MAPS'] = 'false' ENV['NO_FORKING'...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/extra_core/logger.rb
lib/volt/extra_core/logger.rb
if RUBY_PLATFORM == 'opal' # The basic front-end logger, log to console class Logger def initialize(*args) # TODO: handle options end [:fatal, :info, :warn, :debug, :error].each do |method_name| define_method(method_name) do |text, &block| text = block.call if block `consol...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/extra_core/extra_core.rb
lib/volt/extra_core/extra_core.rb
require 'volt/extra_core/logger' require 'volt/extra_core/array' require 'volt/extra_core/object' require 'volt/extra_core/blank' require 'volt/extra_core/stringify_keys' require 'volt/extra_core/string' require 'volt/extra_core/hash' require 'volt/extra_core/class' if RUBY_PLATFORM == 'opal' # TODO: != does not work...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/extra_core/blank.rb
lib/volt/extra_core/blank.rb
class Object # An object is blank if it's false, empty, or a whitespace string. # For example, '', ' ', +nil+, [], and {} are all blank. # # This simplifies: # # if address.nil? || address.empty? # # ...to: # # if address.blank? def blank? respond_to?(:empty?) ? empty? : !self end #...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/extra_core/array.rb
lib/volt/extra_core/array.rb
class Array def sum inject(0, :+) end # For some reason .to_h doesn't show as defined in opal, but defined?(:to_h) # returns true. def to_h Hash[self] end # Converts an array to a sentence def to_sentence(options={}) conjunction = options.fetch(:conjunction, 'and') comma = optio...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/extra_core/inflector.rb
lib/volt/extra_core/inflector.rb
# Copied from rails ActiveSupport: https://github.com/rails/rails/blob/feaa6e2048fe86bcf07e967d6e47b865e42e055b/activesupport/lib/active_support/inflector/inflections.rb require 'volt/extra_core/inflector/inflections' require 'volt/extra_core/inflector/methods' require 'volt/extra_core/inflections'
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/extra_core/inflections.rb
lib/volt/extra_core/inflections.rb
require 'volt/extra_core/inflector/inflections' Volt::Inflector.inflections(:en) do |inflect| inflect.plural(/$/, 's') inflect.plural(/s$/i, 's') inflect.plural(/^(ax|test)is$/i, '\1es') inflect.plural(/(octop|vir)us$/i, '\1i') inflect.plural(/(octop|vir)i$/i, '\1i') inflect.plural(/(alias|status)$/i, '\1e...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/extra_core/class.rb
lib/volt/extra_core/class.rb
class Class # Provides a way to make class attributes that inherit. Pass # in symbols for attribute names def class_attribute(*attrs) attrs.each do |name| define_singleton_method(name) { nil } ivar = "@#{name}" define_singleton_method("#{name}=") do |val| singleton_class.class_eva...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/extra_core/string.rb
lib/volt/extra_core/string.rb
require 'volt/extra_core/inflector' class String # TODO: replace with better implementations # NOTE: strings are currently immutable in Opal, so no ! methods # Turns a string into the camel case version. If it is already camel case, it should # return the same string. def camelize(first_letter = :upper) ...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/extra_core/object.rb
lib/volt/extra_core/object.rb
require 'volt/utils/ejson' class Object # Setup a default pretty_inspect # alias_method :pretty_inspect, :inspect def instance_values Hash[instance_variables.map { |name| [name[1..-1], instance_variable_get(name)] }] end def html_inspect inspect.gsub('<', '&lt;').gsub('>', '&gt;') end # TODO: ...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/extra_core/stringify_keys.rb
lib/volt/extra_core/stringify_keys.rb
class Object def stringify_keys each_with_object({}) do |(key, value), hash| hash[key.to_s] = value end end def symbolize_keys each_with_object({}) do |(key, value), hash| hash[key.to_sym] = value end end end
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/extra_core/hash.rb
lib/volt/extra_core/hash.rb
class Hash # Returns a hash excluding the keys passed in. def without(*keys) reject do |key, value| keys.include?(key) end end end
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/extra_core/symbol.rb
lib/volt/extra_core/symbol.rb
class Symbol def camelize to_s.camelize.to_sym end def underscore to_s.underscore.to_sym end def pluralize to_s.pluralize.to_sym end def singularize to_s.singularize.to_sym end def plural? to_s.plural? end def singular? to_s.singular? end end
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/extra_core/inflector/methods.rb
lib/volt/extra_core/inflector/methods.rb
# encoding: utf-8 # The Inflector transforms words from singular to plural, class names to table # names, modularized class names to ones without, and class names to foreign # keys. The default inflections for pluralization, singularization, and # uncountable words are kept in inflections.rb. module Volt module Infl...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
voltrb/volt
https://github.com/voltrb/volt/blob/f942b92385adbc894ee4a37903ee6a9c1a65e9a4/lib/volt/extra_core/inflector/inflections.rb
lib/volt/extra_core/inflector/inflections.rb
module Volt module Inflector # A singleton instance of this class is yielded by Inflector.inflections, # which can then be used to specify additional inflection rules. If passed # an optional locale, rules for other languages can be specified. The # default locale is <tt>:en</tt>. Only rules for Engli...
ruby
MIT
f942b92385adbc894ee4a37903ee6a9c1a65e9a4
2026-01-04T15:51:19.582691Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/generators_helper.rb
spec/generators_helper.rb
require 'rubygems' require "bundler/setup" require 'pry' require 'rolify' require 'rolify/matchers' require 'rails/all' require_relative 'support/stream_helpers' include StreamHelpers require 'coveralls' Coveralls.wear_merged! require 'common_helper' ENV['ADAPTER'] ||= 'active_record' if ENV['ADAPTER'] == 'active...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/common_helper.rb
spec/common_helper.rb
require 'test-unit' begin require 'pry' rescue LoadError end # `Test::Unit::AutoRunner.need_auto_run=` was introduced to the test-unit # gem in version 2.4.9. Previous to this version `Test::Unit.run=` was # used. The implementation of test-unit included with Ruby has neither # method. if defined? Test::Unit::AutoR...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/spec_helper.rb
spec/spec_helper.rb
require 'coveralls' Coveralls.wear_merged! require 'rubygems' require "bundler/setup" require 'rolify' require 'rolify/matchers' require 'rails' begin require 'its' rescue LoadError end require 'database_cleaner' ENV['ADAPTER'] ||= 'active_record' load File.dirname(__FILE__) + "/support/adapters/#{ENV['ADAPTER']}...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/support/data.rb
spec/support/data.rb
# Users [ User, Customer, Admin::Moderator, StrictUser ].each do |user| user.destroy_all user.create(:login => "admin") user.create(:login => "moderator") user.create(:login => "god") user.create(:login => "zombie") end # Roles [ Role, Privilege, Admin::Right ].each do |role| role.destroy_all end # Resou...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/support/stream_helpers.rb
spec/support/stream_helpers.rb
module StreamHelpers def capture(stream) stream = stream.to_s captured_stream = Tempfile.new(stream) stream_io = eval("$#{stream}") origin_stream = stream_io.dup stream_io.reopen(captured_stream) yield stream_io.rewind return captured_stream.read ensure captured_stream.close ...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/support/schema.rb
spec/support/schema.rb
ActiveRecord::Schema.define do self.verbose = false [ :roles, :privileges, :admin_rights ].each do |table| create_table(table) do |t| t.string :name t.references :resource, :polymorphic => true t.timestamps null: false end end [ :users, :human_resources, :customers, :admin_moderators, :st...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/support/adapters/active_record.rb
spec/support/adapters/active_record.rb
load File.dirname(__FILE__) + '/utils/active_record.rb' extend_rspec_with_activerecord_specific_matchers establish_connection ActiveRecord::Base.extend Rolify load File.dirname(__FILE__) + '/../schema.rb' # Standard user and role classes class User < ActiveRecord::Base rolify end class Role < ActiveRecord::Base ...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/support/adapters/mongoid.rb
spec/support/adapters/mongoid.rb
load File.dirname(__FILE__) + '/utils/mongoid.rb' load_mongoid_config begin Mongo::Logger.logger.level = ::Logger::FATAL rescue NameError end ::Mongoid::Document.module_eval do def self.included(base) base.extend Rolify end end Rolify.use_mongoid # Standard user and role classes class User include Mong...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/support/adapters/utils/active_record.rb
spec/support/adapters/utils/active_record.rb
require 'active_record' def establish_connection ActiveRecord::Base.establish_connection( :adapter => "sqlite3", :database => ":memory:" ) end def extend_rspec_with_activerecord_specific_matchers RSpec::Matchers::BuiltIn::OperatorMatcher.register(ActiveRecord::Relation, '=~', RSpec::Matchers::BuiltIn::C...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/support/adapters/utils/mongoid.rb
spec/support/adapters/utils/mongoid.rb
require 'mongoid' def mongoid_major_version Mongoid::VERSION.split('.').first.to_i end def mongoid_config "spec/support/adapters/mongoid_#{mongoid_major_version}.yml" end def load_mongoid_config Mongoid.load!(mongoid_config, :test) end
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/generators/rolify/rolify_mongoid_generator_spec.rb
spec/generators/rolify/rolify_mongoid_generator_spec.rb
require 'generators_helper' # Generators are not automatically loaded by Rails require 'generators/rolify/rolify_generator' describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'mongoid' do # Tell the generator where to put its output (what it thinks of as Rails.root) destination File.expand_pat...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/generators/rolify/rolify_activerecord_generator_spec.rb
spec/generators/rolify/rolify_activerecord_generator_spec.rb
require 'generators_helper' # Generators are not automatically loaded by Rails require 'generators/rolify/rolify_generator' describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_record' do # Tell the generator where to put its output (what it thinks of as Rails.root) destination File.expa...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/shared_contexts.rb
spec/rolify/shared_contexts.rb
shared_context "global role", :scope => :global do subject { admin } def admin user_class.first end before(:all) do load_roles create_other_roles end def load_roles role_class.destroy_all admin.roles = [] admin.add_role :admin admin.add_role :staff admin.add_role :ma...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/utils_spec.rb
spec/rolify/utils_spec.rb
require "spec_helper" describe Rolify::Utils do class Harness extend Rolify::Utils define_method(:new_method) { |*_args| true } deprecate :old_method, :new_method end let(:harness) { Harness.new } context '#deprecate' do it 'calls new method with same arguments' do expect(harness).to re...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/role_spec.rb
spec/rolify/role_spec.rb
require "spec_helper" describe Rolify do context 'cache' do let(:user) { User.first } before { user.grant(:zombie) } specify do expect(user).to have_role(:zombie) user.remove_role(:zombie) expect(user).to_not have_role(:zombie) end end end
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/namespace_spec.rb
spec/rolify/namespace_spec.rb
require "spec_helper" require "rolify/shared_examples/shared_examples_for_roles" require "rolify/shared_examples/shared_examples_for_dynamic" require "rolify/shared_examples/shared_examples_for_scopes" require "rolify/shared_examples/shared_examples_for_callbacks" describe "Rolify.namespace" do def user_class Ad...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/resourcifed_and_rolifed_spec.rb
spec/rolify/resourcifed_and_rolifed_spec.rb
require "spec_helper" describe "Resourcify and rolify on the same model" do before(:all) do reset_defaults Role.delete_all HumanResource.delete_all end let!(:user) do user = HumanResource.new login: 'Samer' user.save user end it "should add the role to the user" do expec...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/matchers_spec.rb
spec/rolify/matchers_spec.rb
require 'spec_helper' describe 'have_role', focus: true do let(:object) { Object.new } it 'delegates to has_role?' do object.should_receive(:has_role?).with(:read, 'Resource') { true } object.should have_role(:read, 'Resource') end it 'reports a nice failure message for should' do object.should_r...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/config_spec.rb
spec/rolify/config_spec.rb
require "spec_helper" if ENV['ADAPTER'] == 'active_record' class ARUser < ActiveRecord::Base extend Rolify end else class MUser include Mongoid::Document extend Rolify end end describe Rolify do before do Rolify.use_defaults end describe :dynamic_shortcuts do context "using default...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/custom_spec.rb
spec/rolify/custom_spec.rb
require "spec_helper" require "rolify/shared_examples/shared_examples_for_roles" require "rolify/shared_examples/shared_examples_for_dynamic" require "rolify/shared_examples/shared_examples_for_scopes" require "rolify/shared_examples/shared_examples_for_callbacks" describe "Using Rolify with custom User and Role class...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/resource_spec.rb
spec/rolify/resource_spec.rb
require "spec_helper" describe Rolify::Resource do before(:all) do reset_defaults silence_warnings { User.rolify } Forum.resourcify Group.resourcify Team.resourcify Organization.resourcify Role.destroy_all end # Users let(:admin) { User.first } let(:tourist) { User.last } let...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/shared_examples/shared_examples_for_has_any_role.rb
spec/rolify/shared_examples/shared_examples_for_has_any_role.rb
shared_examples_for "#has_any_role?_examples" do |param_name, param_method| context "using #{param_name} as parameter" do context "with a global role", :scope => :global do before do subject.add_role "staff".send(param_method) end it { subject.has_any_role?("staff".send(param_meth...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/shared_examples/shared_examples_for_roles.rb
spec/rolify/shared_examples/shared_examples_for_roles.rb
require "rolify/shared_contexts" require "rolify/shared_examples/shared_examples_for_add_role" require "rolify/shared_examples/shared_examples_for_has_role" require "rolify/shared_examples/shared_examples_for_only_has_role" require "rolify/shared_examples/shared_examples_for_has_all_roles" require "rolify/shared_exampl...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/shared_examples/shared_examples_for_finders.rb
spec/rolify/shared_examples/shared_examples_for_finders.rb
shared_examples_for :finders do |param_name, param_method| context "using #{param_name} as parameter" do describe ".with_role" do it { should respond_to(:with_role).with(1).argument } it { should respond_to(:with_role).with(2).arguments } context "when resource setting: strict is set to false" ...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/shared_examples/shared_examples_for_scopes.rb
spec/rolify/shared_examples/shared_examples_for_scopes.rb
require "rolify/shared_contexts" shared_examples_for "Role.scopes" do before do role_class.destroy_all end subject { user_class.first } describe ".global" do let!(:admin_role) { subject.add_role :admin } let!(:staff_role) { subject.add_role :staff } it { subject.roles.global.should...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/shared_examples/shared_examples_for_add_role.rb
spec/rolify/shared_examples/shared_examples_for_add_role.rb
shared_examples_for "#add_role_examples" do |param_name, param_method| context "using #{param_name} as parameter" do context "with a global role", :scope => :global do it "should add the role to the user" do expect { subject.add_role "root".send(param_method) }.to change { subject.roles.count }.by(1...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/shared_examples/shared_examples_for_only_has_role.rb
spec/rolify/shared_examples/shared_examples_for_only_has_role.rb
shared_examples_for "#only_has_role?_examples" do |param_name, param_method| context "using #{param_name} as parameter" do context "with a global role", :scope => :global do subject do user = User.create(:login => "global_user") user.add_role "global_role".send(param_method) user ...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/shared_examples/shared_examples_for_dynamic.rb
spec/rolify/shared_examples/shared_examples_for_dynamic.rb
shared_examples_for Rolify::Dynamic do before(:all) do Rolify.dynamic_shortcuts = true role_class.destroy_all rolify_options = { :role_cname => role_class.to_s } rolify_options[:role_join_table_name] = join_table if defined? join_table silence_warnings { user_class.rolify rolify_options } Foru...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/shared_examples/shared_examples_for_remove_role.rb
spec/rolify/shared_examples/shared_examples_for_remove_role.rb
shared_examples_for "#remove_role_examples" do |param_name, param_method| context "using #{param_name} as parameter" do context "removing a global role", :scope => :global do context "being a global role of the user" do it { expect { subject.remove_role("admin".send(param_method)) }.to change { subj...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/shared_examples/shared_examples_for_callbacks.rb
spec/rolify/shared_examples/shared_examples_for_callbacks.rb
shared_examples_for "Rolify.callbacks" do before(:all) do reset_defaults Rolify.dynamic_shortcuts = false role_class.destroy_all end after :each do @user.roles.destroy_all end describe "rolify association callbacks", :if => (Rolify.orm == "active_record") do describe "before_add" do ...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/shared_examples/shared_examples_for_has_all_roles.rb
spec/rolify/shared_examples/shared_examples_for_has_all_roles.rb
shared_examples_for "#has_all_roles?_examples" do |param_name, param_method| context "using #{param_name} as parameter" do context "with a global role", :scope => :global do context "on global roles only request" do it { subject.has_all_roles?("staff".send(param_method)).should be_truthy } ...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/spec/rolify/shared_examples/shared_examples_for_has_role.rb
spec/rolify/shared_examples/shared_examples_for_has_role.rb
shared_examples_for "#has_role?_examples" do |param_name, param_method| context "using #{param_name} as parameter" do context "with a global role", :scope => :global do it { subject.has_role?("admin".send(param_method)).should be_truthy } it { subject.has_cached_role?("admin".send(param_method)).shou...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify.rb
lib/rolify.rb
require 'rolify/adapters/base' require 'rolify/configure' require 'rolify/dynamic' require 'rolify/railtie' if defined?(Rails) require 'rolify/resource' require 'rolify/role' module Rolify extend Configure attr_accessor :role_cname, :adapter, :resource_adapter, :role_join_table_name, :role_table_name, :strict_rol...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/generators/mongoid/rolify_generator.rb
lib/generators/mongoid/rolify_generator.rb
require 'rails/generators/mongoid_generator' require 'active_support/core_ext' module Mongoid module Generators class RolifyGenerator < Rails::Generators::NamedBase source_root File.expand_path("../templates", __FILE__) argument :user_cname, :type => :string, :default => "User", :banner => "User" ...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/generators/rolify/user_generator.rb
lib/generators/rolify/user_generator.rb
require 'rails/generators/migration' require 'active_support/core_ext' module Rolify module Generators class UserGenerator < Rails::Generators::NamedBase argument :role_cname, :type => :string, :default => "Role" class_option :orm, :type => :string, :default => "active_record" desc "Inje...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/generators/rolify/rolify_generator.rb
lib/generators/rolify/rolify_generator.rb
module Rolify module Generators class RolifyGenerator < Rails::Generators::NamedBase Rails::Generators::ResourceHelpers source_root File.expand_path('../templates', __FILE__) argument :user_cname, :type => :string, :default => "User" namespace :rolify hook_for :orm, :required...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/generators/rolify/templates/initializer.rb
lib/generators/rolify/templates/initializer.rb
Rolify.configure<%= "(\"#{class_name.camelize.to_s}\")" if class_name != "Role" %> do |config| # By default ORM adapter is ActiveRecord. uncomment to use mongoid <%= "# " if options.orm == :active_record || !options.orm %>config.use_mongoid # Dynamic shortcuts for User class (user.is_admin? like methods). Defaul...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/generators/rolify/templates/role-active_record.rb
lib/generators/rolify/templates/role-active_record.rb
class <%= role_cname.camelize %> < ActiveRecord::Base <% if need_table_prefix?(role_cname) %> def self.table_name_prefix <%= table_prefix(role_cname) %>_ end <% end %> has_and_belongs_to_many :<%= user_cname.tableize %>, :join_table => :<%= "#{table_name(user_cname, true)}_#{table_name(role_cname, true)}" %> ...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/generators/rolify/templates/role-mongoid.rb
lib/generators/rolify/templates/role-mongoid.rb
class <%= role_cname.camelize %> include Mongoid::Document has_and_belongs_to_many :<%= user_cname.tableize %> belongs_to :resource, :polymorphic => true field :name, :type => String index({ :name => 1, :resource_type => 1, :resource_id => 1 }, { :unique => true}) scopify end
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/generators/active_record/rolify_generator.rb
lib/generators/active_record/rolify_generator.rb
require 'rails/generators/active_record' require 'active_support/core_ext' require 'erb' module ActiveRecord module Generators class RolifyGenerator < ActiveRecord::Generators::Base source_root File.expand_path("../templates", __FILE__) argument :user_cname, :type => :string, :default => "User", :ba...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/generators/active_record/templates/migration.rb
lib/generators/active_record/templates/migration.rb
class RolifyCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %> def change create_table(:<%= table_name %>) do |t| t.string :name t.references :resource, :polymorphic => true t.timestamps end create_table(:<%= join_table %>, :id => false) do |t| t.r...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/generators/active_record/templates/model.rb
lib/generators/active_record/templates/model.rb
has_and_belongs_to_many :<%= user_class.table_name %>, :join_table => :<%= join_table %> <% if Rails::VERSION::MAJOR < 5 %> belongs_to :resource, :polymorphic => true <% else %> belongs_to :resource, :polymorphic => true, :optional => true <% end %> validates :resou...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/resource.rb
lib/rolify/resource.rb
module Rolify module Resource def self.included(base) base.extend ClassMethods end module ClassMethods def find_roles(role_name = nil, user = nil) self.resource_adapter.find_roles(role_name, self, user) end def with_role(role_name, user = nil) if role_name.is_a? A...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/dynamic.rb
lib/rolify/dynamic.rb
require "rolify/configure" module Rolify module Dynamic def define_dynamic_method(role_name, resource) class_eval do define_method("is_#{role_name}?".to_sym) do has_role?("#{role_name}") end if !method_defined?("is_#{role_name}?".to_sym) && self.adapter.where_strict(self.role_cla...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/version.rb
lib/rolify/version.rb
module Rolify VERSION = "6.0.1" end
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/matchers.rb
lib/rolify/matchers.rb
require 'rspec/expectations' RSpec::Matchers.define :have_role do |*args| match do |resource| resource.has_role?(*args) end failure_message do |resource| "expected to have role #{args.map(&:inspect).join(" ")}" end failure_message_when_negated do |resource| "expected not to have role #{args.map...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/finders.rb
lib/rolify/finders.rb
module Rolify module Finders def with_role(role_name, resource = nil) strict = self.strict_rolify && resource && resource != :any self.adapter.scope( self, { :name => role_name, :resource => resource }, strict ) end def without_role(role_name, resource = nil) ...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/utils.rb
lib/rolify/utils.rb
module Rolify module Utils def deprecate(old_method, new_method) define_method(old_method) do |*args| warn "[DEPRECATION] #{caller.first}: `#{old_method}` is deprecated. Please use `#{new_method}` instead." send(new_method, *args) end end end end
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/railtie.rb
lib/rolify/railtie.rb
require 'rolify' require 'rails' module Rolify class Railtie < Rails::Railtie initializer 'rolify.initialize' do ActiveSupport.on_load(:active_record) do ActiveRecord::Base.send :extend, Rolify end config.before_initialize do ::Mongoid::Document.module_eval do d...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/configure.rb
lib/rolify/configure.rb
module Rolify module Configure @@dynamic_shortcuts = false @@orm = "active_record" @@remove_role_if_empty = true def configure(*role_cnames) return if !sanity_check(role_cnames) yield self if block_given? end def dynamic_shortcuts @@dynamic_shortcuts end def dynami...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/role.rb
lib/rolify/role.rb
require "rolify/finders" require "rolify/utils" module Rolify module Role extend Utils def self.included(base) base.extend Finders end def add_role(role_name, resource = nil) role = self.class.adapter.find_or_create_by(role_name.to_s, (r...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/adapters/base.rb
lib/rolify/adapters/base.rb
module Rolify module Adapter class Base def initialize(role_cname, user_cname) @role_cname = role_cname @user_cname = user_cname end def role_class @role_cname.constantize end def user_class @user_cname.constantize end def ro...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/adapters/mongoid/role_adapter.rb
lib/rolify/adapters/mongoid/role_adapter.rb
require 'rolify/adapters/base' module Rolify module Adapter class RoleAdapter < RoleAdapterBase def where(relation, *args) conditions = build_conditions(relation, args) relation.any_of(*conditions) end def where_strict(relation, args) wrap_conditions = relation.name != ...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/adapters/mongoid/scopes.rb
lib/rolify/adapters/mongoid/scopes.rb
module Rolify module Adapter module Scopes def global where(:resource_type => nil, :resource_id => nil) end def class_scoped(resource_type = nil) where_conditions = { :resource_type.ne => nil, :resource_id => nil } where_conditions = { :resource_type => resource_ty...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/adapters/mongoid/resource_adapter.rb
lib/rolify/adapters/mongoid/resource_adapter.rb
require 'rolify/adapters/base' module Rolify module Adapter class ResourceAdapter < ResourceAdapterBase def find_roles(role_name, relation, user) roles = user && (user != :any) ? user.roles : self.role_class roles = roles.where(:resource_type.in => self.relation_types_for(relation)) ...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/adapters/active_record/role_adapter.rb
lib/rolify/adapters/active_record/role_adapter.rb
require 'rolify/adapters/base' module Rolify module Adapter class RoleAdapter < RoleAdapterBase def where(relation, *args) conditions, values = build_conditions(relation, args) relation.where(conditions, *values) end def where_strict(relation, args) wrap_conditions = re...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/adapters/active_record/scopes.rb
lib/rolify/adapters/active_record/scopes.rb
module Rolify module Adapter module Scopes def global where(:resource_type => nil, :resource_id => nil) end def class_scoped(resource_type = nil) where_conditions = "resource_type IS NOT NULL AND resource_id IS NULL" where_conditions = [ "resource_type = ? AND reso...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
RolifyCommunity/rolify
https://github.com/RolifyCommunity/rolify/blob/55261dcc26ae0bbca90a657e9449c65095924465/lib/rolify/adapters/active_record/resource_adapter.rb
lib/rolify/adapters/active_record/resource_adapter.rb
require 'rolify/adapters/base' module Rolify module Adapter class ResourceAdapter < ResourceAdapterBase def find_roles(role_name, relation, user) roles = user && (user != :any) ? user.roles : self.role_class roles = roles.where('resource_type IN (?)', self.relation_types_for(relation)) ...
ruby
MIT
55261dcc26ae0bbca90a657e9449c65095924465
2026-01-04T15:51:28.375892Z
false
gazay/gon
https://github.com/gazay/gon/blob/a7a1da08cc4f211e7d2824fe0daf96816af14fca/spec/spec_helper.rb
spec/spec_helper.rb
# frozen_string_literal: true require 'active_support/all' require 'rails/railtie' require 'rails/version' # jbuilder <= 2.13.0 checks rails version require 'gon' require 'jbuilder' RSpec.configure do |_config| end
ruby
MIT
a7a1da08cc4f211e7d2824fe0daf96816af14fca
2026-01-04T15:51:43.063639Z
false
gazay/gon
https://github.com/gazay/gon/blob/a7a1da08cc4f211e7d2824fe0daf96816af14fca/spec/gon/templates_spec.rb
spec/gon/templates_spec.rb
# frozen_string_literal: true describe Gon do describe '.template_path' do context 'template is specified' do it 'add the extension if not included in the template name' do expect(Gon::EnvFinder.send(:template_path, { :template => 'spec/test_data/sample' }, 'jbuilder')).to eql('spec/test_data/sam...
ruby
MIT
a7a1da08cc4f211e7d2824fe0daf96816af14fca
2026-01-04T15:51:43.063639Z
false
gazay/gon
https://github.com/gazay/gon/blob/a7a1da08cc4f211e7d2824fe0daf96816af14fca/spec/gon/rabl_spec.rb
spec/gon/rabl_spec.rb
# frozen_string_literal: true describe Gon do describe '.rabl' do before :each do Gon.clear controller.instance_variable_set('@objects', objects) end let(:controller) { ActionController::Base.new } let(:objects) { [1, 2] } context 'render template with deprecation' do it 'sti...
ruby
MIT
a7a1da08cc4f211e7d2824fe0daf96816af14fca
2026-01-04T15:51:43.063639Z
false
gazay/gon
https://github.com/gazay/gon/blob/a7a1da08cc4f211e7d2824fe0daf96816af14fca/spec/gon/jbuilder_spec.rb
spec/gon/jbuilder_spec.rb
# frozen_string_literal: true describe Gon do describe '.jbuilder' do context 'render jbuilder templates' do before do Gon.clear controller.instance_variable_set('@objects', objects) allow(Rails).to receive_message_chain(:application, :routes, :url_helpers, :instance_methods) { []...
ruby
MIT
a7a1da08cc4f211e7d2824fe0daf96816af14fca
2026-01-04T15:51:43.063639Z
false
gazay/gon
https://github.com/gazay/gon/blob/a7a1da08cc4f211e7d2824fe0daf96816af14fca/spec/gon/watch_spec.rb
spec/gon/watch_spec.rb
# frozen_string_literal: true describe Gon::Watch do let(:controller) { ActionController::Base.new } let(:request) { ActionDispatch::Request.new({}) } before :each do controller.request = request controller.params = {} env = {} env['ORIGINAL_FULLPATH'] = '/foo' env['REQUEST_METHOD'] = 'GET'...
ruby
MIT
a7a1da08cc4f211e7d2824fe0daf96816af14fca
2026-01-04T15:51:43.063639Z
false
gazay/gon
https://github.com/gazay/gon/blob/a7a1da08cc4f211e7d2824fe0daf96816af14fca/spec/gon/thread_spec.rb
spec/gon/thread_spec.rb
# frozen_string_literal: true require 'action_dispatch/testing/test_request' class GonTestWorker include Gon::ControllerHelpers def request @request ||= ActionDispatch::TestRequest.create end def execute gon.clear gon.a ||= 1 gon.a += 1 end def value gon.a end end describe 'thread...
ruby
MIT
a7a1da08cc4f211e7d2824fe0daf96816af14fca
2026-01-04T15:51:43.063639Z
false