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

- (Approach) initialize(engine, users, steps)

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

- (Object) engine (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

- (Object) steps (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

- (Object) users (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

- (Object) <=>(other)



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

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

- (Object) changes



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

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

- (Object) check(approach_checker)



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

- (Object) clone_for_step(*step_params)



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

- (Object) inspect



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

- (Object) sort_value



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

- (Object) state_hash



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

- (Boolean) subset?(other_approach)

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