class SousChef::Resource::Base
Attributes
context[R]
name[R]
Public Class Methods
new(context, name, &block)
click to toggle source
# File lib/sous_chef/resource/base.rb, line 6 def initialize(context, name, &block) @context = context @name = name @block = block @only_if = nil @commands = [] end
Public Instance Methods
append(cmd)
click to toggle source
# File lib/sous_chef/resource/base.rb, line 42 def append(cmd) @commands.push(cmd) end
Also aliased as: command
not_if(cmd=nil)
click to toggle source
# File lib/sous_chef/resource/base.rb, line 21 def not_if(cmd=nil) only_if "! #{cmd}" end
only_if(cmd=nil)
click to toggle source
# File lib/sous_chef/resource/base.rb, line 25 def only_if(cmd=nil) if cmd @only_if = cmd else @only_if end end
prepend(cmd)
click to toggle source
# File lib/sous_chef/resource/base.rb, line 38 def prepend(cmd) @commands.unshift(cmd) end
respond_to?(meth)
click to toggle source
Calls superclass method
# File lib/sous_chef/resource/base.rb, line 34 def respond_to?(meth) super || context.respond_to?(meth) end
Also aliased as: resource_respond_to?
setup()
click to toggle source
# File lib/sous_chef/resource/base.rb, line 14 def setup if @block instance_eval &@block @block = nil end end
to_script()
click to toggle source
# File lib/sous_chef/resource/base.rb, line 48 def to_script setup if only_if @commands.compact! @commands.map! { |line| " #{line}" } prepend "if #{only_if}; then" append "fi" end @commands.join("\n").strip end
Protected Instance Methods
method_missing(meth, *args, &block)
click to toggle source
Calls superclass method
# File lib/sous_chef/resource/base.rb, line 70 def method_missing(meth, *args, &block) if context.respond_to?(meth) context.__send__(meth, *args, &block) else super end end
set_or_return(attr, val)
click to toggle source
# File lib/sous_chef/resource/base.rb, line 62 def set_or_return(attr, val) if val.nil? instance_variable_get("@#{attr}") else instance_variable_set("@#{attr}", val) end end