Class: Puppet::Interface::ActionBuilder
- Defined in:
- lib/vendor/puppet/interface/action_builder.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
Class Method Summary collapse
Instance Method Summary collapse
- #default(value = true) ⇒ Object
- #option(*declaration, &block) ⇒ Object
- #render_as(value = nil) ⇒ Object
-
#when_invoked(&block) ⇒ Object
Ideally the method we’re defining here would be added to the action, and a method on the face would defer to it, but we can’t get scope correct, so we stick with this.
- #when_rendering(type = nil, &block) ⇒ Object
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
5 6 7 |
# File 'lib/vendor/puppet/interface/action_builder.rb', line 5 def action @action end |
Class Method Details
.build(face, name, &block) ⇒ Object
7 8 9 10 |
# File 'lib/vendor/puppet/interface/action_builder.rb', line 7 def self.build(face, name, &block) raise "Action #{name.inspect} must specify a block" unless block new(face, name, &block).action end |
Instance Method Details
#default(value = true) ⇒ Object
34 35 36 |
# File 'lib/vendor/puppet/interface/action_builder.rb', line 34 def default(value = true) @action.default = !!value end |
#option(*declaration, &block) ⇒ Object
29 30 31 32 |
# File 'lib/vendor/puppet/interface/action_builder.rb', line 29 def option(*declaration, &block) option = Puppet::Interface::OptionBuilder.build(@action, *declaration, &block) @action.add_option(option) end |
#render_as(value = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vendor/puppet/interface/action_builder.rb', line 38 def render_as(value = nil) value.nil? and raise ArgumentError, "You must give a rendering format to render_as" formats = Puppet::Network::FormatHandler.formats unless formats.include? value raise ArgumentError, "#{value.inspect} is not a valid rendering format: #{formats.sort.join(", ")}" end @action.render_as = value end |
#when_invoked(&block) ⇒ Object
Ideally the method we’re defining here would be added to the action, and a method on the face would defer to it, but we can’t get scope correct, so we stick with this. –daniel 2011-03-24
15 16 17 |
# File 'lib/vendor/puppet/interface/action_builder.rb', line 15 def when_invoked(&block) @action.when_invoked = block end |
#when_rendering(type = nil, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/puppet/interface/action_builder.rb', line 19 def when_rendering(type = nil, &block) if type.nil? then # the default error message sucks --daniel 2011-04-18 raise ArgumentError, 'You must give a rendering format to when_rendering' end if block.nil? then raise ArgumentError, 'You must give a block to when_rendering' end @action.set_rendering_method_for(type, block) end |