Class: Vana::Element::BaseElement

Inherits:
Object
  • Object
show all
Defined in:
lib/vana/element.rb

Overview

methods for every element

Direct Known Subclasses

Copy, Shell

Instance Method Summary collapse

Constructor Details

#initialize(hosts, *args) {|_self| ... } ⇒ BaseElement

Returns a new instance of BaseElement.

Yields:

  • (_self)

Yield Parameters:



8
9
10
11
12
13
14
15
# File 'lib/vana/element.rb', line 8

def initialize(hosts, *args)
  @hosts = hosts
  @element_opts = {}
  @opts = {}

  yield self if block_given?
  setup(*args)
end

Instance Method Details

#action(_host, *_args) ⇒ Object



21
22
23
# File 'lib/vana/element.rb', line 21

def action(_host, *_args)
  # nop
end

#execute(*args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/vana/element.rb', line 29

def execute(*args)
  puts "-- #{@element_opts[:name]}"
  @hosts.each do |host|
    output = action(host, *args)
    puts "#{host}: #{output.to_json}".colorize(output[:success] ? :light_green : :light_red)

    # TODO: need a better place to handle exceptions and keep going with the script
    # raise "Execution failed on '#{@element_opts[:name]}'" unless output[:success]
  end
end

#name=(name) ⇒ Object



25
26
27
# File 'lib/vana/element.rb', line 25

def name=(name)
  @element_opts[:name] = name
end

#setup(*_args) ⇒ Object



17
18
19
# File 'lib/vana/element.rb', line 17

def setup(*_args)
  # nop
end