Class: Dotum::AbstractRules::OptionsBase

Inherits:
Base
  • Object
show all
Defined in:
lib/dotum/abstract_rules/options_base.rb

Instance Attribute Summary

Attributes inherited from Base

#context

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#exec, pretty, #pretty_subject

Methods included from RuleOptionsDSL

#eval_options_block, #expand_shorthand, #option_configs, #option_defaults, #optional, #preprocessor_methods, #register_preprocessor, #required, #shorthand, #shorthand_config, #standard, #validate_options

Methods included from RuleDSL

#available?, #failure!, #method_missing, #package_dir, #platform?, #skip!, #state_dir, #success!, #target_dir

Constructor Details

#initialize(context, options) ⇒ OptionsBase

Returns a new instance of OptionsBase.



22
23
24
25
26
27
28
29
30
31
# File 'lib/dotum/abstract_rules/options_base.rb', line 22

def initialize(context, options)
  super(context)

  options.each do |option, value|
    filter = self.class.option_configs[option][:filter]
    value = instance_exec(value, &filter) if filter && !value.nil?

    instance_variable_set(:"@#{option}", value)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Dotum::RuleDSL

Class Method Details

.exec(context, *args, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dotum/abstract_rules/options_base.rb', line 5

def self.exec(context, *args, &block)
  options = option_defaults.merge(expand_shorthand(*args))
  options.merge! eval_options_block(&block) if block

  if errors = validate_options(options)
    raise "Validation errors: #{errors.inspect}"
  end

  if respond_to? :expand_options
    expand_options(context, options).map { |rule_options|
      new(context, rule_options).exec
    }
  else
    new(context, options).exec
  end
end