Class: Servactory::Context::Workspace::Inputs

Inherits:
Object
  • Object
show all
Defined in:
lib/servactory/context/workspace/inputs.rb

Instance Method Summary collapse

Constructor Details

#initialize(context:, collection_of_inputs:) ⇒ Inputs

Returns a new instance of Inputs.



7
8
9
10
# File 'lib/servactory/context/workspace/inputs.rb', line 7

def initialize(context:, collection_of_inputs:)
  @context = context
  @collection_of_inputs = collection_of_inputs
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_args) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/servactory/context/workspace/inputs.rb', line 24

def method_missing(name, *_args)
  if name.to_s.end_with?("=")
    prepared_name = name.to_s.delete("=").to_sym

    raise_error_for(:assign, prepared_name)
  else
    fetch_with(name:) { raise_error_for(:fetch, name) }
  end
end

Instance Method Details

#except(*names) ⇒ Object



18
19
20
21
22
# File 'lib/servactory/context/workspace/inputs.rb', line 18

def except(*names)
  @collection_of_inputs
    .except(*names)
    .to_h { |input| [input.internal_name, send(input.internal_name)] }
end

#only(*names) ⇒ Object



12
13
14
15
16
# File 'lib/servactory/context/workspace/inputs.rb', line 12

def only(*names)
  @collection_of_inputs
    .only(*names)
    .to_h { |input| [input.internal_name, send(input.internal_name)] }
end

#respond_to_missing?(name) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/servactory/context/workspace/inputs.rb', line 34

def respond_to_missing?(name, *)
  @collection_of_inputs.names.include?(name) || super
end