Class: Igniter::Contracts::Execution::Builder

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile:) ⇒ Builder

Returns a new instance of Builder.



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

def initialize(profile:)
  @profile = profile
  @operations = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object



30
31
32
33
34
35
# File 'lib/igniter/contracts/execution/builder.rb', line 30

def method_missing(name, *args, **kwargs, &block)
  keyword = profile.dsl_keyword(name)
  keyword.call(*args, builder: self, **kwargs, &block)
rescue KeyError
  raise UnknownDslKeywordError, "unknown DSL keyword #{name}"
end

Instance Attribute Details

#operationsObject (readonly)

Returns the value of attribute operations.



13
14
15
# File 'lib/igniter/contracts/execution/builder.rb', line 13

def operations
  @operations
end

#profileObject (readonly)

Returns the value of attribute profile.



13
14
15
# File 'lib/igniter/contracts/execution/builder.rb', line 13

def profile
  @profile
end

Class Method Details

.build(profile:, &block) ⇒ Object



7
8
9
10
11
# File 'lib/igniter/contracts/execution/builder.rb', line 7

def self.build(profile:, &block)
  builder = new(profile: profile)
  builder.instance_eval(&block)
  builder
end

Instance Method Details

#add_operation(kind:, name:, **attributes) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/igniter/contracts/execution/builder.rb', line 20

def add_operation(kind:, name:, **attributes)
  normalized_kind = kind.to_sym
  unless profile.supports_node_kind?(normalized_kind)
    raise UnknownNodeKindError,
          "unknown node kind #{normalized_kind}"
  end

  operations << Operation.new(kind: normalized_kind, name: name, attributes: attributes)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/igniter/contracts/execution/builder.rb', line 37

def respond_to_missing?(name, include_private = false)
  profile.dsl_keywords.key?(name.to_sym) || super
end