Class: PoolParty::Resources::FileResource

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

Direct Known Subclasses

RemoteFile

Instance Attribute Summary

Attributes inherited from PoolParty::Resource

#exists, #graph_index, #meta_not_if, #meta_notifies, #meta_only_if, #meta_subscribes

Attributes inherited from Base

#base_name, #init_opts

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PoolParty::Resource

#after_compile, #after_loaded_requires_parent, #before_compile, #case_of, #cloud, #compile, define_resource, define_resource_methods, defined, defined_resources, #does_not_exist!, #exists!, #has_method_name, inherited, #initialize, is_base_resource_class?, method_defined!, method_defined?, #not_if, #notifies, #only_if, #pool, #print_variable, #requires, #subscribes

Methods inherited from Base

#add_ordered_resources_to_result, #all_resources, #before_load, #clouds_dot_rb_dir, clouds_dot_rb_dir, #clouds_dot_rb_file, clouds_dot_rb_file, #compile_opts, #create_graph, #dependencies, #get_resource, #has_searchable_paths, #initialize, #method_missing, #ordered_resources, #output_resources_graph, #resources, #resources_graph, #resources_with_dependencies, #resources_without_dependencies, #run_in_context, #run_with_callbacks, #to_s, #valid?, #validations

Methods included from Delayed

included

Methods included from Callbacks

included

Methods included from SearchablePaths

included

Constructor Details

This class inherits a constructor from PoolParty::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PoolParty::Base

Class Method Details

.has_method_nameObject



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

def self.has_method_name
  "file"
end

Instance Method Details

#after_loadedObject



42
43
44
# File 'lib/poolparty/resources/file.rb', line 42

def after_loaded
  requires get_user(owner) if owner && owner != "root"
end

#pathObject

A convenience helper to point to the path of the file



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

def path
  name
end


50
51
52
53
54
55
56
57
58
59
60
# File 'lib/poolparty/resources/file.rb', line 50

def print_to_chef
  <<-EOE
template "<%= name %>" do
  source "<%= name %>.erb"
  action :<%= exists? ? :create : :delete %>
  backup <%= backup %>
  mode <%= print_variable(mode) %>
  owner <%= print_variable(owner) %>
end
  EOE
end

#template(*arg) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/poolparty/resources/file.rb', line 62

def template(*arg)
  if arg.empty?
    @template
  else
    file = arg.first
    @template = if File.file?(b = File.expand_path(file))
      b
    elsif File.file?(d = File.expand_path(File.join(clouds_dot_rb_dir, file)))
      d
    elsif f = search_in_known_locations(file)
      f
    else
      raise PoolParty::PoolPartyError.create("TemplateNotFound", "The template #{file} could not be found when creating the file #{name}. Please check that it exists")
    end
  end
end