Class: Vangrail::Grant
- Inherits:
-
Object
- Object
- Vangrail::Grant
- Defined in:
- lib/vangrail/plan.rb
Overview
One scoped authority in a Plan.
Constant Summary collapse
- EFFECTS =
%i[read write external].freeze
Instance Attribute Summary collapse
-
#after ⇒ Object
readonly
Returns the value of attribute after.
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#conversation_id ⇒ Object
readonly
Returns the value of attribute conversation_id.
-
#effect ⇒ Object
readonly
Returns the value of attribute effect.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#integrity ⇒ Object
readonly
Returns the value of attribute integrity.
-
#sinks ⇒ Object
readonly
Returns the value of attribute sinks.
-
#tool ⇒ Object
readonly
Returns the value of attribute tool.
-
#uses ⇒ Object
readonly
Returns the value of attribute uses.
Instance Method Summary collapse
- #confirmation_required? ⇒ Boolean
-
#initialize(tool:, effect:, arguments: {}, sinks: nil, uses: nil, after: nil, integrity: nil, confirm: false, transaction: false, conversation_id: nil, id: nil) ⇒ Grant
constructor
A new instance of Grant.
- #to_h ⇒ Object
- #transaction_required? ⇒ Boolean
Constructor Details
#initialize(tool:, effect:, arguments: {}, sinks: nil, uses: nil, after: nil, integrity: nil, confirm: false, transaction: false, conversation_id: nil, id: nil) ⇒ Grant
Returns a new instance of Grant.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vangrail/plan.rb', line 16 def initialize(tool:, effect:, arguments: {}, sinks: nil, uses: nil, after: nil, integrity: nil, confirm: false, transaction: false, conversation_id: nil, id: nil) @tool = tool.to_sym @effect = effect.to_sym raise ArgumentError, "effect must be one of #{EFFECTS.join(', ')}" unless EFFECTS.include?(@effect) if !uses.nil? && (!uses.is_a?(Integer) || !uses.positive?) raise ArgumentError, 'uses must be a positive integer or nil' end @id = (id || SecureRandom.uuid).to_s.freeze @arguments = immutable_hash(arguments) @sinks = normalize_optional(sinks) @uses = uses @after = normalize(after) @integrity = normalize_optional(integrity) @confirmation_required = confirm.equal?(true) @transaction_required = transaction.equal?(true) @conversation_id = conversation_id&.to_s&.freeze freeze end |
Instance Attribute Details
#after ⇒ Object (readonly)
Returns the value of attribute after.
13 14 15 |
# File 'lib/vangrail/plan.rb', line 13 def after @after end |
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
13 14 15 |
# File 'lib/vangrail/plan.rb', line 13 def arguments @arguments end |
#conversation_id ⇒ Object (readonly)
Returns the value of attribute conversation_id.
13 14 15 |
# File 'lib/vangrail/plan.rb', line 13 def conversation_id @conversation_id end |
#effect ⇒ Object (readonly)
Returns the value of attribute effect.
13 14 15 |
# File 'lib/vangrail/plan.rb', line 13 def effect @effect end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/vangrail/plan.rb', line 13 def id @id end |
#integrity ⇒ Object (readonly)
Returns the value of attribute integrity.
13 14 15 |
# File 'lib/vangrail/plan.rb', line 13 def integrity @integrity end |
#sinks ⇒ Object (readonly)
Returns the value of attribute sinks.
13 14 15 |
# File 'lib/vangrail/plan.rb', line 13 def sinks @sinks end |
#tool ⇒ Object (readonly)
Returns the value of attribute tool.
13 14 15 |
# File 'lib/vangrail/plan.rb', line 13 def tool @tool end |
#uses ⇒ Object (readonly)
Returns the value of attribute uses.
13 14 15 |
# File 'lib/vangrail/plan.rb', line 13 def uses @uses end |
Instance Method Details
#confirmation_required? ⇒ Boolean
38 39 40 |
# File 'lib/vangrail/plan.rb', line 38 def confirmation_required? @confirmation_required end |
#to_h ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/vangrail/plan.rb', line 46 def to_h { 'id' => id, 'tool' => tool.to_s, 'effect' => effect.to_s, 'arguments' => arguments.transform_values { |constraint| describe(constraint) }, 'sinks' => sinks&.map(&:to_s), 'uses' => uses, 'after' => after.map(&:to_s), 'integrity' => integrity&.map(&:to_s), 'confirm' => confirmation_required?, 'transaction' => transaction_required?, 'conversation_id' => conversation_id, }.compact end |
#transaction_required? ⇒ Boolean
42 43 44 |
# File 'lib/vangrail/plan.rb', line 42 def transaction_required? @transaction_required end |