Module: SlowYourRoles
- Extended by:
- ActiveSupport::Concern
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/slow_your_roles.rb,
lib/methods/bitmask.rb,
lib/methods/serialize.rb,
lib/generators/install_generator_helpers.rb,
lib/generators/slow_your_roles/slow_your_roles_generator.rb
Overview
Include this module in your ActiveRecord model for role support.
Defined Under Namespace
Modules: ClassMethods, Generators, InstallGeneratorHelpers Classes: Bitmask, Serialize
Constant Summary collapse
- ALLOWED_METHODS =
%i[serialize bitmask].freeze
Instance Method Summary collapse
- #method_missing_with_roles(method_id, *args, &block) ⇒ Object
- #respond_to_with_roles?(method_id, _include_private = false) ⇒ Boolean
Instance Method Details
#method_missing_with_roles(method_id, *args, &block) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/slow_your_roles.rb', line 36 def method_missing_with_roles(method_id, *args, &block) match = method_id.to_s.match(/^is_(\w+)[?]$/) if match && respond_to?('has_role?') self.class.send(:define_method, "is_#{match[1]}?") do send :has_role?, (match[1]).to_s end send "is_#{match[1]}?" else method_missing_without_roles(method_id, *args, &block) end end |
#respond_to_with_roles?(method_id, _include_private = false) ⇒ Boolean
48 49 50 51 52 53 54 55 |
# File 'lib/slow_your_roles.rb', line 48 def respond_to_with_roles?(method_id, _include_private = false) match = method_id.to_s.match(/^is_(\w+)[?]$/) if match && respond_to?('has_role?') true else respond_to_without_roles?(method_id, false) end end |