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

Class Method Details

.included(base) ⇒ Object



2
3
4
5
# File 'lib/easy_roles.rb', line 2

def self.included(base)
  base.extend ClassMethods
  base.send :alias_method_chain, :method_missing, :roles
end

Instance Method Details

#method_missing_with_roles(method_id, *args, &block) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/easy_roles.rb', line 105

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