Class: Dotum::AbstractRules::Base

Inherits:
Object
  • Object
show all
Extended by:
RuleOptionsDSL
Includes:
RuleDSL
Defined in:
lib/dotum/abstract_rules/base.rb

Direct Known Subclasses

OptionsBase, Rules::Cd, Rules::Run

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

Returns a new instance of Base.



15
16
17
# File 'lib/dotum/abstract_rules/base.rb', line 15

def initialize(context)
  @context = context.child
end

Dynamic Method Handling

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

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



38
39
40
# File 'lib/dotum/abstract_rules/base.rb', line 38

def context
  @context
end

Class Method Details

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



7
8
9
# File 'lib/dotum/abstract_rules/base.rb', line 7

def self.exec(context, *args, &block)
  new(context, *args, &block).exec
end

.prettyObject



11
12
13
# File 'lib/dotum/abstract_rules/base.rb', line 11

def self.pretty
  @pretty ||= name.split('::').last.gsub(/([^A-Z])([A-Z]+)/, "\\1_\\2").downcase
end

Instance Method Details

#execObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dotum/abstract_rules/base.rb', line 19

def exec
  context.logger.start_rule(self)

  status, reason = catch(:finish_rule) do
    preprocess
    execute

    success!
  end

  context.logger.finish_rule(self, status, reason)

  if status == :failure
    raise "Rule failed: #{reason}"
  end

  self
end

#pretty_subjectObject

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/dotum/abstract_rules/base.rb', line 40

def pretty_subject
  raise NotImplementedError, "#{self.class}#pretty_subject"
end