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, hashs, 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, hashs = nil, &block) ⇒ Object
Instance Attribute Details
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
22 23 24 |
# File 'lib/role_making/resourcing.rb', line 22 def groups @groups end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
22 23 24 |
# File 'lib/role_making/resourcing.rb', line 22 def resources @resources end |
Instance Method Details
#add_resource(group, verb, object, hashs, behavior) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/role_making/resourcing.rb', line 41 def add_resource(group,verb,object,hashs,behavior) name = "#{verb}@#{hashs.try(:delete,:res_name) || object.to_s.underscore}" action_scope = hashs.try(:delete,:action_scope) res_scope = hashs.try(:delete,:res_scope) hashs = nil if hashs.blank? resource = Res.new(name,group,verb,hashs,object,behavior,action_scope,res_scope) @resources << resource end |
#each_group(&block) ⇒ Object
50 51 52 53 54 |
# File 'lib/role_making/resourcing.rb', line 50 def each_group(&block) @groups.each do |group| block.call(group) end end |
#each_resource(&block) ⇒ Object
56 57 58 |
# File 'lib/role_making/resourcing.rb', line 56 def each_resource(&block) @resources.group_by(&:group).each(&block) end |
#each_resources_by(group, &block) ⇒ Object
60 61 62 |
# File 'lib/role_making/resourcing.rb', line 60 def each_resources_by(group,&block) @resources.find_all{|r| r.group == group}.each(&block) end |
#find_by_name(name) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/role_making/resourcing.rb', line 64 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
23 24 25 26 27 28 |
# File 'lib/role_making/resourcing.rb', line 23 def group(name,&block) @groups << name @groups.uniq! @current_group = name block.call end |
#resource(verb_or_verbs, object, hashs = nil, &block) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/role_making/resourcing.rb', line 32 def resource(verb_or_verbs,object,hashs=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,hashs.try(:dup),behavior) end end |