Class: Authorization::DevelopmentSupport::ChangeSupporter::Approach
- Inherits:
-
Object
- Object
- Authorization::DevelopmentSupport::ChangeSupporter::Approach
- Defined in:
- lib/declarative_authorization/development_support/change_supporter.rb
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
-
#failed_tests ⇒ Object
readonly
Returns the value of attribute failed_tests.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#users ⇒ Object
readonly
Returns the value of attribute users.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #abstract_actions ⇒ Object
- #apply(action) ⇒ Object
- #changes ⇒ Object
- #check(approach_checker) ⇒ Object
-
#initialize(engine, users, steps) ⇒ Approach
constructor
A new instance of Approach.
- #initialize_copy(other) ⇒ Object
- #inspect ⇒ Object
- #reverse_of_previous?(specific_action) ⇒ Boolean
- #sort_value ⇒ Object
- #state_hash ⇒ Object
- #subset?(other_approach) ⇒ Boolean
Constructor Details
#initialize(engine, users, steps) ⇒ Approach
Returns a new instance of Approach.
111 112 113 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 111 def initialize (engine, users, steps) @engine, @users, @steps = engine, users, steps end |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
110 111 112 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 110 def engine @engine end |
#failed_tests ⇒ Object (readonly)
Returns the value of attribute failed_tests.
110 111 112 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 110 def failed_tests @failed_tests end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
110 111 112 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 110 def steps @steps end |
#users ⇒ Object (readonly)
Returns the value of attribute users.
110 111 112 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 110 def users @users end |
Instance Method Details
#<=>(other) ⇒ Object
183 184 185 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 183 def <=> (other) sort_value <=> other.sort_value end |
#abstract_actions ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 132 def abstract_actions if failed_tests.first.positive [ AssignPrivilegeToRoleAction, AssignRoleToUserAction, CreateAndAssignRoleToUserAction, AddPrivilegeAndAssignRoleToUserAction ] else [ RemovePrivilegeFromRoleAction, RemoveRoleFromUserAction ] end end |
#apply(action) ⇒ Object
152 153 154 155 156 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 152 def apply (action) ok = action.apply(self) @steps << action if ok ok end |
#changes ⇒ Object
128 129 130 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 128 def changes @steps end |
#check(approach_checker) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 115 def check (approach_checker) res = approach_checker.check(@engine, @users) @failed_tests = approach_checker.failed_tests #puts "CHECKING #{inspect} (#{res}, #{sort_value})" res end |
#initialize_copy(other) ⇒ Object
122 123 124 125 126 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 122 def initialize_copy (other) @engine = @engine.clone @users = @users.clone @steps = @steps.clone end |
#inspect ⇒ Object
177 178 179 180 181 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 177 def inspect "Approach: Steps: #{changes.map(&:inspect) * ', '}"# + # "\n Roles: #{AnalyzerEngine.roles(@engine).map(&:to_sym).inspect}; " + # "\n Users: #{@users.map(&:role_symbols).inspect}" end |
#reverse_of_previous?(specific_action) ⇒ Boolean
148 149 150 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 148 def reverse_of_previous? (specific_action) changes.any? {|step| step.reverse?(specific_action)} end |
#sort_value ⇒ Object
173 174 175 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 173 def sort_value changes.sum(&:weight) + @failed_tests.length end |
#state_hash ⇒ Object
163 164 165 166 167 168 169 170 171 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 163 def state_hash @state_hash ||= @engine.auth_rules.inject(0) do |memo, rule| memo + rule.privileges.hash + rule.contexts.hash + rule.attributes.hash + rule.role.hash end + @users.inject(0) {|memo, user| memo + user.role_symbols.hash } + @engine.privileges.hash + @engine.privilege_hierarchy.hash + @engine.roles.hash + @engine.role_hierarchy.hash end |
#subset?(other_approach) ⇒ Boolean
158 159 160 161 |
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 158 def subset? (other_approach) other_approach.changes.length >= changes.length && changes.all? {|step| other_approach.changes.any? {|step_2| step_2.eql?(step)} } end |