Class: JobWorkflow::Arguments

Inherits:
Object
  • Object
show all
Defined in:
lib/job_workflow/arguments.rb

Instance Method Summary collapse

Constructor Details

#initialize(data:) ⇒ Arguments

: (data: Hash[Symbol, untyped]) -> void



6
7
8
9
# File 'lib/job_workflow/arguments.rb', line 6

def initialize(data:)
  @data = data.freeze
  @reader_names = data.keys.to_set
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

: (Symbol name, *untyped args, **untyped kwargs) ?{ () -> untyped } -> untyped



18
19
20
21
22
23
# File 'lib/job_workflow/arguments.rb', line 18

def method_missing(name, *args, **kwargs, &block)
  return super unless args.empty? && kwargs.empty? && block.nil?
  return super unless reader_names.include?(name.to_sym)

  data[name.to_sym]
end

Instance Method Details

#merge(other_data) ⇒ Object

: (Hash[Symbol, untyped] other_data) -> Arguments



12
13
14
15
# File 'lib/job_workflow/arguments.rb', line 12

def merge(other_data)
  merged = data.merge(other_data.slice(*reader_names.to_a))
  self.class.new(data: merged)
end

#respond_to_missing?(sym, include_private) ⇒ Boolean

: (Symbol sym, bool include_private) -> bool

Returns:

  • (Boolean)


26
27
28
# File 'lib/job_workflow/arguments.rb', line 26

def respond_to_missing?(sym, include_private)
  reader_names.include?(sym.to_sym) || super
end

#to_hObject

: () -> Hash[Symbol, untyped]



31
32
33
# File 'lib/job_workflow/arguments.rb', line 31

def to_h
  data
end