Class: RobotLab::DotState

Inherits:
Object
  • Object
show all
Defined in:
lib/robot_lab/hook_context.rb

Instance Method Summary collapse

Constructor Details

#initializeDotState

Returns a new instance of DotState.



167
168
169
# File 'lib/robot_lab/hook_context.rb', line 167

def initialize
  @data = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



176
177
178
179
180
181
182
183
184
# File 'lib/robot_lab/hook_context.rb', line 176

def method_missing(name, *args)
  key = name.to_s.delete_suffix('=').to_sym

  if name.to_s.end_with?('=')
    @data[key] = args.first
  else
    @data[key]
  end
end

Instance Method Details

#merge_defaults(hash) ⇒ Object



171
172
173
174
# File 'lib/robot_lab/hook_context.rb', line 171

def merge_defaults(hash)
  hash.each { |k, v| @data[k.to_sym] = v unless @data.key?(k.to_sym) }
  self
end

#respond_to_missing?Boolean

Returns:

  • (Boolean)


186
187
188
# File 'lib/robot_lab/hook_context.rb', line 186

def respond_to_missing?(*)
  true
end

#to_hObject



190
191
192
# File 'lib/robot_lab/hook_context.rb', line 190

def to_h
  @data.dup
end