Class: Clickwrap::AuthorityDecision
- Inherits:
-
Data
- Object
- Data
- Clickwrap::AuthorityDecision
- Defined in:
- lib/clickwrap/authority.rb
Overview
The host's answer to "may this actor act for that represented party?". Clickwrap records the answer and its provenance; it does not decide whether the authority is legally sufficient.
Instance Attribute Summary collapse
-
#authorized ⇒ Object
readonly
Returns the value of attribute authorized.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#verified_at ⇒ Object
readonly
Returns the value of attribute verified_at.
Class Method Summary collapse
Instance Method Summary collapse
- #authorized? ⇒ Boolean
-
#initialize(authorized: false, source: nil, role: nil, verified_at: nil, details: {}) ⇒ AuthorityDecision
constructor
A new instance of AuthorityDecision.
- #to_snapshot ⇒ Object
Constructor Details
#initialize(authorized: false, source: nil, role: nil, verified_at: nil, details: {}) ⇒ AuthorityDecision
Returns a new instance of AuthorityDecision.
72 73 74 75 76 77 78 79 80 |
# File 'lib/clickwrap/authority.rb', line 72 def initialize(authorized: false, source: nil, role: nil, verified_at: nil, details: {}) super( authorized: == true, source: source&.to_s, role: role&.to_s, verified_at: verified_at, details: (details || {}).to_h.deep_stringify_keys.freeze ) end |
Instance Attribute Details
#authorized ⇒ Object (readonly)
Returns the value of attribute authorized
71 72 73 |
# File 'lib/clickwrap/authority.rb', line 71 def @authorized end |
#details ⇒ Object (readonly)
Returns the value of attribute details
71 72 73 |
# File 'lib/clickwrap/authority.rb', line 71 def details @details end |
#role ⇒ Object (readonly)
Returns the value of attribute role
71 72 73 |
# File 'lib/clickwrap/authority.rb', line 71 def role @role end |
#source ⇒ Object (readonly)
Returns the value of attribute source
71 72 73 |
# File 'lib/clickwrap/authority.rb', line 71 def source @source end |
#verified_at ⇒ Object (readonly)
Returns the value of attribute verified_at
71 72 73 |
# File 'lib/clickwrap/authority.rb', line 71 def verified_at @verified_at end |
Class Method Details
.from(value) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/clickwrap/authority.rb', line 94 def self.from(value) return value if value.is_a?(self) if value == true raise ConfigurationError, "The represented-party authority callback returned bare true. Return a " \ "Clickwrap::AuthorityDecision (or a hash) with `authorized:`, `source:`, " \ "`role:`, and `verified_at:` so the evidence records why the actor was authorized." end return new(authorized: false) if value.nil? || value == false unless value.respond_to?(:to_h) raise ConfigurationError, "The represented-party authority callback must return false, nil, a " \ "Clickwrap::AuthorityDecision, or a hash with `authorized:`, `source:`, " \ "`role:`, and `verified_at:`. It returned #{value.class.name}." end attributes = value.to_h.symbolize_keys unknown = attributes.keys - AUTHORITY_DECISION_ATTRIBUTES if unknown.any? label = unknown.one? ? "attribute" : "attributes" raise ConfigurationError, "The represented-party authority callback returned unknown #{label} " \ "#{unknown.map { |key| "`#{key}:`" }.join(", ")}. Supported attributes are " \ "#{AUTHORITY_DECISION_ATTRIBUTES.map { |key| "`#{key}:`" }.join(", ")}." end new(**attributes) end |
Instance Method Details
#authorized? ⇒ Boolean
82 |
# File 'lib/clickwrap/authority.rb', line 82 def = == true |
#to_snapshot ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/clickwrap/authority.rb', line 84 def to_snapshot { "state" => ? "verified" : "not_verified", "source" => source, "role" => role, "verified_at" => verified_at&.iso8601(6), "details" => details.presence }.compact end |