Module: BlackStack::Deployer::RoutineModule
- Included in:
- Routine
- Defined in:
- lib/my-ruby-deployer.rb
Overview
define attributes and methods of a deployer routine
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(h) ⇒ Object
def self.descriptor_error(h).
- #run(node, l = nil, params = {}) ⇒ Object
- #to_hash ⇒ Object
Instance Attribute Details
#commands ⇒ Object
Returns the value of attribute commands.
148 149 150 |
# File 'lib/my-ruby-deployer.rb', line 148 def commands @commands end |
#name ⇒ Object
Returns the value of attribute name.
148 149 150 |
# File 'lib/my-ruby-deployer.rb', line 148 def name @name end |
Class Method Details
.descriptor_errors(h) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/my-ruby-deployer.rb', line 150 def self.descriptor_errors(h) errors = [] # validate: the parameter h is a hash errors << "The parameter h is not a hash" unless h.is_a?(Hash) # validate: the paramerer h has a key :name errors << "The parameter h does not have a key :name" unless h.has_key?(:name) # validate: the paramerer h has a key :command errors << "The parameter h does not have a key :commands" unless h.has_key?(:commands) # validate: the parameter h[:name] is a string or a symbol errors << "The parameter h[:name] is not a string" unless h[:name].is_a?(String) # validate: the parameter h[:name] is not 'reboot' because it is a reserved name errors << "The parameter h[:name] is a reserved name (#{h[:name].to_s})" if h[:name] == 'reboot' # validate: the parameter h[:commands] is required errors << "The parameter h[:commands] is required" if h[:commands].nil? # validate: the parametrer h[:commands] is an array errors << "The parameter h[:commands] is not an array" unless h[:commands].is_a?(Array) # validate: the parameter h[:commands] has at least one element errors << "The parameter h[:commands] does not have at least one element" unless h[:commands].size > 0 # validate: each element of the array h[:commands] is a hash h[:commands].each do |c| errors += BlackStack::Deployer::CommandModule.descriptor_errors(c) end # h[:commands].each do |c| errors.uniq end |
Instance Method Details
#initialize(h) ⇒ Object
def self.descriptor_error(h)
185 186 187 188 189 190 191 192 193 |
# File 'lib/my-ruby-deployer.rb', line 185 def initialize(h) errors = BlackStack::Deployer::RoutineModule.descriptor_errors(h) raise "The node descriptor is not valid: #{errors.uniq.join(".\n")}" if errors.length > 0 self.name = h[:name] self.commands = [] h[:commands].each do |c| self.commands << Deployer::Command.new(c) end end |
#run(node, l = nil, params = {}) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/my-ruby-deployer.rb', line 205 def run(node, l=nil, params={}) l = BlackStack::DummyLogger.new(nil) if l.nil? l.logs "Running routine #{self.name.blue} on node #{node.name.blue}... " i = 0 self.commands.each do |c| i += 1 l.logs "Command #{i.to_s.blue}... " c.run(node, l, params) l.logf 'done'.green end l.logf 'done'.green end |
#to_hash ⇒ Object
195 196 197 198 199 200 201 202 203 |
# File 'lib/my-ruby-deployer.rb', line 195 def to_hash h = {} h[:name] = self.name h[:commands] = [] self.commands.each do |c| h[:commands] << c.to_hash end h end |