Module: EasyRoles
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/easy_roles.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #method_missing_with_roles(method_id, *args, &block) ⇒ Object
- #respond_to_with_roles?(method_id, include_private = false) ⇒ Boolean
Class Method Details
.included(base) ⇒ Object
2 3 4 5 6 |
# File 'lib/easy_roles.rb', line 2 def self.included(base) base.extend ClassMethods base.send :alias_method_chain, :method_missing, :roles base.send :alias_method_chain, :respond_to?, :roles end |
Instance Method Details
#method_missing_with_roles(method_id, *args, &block) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/easy_roles.rb', line 106 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]}" 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
118 119 120 121 122 123 124 125 |
# File 'lib/easy_roles.rb', line 118 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, include_private = false) end end |