Class: PoolParty::Resources::File

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

Instance Attribute Summary

Attributes inherited from Resource

#poststring, #prestring

Instance Method Summary collapse

Methods inherited from Resource

available_resources, #class_name_sym, #class_type_name, #cloud, #custom_function, custom_function, custom_functions, custom_functions_to_string, #disallowed_options, #duplicatable?, #get_modified_options, inherited, #initialize, #is_a_resource?, #is_in_plugin?, #key, #name, #resource?, #resource_name, #services

Methods included from PoolParty::ResourcingDsl

#cancel, #cancelled?, #client_template_exists?, #client_templates_directory_exists?, #ensures, #get_client_or_gem_template, #ifnot, #is_absent, #is_present, #on_change, #printed, #printed?, #render_template, #requires

Methods included from DependencyResolverResourceExtensions

#to_properties_hash

Methods inherited from PoolPartyBaseClass

add_has_and_does_not_have_methods_for, #add_resource, #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, #is_a_resource?, #is_plugin?, #ordered_resources, #plugin_store, #resource, #resources, #run_in_context, #services, #store_in_local_resources

Methods included from DependencyResolverCloudExtensions

#to_properties_hash

Constructor Details

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *a, &block) ⇒ Object



38
39
40
# File 'lib/poolparty/resources/file.rb', line 38

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

Instance Method Details

#absentObject



14
15
16
# File 'lib/poolparty/resources/file.rb', line 14

def absent
  :delete
end

#after_createObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/poolparty/resources/file.rb', line 18

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

    template_opts = (parent ? options.merge(parent.options) : options)
    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 ? options.merge(parent.options) : options).merge(:renderer => run_render)
    options.merge!(:content => run_render ? Template.compile_string(cont, template_opts) : cont)
  end
end

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



6
7
8
# File 'lib/poolparty/resources/file.rb', line 6

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

#presentObject



10
11
12
# File 'lib/poolparty/resources/file.rb', line 10

def present
  :create
end