Class: Authorization::DevelopmentSupport::ChangeAnalyzer::Approach

Inherits:
Object
  • Object
show all
Defined in:
lib/declarative_authorization/development_support/change_analyzer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine, users, steps) ⇒ Approach

Returns a new instance of Approach.



97
98
99
# File 'lib/declarative_authorization/development_support/change_analyzer.rb', line 97

def initialize (engine, users, steps)
  @engine, @users, @steps = engine, users, steps
end

Instance Attribute Details

#engineObject (readonly)

Returns the value of attribute engine.



96
97
98
# File 'lib/declarative_authorization/development_support/change_analyzer.rb', line 96

def engine
  @engine
end

#stepsObject (readonly)

Returns the value of attribute steps.



96
97
98
# File 'lib/declarative_authorization/development_support/change_analyzer.rb', line 96

def steps
  @steps
end

#usersObject (readonly)

Returns the value of attribute users.



96
97
98
# File 'lib/declarative_authorization/development_support/change_analyzer.rb', line 96

def users
  @users
end

Instance Method Details

#<=>(other) ⇒ Object



141
142
143
# File 'lib/declarative_authorization/development_support/change_analyzer.rb', line 141

def <=> (other)
  sort_value <=> other.sort_value
end

#changesObject



112
113
114
# File 'lib/declarative_authorization/development_support/change_analyzer.rb', line 112

def changes
  @steps.select {|step| step.length > 1}
end

#check(approach_checker) ⇒ Object



101
102
103
104
105
106
# File 'lib/declarative_authorization/development_support/change_analyzer.rb', line 101

def check (approach_checker)
  res = approach_checker.check(@engine, @users)
  @failed_test_count = approach_checker.failed_test_count
  #puts "CHECKING #{inspect} (#{res}, #{sort_value})"
  res
end

#clone_for_step(*step_params) ⇒ Object



108
109
110
# File 'lib/declarative_authorization/development_support/change_analyzer.rb', line 108

def clone_for_step (*step_params)
  self.class.new(@engine.clone, @users.clone, @steps + [Step.new(step_params)])
end

#inspectObject



135
136
137
138
139
# File 'lib/declarative_authorization/development_support/change_analyzer.rb', line 135

def inspect
  "Approach (#{state_hash}): Steps: #{changes.map(&:inspect) * ', '}"# +
     # "\n  Roles: #{AnalyzerEngine.roles(@engine).map(&:to_sym).inspect}; " +
     # "\n  Users: #{@users.map(&:role_symbols).inspect}"
end

#sort_valueObject



131
132
133
# File 'lib/declarative_authorization/development_support/change_analyzer.rb', line 131

def sort_value
  (changes.length + 1) + steps.length / 2 + (@failed_test_count.to_i + 1)
end

#state_hashObject



121
122
123
124
125
126
127
128
129
# File 'lib/declarative_authorization/development_support/change_analyzer.rb', line 121

def 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

Returns:

  • (Boolean)


116
117
118
119
# File 'lib/declarative_authorization/development_support/change_analyzer.rb', line 116

def subset? (other_approach)
  other_approach.changes.length >= changes.length &&
      changes.all? {|step| other_approach.changes.any? {|step_2| step_2.eql?(step)} }
end