Class: Petticoat::Snapshot
- Inherits:
-
Object
- Object
- Petticoat::Snapshot
- Defined in:
- lib/petticoat/snapshot.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Instance Method Summary collapse
- #actions ⇒ Object
- #aliases ⇒ Object
- #evidence(subject_identifier) ⇒ Object
-
#initialize(ability) ⇒ Snapshot
constructor
A new instance of Snapshot.
- #state(action, subject) ⇒ Object
- #subjects ⇒ Object
Constructor Details
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
5 6 7 |
# File 'lib/petticoat/snapshot.rb', line 5 def adapter @adapter end |
Instance Method Details
#actions ⇒ Object
26 27 28 |
# File 'lib/petticoat/snapshot.rb', line 26 def actions adapter.actions.grep(Symbol).map(&:to_s).sort end |
#aliases ⇒ Object
30 31 32 |
# File 'lib/petticoat/snapshot.rb', line 30 def aliases adapter.aliases.to_h { |key, values| [key.to_s, values.map(&:to_s).uniq.sort] } end |
#evidence(subject_identifier) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/petticoat/snapshot.rb', line 38 def evidence(subject_identifier) adapter.rules.map do |rule| { 'allow' => rule.base_behavior, 'actions' => rule.actions.filter_map { |action| action.to_s if action.is_a?(Symbol) }, 'subjects' => rule.subjects.map { |subject| subject_identifier.call(subject) || 'unsupported' }, 'predicate' => predicate_kind(rule), 'attributes_restricted' => !rule.attributes.empty? } end end |
#state(action, subject) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/petticoat/snapshot.rb', line 11 def state(action, subject) return 'unknown' if unsupported? # An object cannot equal an explicit Symbol action, so this queries only # manage grants. No permission predicate is evaluated. query = action == '*' ? Object.new : action.to_sym relevant = adapter.relevant(query, subject) return 'unknown' if raw_conditions?(relevant) possibilities = outcomes(relevant) return 'conditional' if possibilities.size > 1 possibilities.first ? 'unconditional' : 'denied' end |
#subjects ⇒ Object
34 35 36 |
# File 'lib/petticoat/snapshot.rb', line 34 def subjects adapter.rules.flat_map(&:subjects).uniq end |