class Topo::Provision::ResourceGenerator

Attributes

name[R]
resource_attributes[R]
resource_type[R]
undeploy_action[R]

Public Class Methods

new(data) click to toggle source
# File lib/topo/provision/generators/resource.rb, line 34
def initialize(data)
  @resource_type||= "resource"  # define in each class
  @template_base_name = @resource_type
  @undeploy_action = "destroy"
  @resource_attributes = {}  # define in each class
  @name = data['name']
  provisioning = data['provisioning']
  %w[ driver chef_server].each do |key|
    @resource_attributes[key] = provisioning[key] if provisioning && provisioning.key?(key)
  end
end

Public Instance Methods

default_action(action) click to toggle source
# File lib/topo/provision/generators/resource.rb, line 62
def default_action(action)
end
default_resource_template(action) click to toggle source
# File lib/topo/provision/generators/resource.rb, line 69
def default_resource_template(action)
  default = "resource_#{action}"
  if @@templates[default] == nil
    path = File.join(File.expand_path("../templates", __FILE__), "#{default}.erb")
    @@templates[default] = ERB.new(File.new(path).read, nil, '>')
  end        
  @@templates[default]
end
deploy() click to toggle source
# File lib/topo/provision/generators/resource.rb, line 54
def deploy()
  puts(template("deploy").result(binding))
end
do_action(action) click to toggle source
# File lib/topo/provision/generators/resource.rb, line 46
def do_action(action)
  if (self.respond_to? action)
    self.send(action) 
  else
    self.send("default_action", action) 
  end
end
template(action) click to toggle source
# File lib/topo/provision/generators/resource.rb, line 79
def template(action)
 name = "#{@template_base_name}_#{action}"
 if (@@templates[name] == nil)
    path = File.join(template_root_dir, "#{name}.erb")
    @@templates[name] = File.exists?(path) ? ERB.new(File.new(path).read, nil, '>') :
      default_resource_template(action)       
  end
  @@templates[name]
end
template_root_dir() click to toggle source
# File lib/topo/provision/generators/resource.rb, line 65
def template_root_dir
  File.expand_path("../templates", __FILE__)
end
undeploy() click to toggle source
# File lib/topo/provision/generators/resource.rb, line 58
def undeploy()
  puts(template("undeploy").result(binding))
end