Module: DarDaDa::ActiveRecordExtension
- Defined in:
- lib/dar_da_da/active_record_extension.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary
collapse
Class Method Details
.decorate(base, config) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/dar_da_da/active_record_extension.rb', line 10
def self.decorate(base, config)
base.send :include, DarDaDa::ActiveRecordExtension::InstanceMethods
config.each do |name, role|
base.class_eval("
def #{name}?
role_symbol == :#{name}
end
def self.#{name.to_s.pluralize}
where(\"#{base.table_name}.#{config.options[:role_attribute]} = '#{name}'\")
end
")
end
config.all_rights.each do |right|
base.class_eval("
def allowed_to_#{right}?
allowed_to?(:#{right})
end
")
end
end
|
.included(base) ⇒ Object
5
6
7
8
|
# File 'lib/dar_da_da/active_record_extension.rb', line 5
def self.included(base)
base.class_attribute(:dar_dar_da, :instance_reader => false, :instance_writer => false)
base.extend(ClassMethods)
end
|