Module: RoleMaking::Resourcing::ClassMethods
- Defined in:
- lib/role_making/resourcing.rb
Instance Attribute Summary collapse
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
- #add_resource(group, verb, object, hash, behavior) ⇒ Object
- #each_group(&block) ⇒ Object
- #each_resource(&block) ⇒ Object
- #each_resources_by(group, &block) ⇒ Object
- #find_by_name(name) ⇒ Object
- #group(name, &block) ⇒ Object
- #resource(verb_or_verbs, object, hash = nil, &block) ⇒ Object
Instance Attribute Details
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
13 14 15 |
# File 'lib/role_making/resourcing.rb', line 13 def groups @groups end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
13 14 15 |
# File 'lib/role_making/resourcing.rb', line 13 def resources @resources end |
Instance Method Details
#add_resource(group, verb, object, hash, behavior) ⇒ Object
30 31 32 33 34 |
# File 'lib/role_making/resourcing.rb', line 30 def add_resource(group,verb,object,hash,behavior) name = "#{verb}_#{object.to_s.underscore}" resource = Res.new(name,group,verb,hash,object,behavior) @resources << resource end |
#each_group(&block) ⇒ Object
36 37 38 39 40 |
# File 'lib/role_making/resourcing.rb', line 36 def each_group(&block) @groups.each do |group| block.call(group) end end |
#each_resource(&block) ⇒ Object
42 43 44 |
# File 'lib/role_making/resourcing.rb', line 42 def each_resource(&block) @resources.group_by(&:group).each(&block) end |
#each_resources_by(group, &block) ⇒ Object
46 47 48 |
# File 'lib/role_making/resourcing.rb', line 46 def each_resources_by(group,&block) @resources.find_all{|r| r.group == group}.each(&block) end |
#find_by_name(name) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/role_making/resourcing.rb', line 50 def find_by_name(name) resource = @resources.detect { |e| e.name == name.to_s } raise "not found resources by name: #{name}" unless resource resource end |
#group(name, &block) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/role_making/resourcing.rb', line 14 def group(name,&block) @groups << name @groups.uniq! @current_group = name block.call end |
#resource(verb_or_verbs, object, hash = nil, &block) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/role_making/resourcing.rb', line 21 def resource(verb_or_verbs,object,hash=nil,&block) raise "Need define group first" if @current_group.nil? group = @current_group behavior = block Array.wrap(verb_or_verbs).each do |verb| add_resource(group,verb,object,hash,behavior) end end |