Class: JobWorkflow::Arguments

Inherits:
Object
  • Object
show all
Defined in:
lib/job_workflow/arguments.rb,
sig/generated/job_workflow/arguments.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:) ⇒ Arguments

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

Parameters:

  • data: (Hash[Symbol, untyped])


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) ⇒ void

This method returns an undefined value.

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

Parameters:

  • name (Symbol)
  • args (Object)
  • kwargs (Object)


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 Attribute Details

#dataHash[Symbol, untyped] (readonly)

Signature:

  • Hash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


37
38
39
# File 'lib/job_workflow/arguments.rb', line 37

def data
  @data
end

#reader_namesSet[Symbol] (readonly)

Signature:

  • Set[Symbol]

Returns:

  • (Set[Symbol])


38
39
40
# File 'lib/job_workflow/arguments.rb', line 38

def reader_names
  @reader_names
end

Instance Method Details

#merge(other_data) ⇒ Arguments

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

Parameters:

  • other_data (Hash[Symbol, untyped])

Returns:



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

Parameters:

  • sym (Symbol)
  • include_private (Boolean)

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_hHash[Symbol, untyped]

: () -> Hash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


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

def to_h
  data
end