Class: Spectre::Mixin::MixinContext

Inherits:
DslClass show all
Defined in:
lib/spectre/mixin.rb

Instance Method Summary collapse

Methods inherited from DslClass

#_evaluate, #_execute, #method_missing

Constructor Details

#initialize(desc) ⇒ MixinContext

Returns a new instance of MixinContext.



9
10
11
# File 'lib/spectre/mixin.rb', line 9

def initialize desc
  @__desc = desc
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Spectre::DslClass

Instance Method Details

#optional(params, *keys) ⇒ Object



19
20
21
22
# File 'lib/spectre/mixin.rb', line 19

def optional params, *keys
  Spectre::Logging.log_debug("optional parameters for '#{@__desc}': #{keys.join ', '}")
  params
end

#required(params, *keys) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
# File 'lib/spectre/mixin.rb', line 13

def required params, *keys
  missing_keys = keys.select { |x| !params.to_h.key? x }
  Spectre::Logging.log_debug("required parameters for '#{@__desc}': #{keys.join ', '}")
  raise ArgumentError, "mixin '#{@__desc}' requires #{keys.join ', '}, but only has #{missing_keys.join ', '} given" unless missing_keys.empty?
end