class Hookit::Resource::Base
Attributes
dict[RW]
Public Class Methods
actions(*actions)
click to toggle source
# File lib/hookit/resource/base.rb, line 17 def actions(*actions) if actions.any? @actions = *actions else @actions end end
default_action(action=nil)
click to toggle source
# File lib/hookit/resource/base.rb, line 25 def default_action(action=nil) if action @default_action = action else @default_action || :run end end
field(key)
click to toggle source
# File lib/hookit/resource/base.rb, line 7 def field(key) define_method key do |*args, &block| if data = block || args[0] instance_variable_set("@#{key}", data) else instance_variable_get("@#{key}") end end end
new(name)
click to toggle source
# File lib/hookit/resource/base.rb, line 39 def initialize(name) name(name) end
Public Instance Methods
action(*actions)
click to toggle source
# File lib/hookit/resource/base.rb, line 60 def action(*actions) if actions.any? actions.each do |action| if not self.class.actions.include? action raise Hookit::Error::UnknownAction, "unknown action '#{action}'" end end @actions = *actions else @actions || [default_action] end end
can_run?()
click to toggle source
# File lib/hookit/resource/base.rb, line 45 def can_run? only_if_res = true not_if_res = false if only_if and only_if.respond_to? :call only_if_res = only_if.call end if not_if and not_if.respond_to? :call not_if_res = not_if.call end only_if_res and not not_if_res end
default_action()
click to toggle source
# File lib/hookit/resource/base.rb, line 73 def default_action self.class.default_action end
not_if(&block)
click to toggle source
# File lib/hookit/resource/base.rb, line 77 def not_if(&block) if block_given? @not_if = block else @not_if end end
only_if(&block)
click to toggle source
# File lib/hookit/resource/base.rb, line 85 def only_if(&block) if block_given? @only_if = block else @only_if end end
run(action)
click to toggle source
# File lib/hookit/resource/base.rb, line 43 def run(action); end
Protected Instance Methods
run_command!(cmd, expect_code=0)
click to toggle source
# File lib/hookit/resource/base.rb, line 95 def run_command!(cmd, expect_code=0) `#{cmd}` code = $?.exitstatus # break early if the caller doesn't want to validate the exit code if expect_code == false return end if code != expect_code raise Hookit::Error::UnexpectedExit, "#{cmd} failed with exit code '#{code}'" end end