Class: PoolParty::Resources::File

Inherits:
Resource show all
Defined in:
lib/poolparty/resources/file.rb

Overview

File

The file resource is used to describe a file that should be present on all of the instances.

Usage

has_file(:name => '...') do
  # More options. 
  # This block is optional
end

Options

  • name Describe the location of the file with the name

  • mode Describe the mode of the file (default: 644)

  • owner The owner of the file (default: poolparty user)

  • content The contents of the file

  • source Used to describe a file that is hosted on the master instance.

  • template The file contents are described with the template. The location given must be readable

To write a file to the template directory, use:

copy_template_to_storage_directory(filepath)

Example

has_file(:name => '/etc/motd', :content => 'Hey and welcome to your node today!')

Instance Attribute Summary

Attributes inherited from PoolPartyBaseClass

#init_opts, #ordered_resources

Instance Method Summary collapse

Methods inherited from Resource

#after_load, available_resources, #before_load, #class_name_sym, #class_type_name, #cloud, #duplicatable?, #get_modified_options, inherited, #initialize, #is_a_resource?, #is_in_plugin?, #resource?, #resource_name, #services

Methods included from SearchablePaths

included

Methods included from PoolParty::ResourcingDsl

#client_template_exists?, #client_templates_directory_exists?, #ensures, #get_client_or_gem_template, #is_absent, #is_present

Methods included from DependencyResolverResourceExtensions

#to_properties_hash

Methods inherited from PoolPartyBaseClass

add_has_and_does_not_have_methods_for, #add_resource, add_resource_lookup_method, #add_service, #add_to_parent_if_parent_exists_and_is_a_service, #get_local_resource, #get_name_from_options_and_extra_options, #get_resource, #handle_option_values, #in_local_resources?, #initialize, #inspect, #is_a_resource?, #is_plugin?, #plugin_store, #resource, #resources, #run_in_context, #run_with_callbacks, #search_in_known_locations, #store_in_local_resources, #to_hash, #to_json

Methods included from DependencyResolverCloudExtensions

#to_properties_hash

Constructor Details

This class inherits a constructor from PoolParty::Resources::Resource

Instance Method Details

#absentObject



53
54
55
# File 'lib/poolparty/resources/file.rb', line 53

def absent
  :delete
end

#after_createObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/poolparty/resources/file.rb', line 57

def after_create
  run_render = dsl_options.include?(:render_as) ? dsl_options.delete(:render_as) : false
  
  if dsl_options[:template]
    filename = find_file(dsl_options.delete(:template))
    file = ::File.basename( filename )
    raise TemplateNotFound.new("no template given") unless file

    template_opts = (parent ? dsl_options.merge(parent.dsl_options) : dsl_options)
    dsl_options.merge!(:content => run_render ? Template.compile_file(filename, template_opts.merge(:renderer => run_render)).gsub("\"", "\"") : open(filename).read)
  end
  
  if dsl_options.include?(:content)
    cont = dsl_options.delete(:content)
    template_opts = (parent ? dsl_options.merge(parent.dsl_options) : dsl_options).merge(:renderer => run_render)
    dsl_options.merge!(:content => run_render ? Template.compile_string(cont, template_opts) : cont)
  end
end

#loaded(o = {}, &block) ⇒ Object



45
46
47
# File 'lib/poolparty/resources/file.rb', line 45

def loaded(o={}, &block)
  has_directory ::File.dirname(name)
end

#presentObject



49
50
51
# File 'lib/poolparty/resources/file.rb', line 49

def present
  :create
end

#variable(k, v) ⇒ Object

def method_missing m, *a, &block

super rescue ::File.send(m, *a, &block)

end



80
81
82
# File 'lib/poolparty/resources/file.rb', line 80

def variable(k,v)
  set_default_options(k => v)
end