Class: Authorization::DevelopmentSupport::AnalyzerEngine::Privilege

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

Constant Summary

@@privilege_objects =
{}

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Privilege) initialize(privilege, engine)

Returns a new instance of Privilege



162
163
164
165
# File 'lib/declarative_authorization/development_support/development_support.rb', line 162

def initialize (privilege, engine)
  @privilege = privilege
  @engine = engine
end

Class Method Details

+ (Object) for_sym(privilege_sym, engine)



197
198
199
# File 'lib/declarative_authorization/development_support/development_support.rb', line 197

def self.for_sym (privilege_sym, engine)
  @@privilege_objects[[privilege_sym, engine]] ||= new(privilege_sym, engine)
end

Instance Method Details

- (Object) ancestors(priv_symbol = nil)

Ancestor privileges are higher in the hierarchy. Doesn't take context into account.



169
170
171
172
173
174
175
# File 'lib/declarative_authorization/development_support/development_support.rb', line 169

def ancestors (priv_symbol = nil)
  priv_symbol ||= @privilege
  # context-specific?
  (@engine.rev_priv_hierarchy[[priv_symbol, nil]] || []).
      collect {|higher_priv| ancestors(higher_priv) }.flatten +
    (priv_symbol == @privilege ? [] : [Privilege.for_sym(priv_symbol, @engine)])
end

- (Object) descendants(priv_symbol = nil)



176
177
178
179
180
181
182
# File 'lib/declarative_authorization/development_support/development_support.rb', line 176

def descendants (priv_symbol = nil)
  priv_symbol ||= @privilege
  # context-specific?
  (@engine.privilege_hierarchy[priv_symbol] || []).
      collect {|lower_priv, context| descendants(lower_priv) }.flatten +
    (priv_symbol == @privilege ? [] : [Privilege.for_sym(priv_symbol, @engine)])
end

- (Object) rules



184
185
186
# File 'lib/declarative_authorization/development_support/development_support.rb', line 184

def rules
  @rules ||= find_rules_for_privilege
end

- (Object) source_file



190
191
192
# File 'lib/declarative_authorization/development_support/development_support.rb', line 190

def source_file
  rules.empty? ? nil : rules.first.source_file
end

- (Object) source_line



187
188
189
# File 'lib/declarative_authorization/development_support/development_support.rb', line 187

def source_line
  rules.empty? ? nil : rules.first.source_line
end

- (Object) to_sym



194
195
196
# File 'lib/declarative_authorization/development_support/development_support.rb', line 194

def to_sym
  @privilege
end