Module: Dotum::RuleDSL

Included in:
AbstractRules::Base, RuleRunner
Defined in:
lib/dotum/rule_dsl.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dotum/rule_dsl.rb', line 55

def method_missing(sym, *args, &block)
  rule_class_name = sym.to_s.split("_").map(&:capitalize).join.to_sym

  begin
    rule_class = Dotum::Rules.const_get(rule_class_name)
  rescue LoadError
    raise NoMethodError, "Unknown rule #{sym}.  Tried to load Dotum::Rules::#{rule_class_name}: #{$!.message}"
  end

  Dotum::RuleDSL.module_eval <<-end_eval, __FILE__, __LINE__
    def #{sym}(*args, &block)
      Dotum::Rules::#{rule_class_name}.exec(context, *args, &block)
    end
  end_eval

  send(sym, *args, &block)
end

Instance Method Details

#available?(command) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/dotum/rule_dsl.rb', line 37

def available?(command)
  # TODO: Windows friendly.
  `which "#{command}"`
  $?.success?
end

#failure!(reason = nil) ⇒ Object



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

def failure!(reason=nil)
  throw :finish_rule, [:failure, reason]
end

#package_dirObject



43
44
45
# File 'lib/dotum/rule_dsl.rb', line 43

def package_dir
  context.package_dir
end

#platform?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

def platform?(name)
  os = RbConfig::CONFIG["host_os"].downcase

  case name
  when /os\s?x/i     then /mac|darwin/      === os
  when /win(dows)?/i then /mswin|win|mingw/ === os
  when /linux/i      then /linux|cygwin/    === os
  when /bsd/i        then /bsd/             === os
  when /solaris/i    then /solaris|sunos/   === os
  else
    if name.is_a? Regexp
      name === os
    else
      Regexp.new(name, "i") === os
    end
  end
end

#skip!(reason = nil) ⇒ Object



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

def skip!(reason=nil)
  throw :finish_rule, [:skip, reason]
end

#state_dirObject



51
52
53
# File 'lib/dotum/rule_dsl.rb', line 51

def state_dir
  context.state_dir
end

#success!(reason = nil) ⇒ Object



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

def success!(reason=nil)
  throw :finish_rule, [:success, reason]
end

#target_dirObject



47
48
49
# File 'lib/dotum/rule_dsl.rb', line 47

def target_dir
  context.target_dir
end