Class: IdPlease::AssignmentMap
- Inherits:
-
Object
- Object
- IdPlease::AssignmentMap
- Defined in:
- lib/id_please/assignment_map.rb
Instance Attribute Summary collapse
-
#calculated ⇒ Object
readonly
Returns the value of attribute calculated.
-
#subjects ⇒ Object
readonly
Returns the value of attribute subjects.
Instance Method Summary collapse
- #add_all_assignments(subjects) ⇒ Object
-
#initialize(*args) ⇒ AssignmentMap
constructor
A new instance of AssignmentMap.
- #map ⇒ Object
- #role_hash ⇒ Object
- #role_with_assignments ⇒ Object
- #roles ⇒ Object
- #subject_hash ⇒ Object
Constructor Details
#initialize(*args) ⇒ AssignmentMap
Returns a new instance of AssignmentMap.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/id_please/assignment_map.rb', line 26 def initialize(*args) = args. = {:direction => :down, :nested => true}.merge() @subjects = [:subjects] # || raise("You must provide a subject") @subjects = [@subjects] unless @subjects.kind_of?(Array) @direction = [:direction] @assign_class = [:assignment_class] # || raise("You must provide the assignment class through :assignment_class") @nested = [:nested] @member_role = [:member_role] || :member @assignments = [] @calculated = false add_all_assignments(@subjects) end |
Instance Attribute Details
#calculated ⇒ Object (readonly)
Returns the value of attribute calculated.
24 25 26 |
# File 'lib/id_please/assignment_map.rb', line 24 def calculated @calculated end |
#subjects ⇒ Object (readonly)
Returns the value of attribute subjects.
24 25 26 |
# File 'lib/id_please/assignment_map.rb', line 24 def subjects @subjects end |
Instance Method Details
#add_all_assignments(subjects) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/id_please/assignment_map.rb', line 40 def add_all_assignments(subjects) @calculated = false if @direction == :down assignments = @assign_class.(*subjects).all(:include => [:subject, {:role => :authorizable}]) @assignments += assignments if @nested subjects_to_search = assignments.collect(&:subject).select { |s| s._auth_is_group } add_all_assignments(subjects_to_search) unless subjects_to_search.empty? end end end |
#map ⇒ Object
103 104 105 |
# File 'lib/id_please/assignment_map.rb', line 103 def map return self end |
#role_hash ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/id_please/assignment_map.rb', line 78 def role_hash calculate! unless @calculated result = {} @assignment_links.each do |a| result[a.role] ||= [] result[a.role] << a.subject end result.each_pair { |k,v| result[k] = v.uniq } return result end |
#role_with_assignments ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/id_please/assignment_map.rb', line 91 def role_with_assignments calculate! unless @calculated result = Hash.new { |h,k| h[k] = Hash.new() } @assignment_links.each do |a| result[a.role][a.subject] ||= [] result[a.role][a.subject] << a.target end result.each_key { |name| result[name].each_pair { |subject,v| result[name][subject] = v.uniq }} return result end |
#roles ⇒ Object
73 74 75 76 |
# File 'lib/id_please/assignment_map.rb', line 73 def roles calculate! unless @calculated @roles = @assignment_links.collect(&:role).uniq end |
#subject_hash ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/id_please/assignment_map.rb', line 61 def subject_hash calculate! unless @calculated result = {} @assignment_links.each do |a| result[a.subject] ||= [] result[a.subject] << a.role end result.each_pair { |k,v| result[k] = v.uniq } return result end |