Class Authorization::DevelopmentSupport::ChangeAnalyzer::Approach
In: lib/declarative_authorization/development_support/change_analyzer.rb
Parent: Object

Methods

<=>   changes   check   clone_for_step   inspect   new   sort_value   state_hash   subset?  

Attributes

engine  [R] 
steps  [R] 
users  [R] 

Public Class methods

[Source]

    # File lib/declarative_authorization/development_support/change_analyzer.rb, line 97
97:         def initialize (engine, users, steps)
98:           @engine, @users, @steps = engine, users, steps
99:         end

Public Instance methods

[Source]

     # File lib/declarative_authorization/development_support/change_analyzer.rb, line 141
141:         def <=> (other)
142:           sort_value <=> other.sort_value
143:         end

[Source]

     # File lib/declarative_authorization/development_support/change_analyzer.rb, line 112
112:         def changes
113:           @steps.select {|step| step.length > 1}
114:         end

[Source]

     # File lib/declarative_authorization/development_support/change_analyzer.rb, line 101
101:         def check (approach_checker)
102:           res = approach_checker.check(@engine, @users)
103:           @failed_test_count = approach_checker.failed_test_count
104:           #puts "CHECKING #{inspect} (#{res}, #{sort_value})"
105:           res
106:         end

[Source]

     # File lib/declarative_authorization/development_support/change_analyzer.rb, line 108
108:         def clone_for_step (*step_params)
109:           self.class.new(@engine.clone, @users.clone, @steps + [Step.new(step_params)])
110:         end

[Source]

     # File lib/declarative_authorization/development_support/change_analyzer.rb, line 135
135:         def inspect
136:           "Approach (#{state_hash}): Steps: #{changes.map(&:inspect) * ', '}"# +
137:              # "\n  Roles: #{AnalyzerEngine.roles(@engine).map(&:to_sym).inspect}; " +
138:              # "\n  Users: #{@users.map(&:role_symbols).inspect}"
139:         end

[Source]

     # File lib/declarative_authorization/development_support/change_analyzer.rb, line 131
131:         def sort_value
132:           (changes.length + 1) + steps.length / 2 + (@failed_test_count.to_i + 1)
133:         end

[Source]

     # File lib/declarative_authorization/development_support/change_analyzer.rb, line 121
121:         def state_hash
122:           @engine.auth_rules.inject(0) do |memo, rule|
123:             memo + rule.privileges.hash + rule.contexts.hash +
124:                 rule.attributes.hash + rule.role.hash
125:           end +
126:               @users.inject(0) {|memo, user| memo + user.role_symbols.hash } +
127:               @engine.privileges.hash + @engine.privilege_hierarchy.hash +
128:               @engine.roles.hash + @engine.role_hierarchy.hash
129:         end

[Source]

     # File lib/declarative_authorization/development_support/change_analyzer.rb, line 116
116:         def subset? (other_approach)
117:           other_approach.changes.length >= changes.length &&
118:               changes.all? {|step| other_approach.changes.any? {|step_2| step_2.eql?(step)} }
119:         end

[Validate]