Class: Puppet::FileServing::Base
- Defined in:
- lib/puppet/file_serving/base.rb
Overview
The base class for Content and Metadata; provides common functionality like the behaviour around links.
Instance Attribute Summary collapse
-
#links ⇒ Object
Determine how we deal with links.
-
#path ⇒ Object
Set our base path.
-
#relative_path ⇒ Object
Set a relative path; this is used for recursion, and sets the file’s path relative to the initial recursion point.
-
#source ⇒ Object
This is for external consumers to store the source that was used to retrieve the metadata.
Instance Method Summary collapse
-
#exist? ⇒ Boolean
Does our file exist?.
-
#full_path(dummy_argument = :work_arround_for_ruby_GC_bug) ⇒ Object
Return the full path to our file.
-
#initialize(path, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#stat ⇒ Object
Stat our file, using the appropriate link-sensitive method.
- #to_pson_data_hash ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ Base
Returns a new instance of Base.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/puppet/file_serving/base.rb', line 31 def initialize(path, = {}) self.path = path @links = :manage .each do |param, value| begin send param.to_s + "=", value rescue NoMethodError raise ArgumentError, "Invalid option #{param} for #{self.class}" end end end |
Instance Attribute Details
#links ⇒ Object
Determine how we deal with links.
45 46 47 |
# File 'lib/puppet/file_serving/base.rb', line 45 def links @links end |
#path ⇒ Object
Set our base path.
54 55 56 |
# File 'lib/puppet/file_serving/base.rb', line 54 def path @path end |
#relative_path ⇒ Object
Set a relative path; this is used for recursion, and sets the file’s path relative to the initial recursion point.
62 63 64 |
# File 'lib/puppet/file_serving/base.rb', line 62 def relative_path @relative_path end |
#source ⇒ Object
This is for external consumers to store the source that was used to retrieve the metadata.
12 13 14 |
# File 'lib/puppet/file_serving/base.rb', line 12 def source @source end |
Instance Method Details
#exist? ⇒ Boolean
Does our file exist?
15 16 17 18 19 20 |
# File 'lib/puppet/file_serving/base.rb', line 15 def exist? stat return true rescue => detail return false end |
#full_path(dummy_argument = :work_arround_for_ruby_GC_bug) ⇒ Object
Return the full path to our file. Fails if there’s no path set.
23 24 25 26 27 28 29 |
# File 'lib/puppet/file_serving/base.rb', line 23 def full_path(dummy_argument=:work_arround_for_ruby_GC_bug) (if relative_path.nil? or relative_path == "" or relative_path == "." path else File.join(path, relative_path) end).gsub(%r{/+}, "/") end |
#stat ⇒ Object
Stat our file, using the appropriate link-sensitive method.
69 70 71 72 |
# File 'lib/puppet/file_serving/base.rb', line 69 def stat @stat_method ||= self.links == :manage ? :lstat : :stat File.send(@stat_method, full_path) end |
#to_pson_data_hash ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/puppet/file_serving/base.rb', line 74 def to_pson_data_hash { # No 'document_type' since we don't send these bare 'data' => { 'path' => @path, 'relative_path' => @relative_path, 'links' => @links }, 'metadata' => { 'api_version' => 1 } } end |