Class: Chef::Resource::Conditional
- Includes:
- Mixin::ShellOut
- Defined in:
- lib/chef/resource/conditional.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#command_opts ⇒ Object
readonly
Returns the value of attribute command_opts.
-
#positivity ⇒ Object
readonly
Returns the value of attribute positivity.
Class Method Summary collapse
- .not_if(command = nil, command_opts = {}, &block) ⇒ Object
- .only_if(command = nil, command_opts = {}, &block) ⇒ Object
Instance Method Summary collapse
- #continue? ⇒ Boolean
- #description ⇒ Object
- #evaluate ⇒ Object
- #evaluate_block ⇒ Object
- #evaluate_command ⇒ Object
-
#initialize(positivity, command = nil, command_opts = {}, &block) ⇒ Conditional
constructor
A new instance of Conditional.
Methods included from Mixin::ShellOut
Constructor Details
#initialize(positivity, command = nil, command_opts = {}, &block) ⇒ Conditional
Returns a new instance of Conditional.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/chef/resource/conditional.rb', line 45 def initialize(positivity, command=nil, command_opts={}, &block) @positivity = positivity case command when String @command, @command_opts = command, command_opts @block = nil when nil raise ArgumentError, "only_if/not_if requires either a command or a block" unless block_given? @command, @command_opts = nil, nil @block = block else raise ArgumentError, "Invalid only_if/not_if command: #{command.inspect} (#{command.class})" end end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
43 44 45 |
# File 'lib/chef/resource/conditional.rb', line 43 def block @block end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
41 42 43 |
# File 'lib/chef/resource/conditional.rb', line 41 def command @command end |
#command_opts ⇒ Object (readonly)
Returns the value of attribute command_opts.
42 43 44 |
# File 'lib/chef/resource/conditional.rb', line 42 def command_opts @command_opts end |
#positivity ⇒ Object (readonly)
Returns the value of attribute positivity.
40 41 42 |
# File 'lib/chef/resource/conditional.rb', line 40 def positivity @positivity end |
Class Method Details
.not_if(command = nil, command_opts = {}, &block) ⇒ Object
32 33 34 |
# File 'lib/chef/resource/conditional.rb', line 32 def self.not_if(command=nil, command_opts={}, &block) new(:not_if, command, command_opts, &block) end |
.only_if(command = nil, command_opts = {}, &block) ⇒ Object
36 37 38 |
# File 'lib/chef/resource/conditional.rb', line 36 def self.only_if(command=nil, command_opts={}, &block) new(:only_if, command, command_opts, &block) end |
Instance Method Details
#continue? ⇒ Boolean
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/chef/resource/conditional.rb', line 60 def continue? case @positivity when :only_if evaluate when :not_if !evaluate else raise "Cannot evaluate resource conditional of type #{@positivity}" end end |
#description ⇒ Object
83 84 85 86 |
# File 'lib/chef/resource/conditional.rb', line 83 def description cmd_or_block = @command ? "command `#{@command}`" : "ruby block" "#{@positivity} #{cmd_or_block}" end |
#evaluate ⇒ Object
71 72 73 |
# File 'lib/chef/resource/conditional.rb', line 71 def evaluate @command ? evaluate_command : evaluate_block end |
#evaluate_block ⇒ Object
79 80 81 |
# File 'lib/chef/resource/conditional.rb', line 79 def evaluate_block @block.call end |
#evaluate_command ⇒ Object
75 76 77 |
# File 'lib/chef/resource/conditional.rb', line 75 def evaluate_command shell_out(@command, @command_opts).status.success? end |