Class: ClusterChef::DslObject
- Inherits:
-
Object
- Object
- ClusterChef::DslObject
- Defined in:
- lib/cluster_chef/dsl_object.rb
Overview
Provides magic methods, defined with has_keys
Direct Known Subclasses
Cloud::Base, Cloud::SecurityGroup, ComputeBuilder, PrivateKey, ServerSlice, Volume
Class Method Summary collapse
-
.has_keys(*key_names) ⇒ Object
Defines DSL attributes.
-
.ui ⇒ Object
delegate to the knife ui presenter.
Instance Method Summary collapse
- #configure(hsh = {}, &block) ⇒ Object
-
#die(*args) ⇒ Object
helper method for bombing out of a script.
-
#dump(*args) ⇒ Object
helper method for debugging only.
-
#initialize(attrs = {}, &block) ⇒ DslObject
constructor
A new instance of DslObject.
- #reverse_merge!(hsh) ⇒ Object
-
#safely(*args, &block) ⇒ Object
helper method for turning exceptions into warnings.
-
#set(key, val = nil) ⇒ Object
Sets the DSL attribute, unless the given value is nil.
- #step(desc, *style) ⇒ Object
- #to_hash ⇒ Object
- #to_mash ⇒ Object
- #to_s ⇒ Object
-
#ui ⇒ Object
delegate to the knife ui presenter.
Constructor Details
#initialize(attrs = {}, &block) ⇒ DslObject
Returns a new instance of DslObject.
49 50 51 52 |
# File 'lib/cluster_chef/dsl_object.rb', line 49 def initialize(attrs={}, &block) @settings = Mash.new configure(attrs, &block) end |
Class Method Details
.has_keys(*key_names) ⇒ Object
Defines DSL attributes
66 67 68 69 70 71 72 73 74 |
# File 'lib/cluster_chef/dsl_object.rb', line 66 def self.has_keys(*key_names) key_names.map!(&:to_sym) self.keys += key_names self.keys.uniq! key_names.each do |key| next if method_defined?(key) define_method(key){|*args| set(key, *args) } end end |
.ui ⇒ Object
delegate to the knife ui presenter
109 |
# File 'lib/cluster_chef/dsl_object.rb', line 109 def self.ui() ClusterChef.ui ; end |
Instance Method Details
#configure(hsh = {}, &block) ⇒ Object
100 101 102 103 104 |
# File 'lib/cluster_chef/dsl_object.rb', line 100 def configure(hsh={}, &block) @settings.merge!(hsh.to_hash) instance_eval(&block) if block self end |
#die(*args) ⇒ Object
helper method for bombing out of a script
116 |
# File 'lib/cluster_chef/dsl_object.rb', line 116 def die(*args) ClusterChef.die(*args) ; end |
#dump(*args) ⇒ Object
helper method for debugging only
122 |
# File 'lib/cluster_chef/dsl_object.rb', line 122 def dump(*args) args.each{|arg| Chef::Log.debug( arg.inspect ) } end |
#reverse_merge!(hsh) ⇒ Object
96 97 98 |
# File 'lib/cluster_chef/dsl_object.rb', line 96 def reverse_merge!(hsh) @settings.reverse_merge!(hsh.to_hash) end |
#safely(*args, &block) ⇒ Object
helper method for turning exceptions into warnings
119 |
# File 'lib/cluster_chef/dsl_object.rb', line 119 def safely(*args, &block) ClusterChef.safely(*args, &block) ; end |
#set(key, val = nil) ⇒ Object
Sets the DSL attribute, unless the given value is nil.
79 80 81 82 |
# File 'lib/cluster_chef/dsl_object.rb', line 79 def set(key, val=nil) @settings[key.to_s] = val unless val.nil? @settings[key.to_s] end |
#step(desc, *style) ⇒ Object
111 112 113 |
# File 'lib/cluster_chef/dsl_object.rb', line 111 def step(desc, *style) ui.info(" #{"%-15s" % (name.to_s+":")}\t#{ui.color(desc.to_s, *style)}") end |
#to_hash ⇒ Object
84 85 86 |
# File 'lib/cluster_chef/dsl_object.rb', line 84 def to_hash @settings.to_hash end |
#to_mash ⇒ Object
88 89 90 |
# File 'lib/cluster_chef/dsl_object.rb', line 88 def to_mash @settings.dup end |
#to_s ⇒ Object
92 93 94 |
# File 'lib/cluster_chef/dsl_object.rb', line 92 def to_s "<#{self.class} #{to_hash.inspect}>" end |
#ui ⇒ Object
delegate to the knife ui presenter
107 |
# File 'lib/cluster_chef/dsl_object.rb', line 107 def ui() ClusterChef.ui ; end |