Class: Yabeda::DSL::OptionBuilder

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/yabeda/dsl/option_builder.rb

Overview

Collects options for metric initializer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metric_klass, options) ⇒ Object

Parameters:

  • metric_klass
  • options

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, method_args, &_block) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/yabeda/dsl/option_builder.rb', line 21

def method_missing(method_name, method_args, &_block)
  if kwarg?(method_name)
    options[method_name] = method_args
  else
    super
  end
end

Instance Attribute Details

#metric_klassObject (readonly)

Reader method for the metric_klass initializer parameter.



9
# File 'lib/yabeda/dsl/option_builder.rb', line 9

param :metric_klass

#optionsObject (readonly)

Reader method for the options initializer parameter.



10
# File 'lib/yabeda/dsl/option_builder.rb', line 10

param :options

Instance Method Details

#options_from(&block) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
# File 'lib/yabeda/dsl/option_builder.rb', line 12

def options_from(&block)
  instance_eval(&block) if block

  return options if unknown_options.empty?

  raise ConfigurationError,
        "option '#{unknown_options.first}' is not available for #{metric_klass.name}"
end

#respond_to_missing?(method_name, _args) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/yabeda/dsl/option_builder.rb', line 29

def respond_to_missing?(method_name, _args)
  kwarg?(method_name) || super
end