Class: Igniter::Contracts::Execution::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/igniter/contracts/execution/operation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, name:, attributes: {}) ⇒ Operation

Returns a new instance of Operation.



9
10
11
12
13
14
# File 'lib/igniter/contracts/execution/operation.rb', line 9

def initialize(kind:, name:, attributes: {})
  @kind = kind.to_sym
  @name = name.to_sym
  @attributes = attributes.transform_keys(&:to_sym).freeze
  freeze
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



7
8
9
# File 'lib/igniter/contracts/execution/operation.rb', line 7

def attributes
  @attributes
end

#kindObject (readonly)

Returns the value of attribute kind.



7
8
9
# File 'lib/igniter/contracts/execution/operation.rb', line 7

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/igniter/contracts/execution/operation.rb', line 7

def name
  @name
end

Instance Method Details

#attribute(key) ⇒ Object



16
17
18
# File 'lib/igniter/contracts/execution/operation.rb', line 16

def attribute(key)
  attributes.fetch(key.to_sym)
end

#attribute?(key) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/igniter/contracts/execution/operation.rb', line 20

def attribute?(key)
  attributes.key?(key.to_sym)
end

#output?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/igniter/contracts/execution/operation.rb', line 28

def output?
  kind == :output
end

#to_hObject



32
33
34
35
36
37
38
# File 'lib/igniter/contracts/execution/operation.rb', line 32

def to_h
  {
    kind: kind,
    name: name,
    attributes: StructuredDump.dump(attributes)
  }
end

#with_attributes(updated_attributes) ⇒ Object



24
25
26
# File 'lib/igniter/contracts/execution/operation.rb', line 24

def with_attributes(updated_attributes)
  self.class.new(kind: kind, name: name, attributes: updated_attributes)
end