Class: Puppet::FileServing::Base
- Defined in:
- lib/vendor/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.
Class Method Summary collapse
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.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vendor/puppet/file_serving/base.rb', line 28 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.
42 43 44 |
# File 'lib/vendor/puppet/file_serving/base.rb', line 42 def links @links end |
#path ⇒ Object
Set our base path.
51 52 53 |
# File 'lib/vendor/puppet/file_serving/base.rb', line 51 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.
59 60 61 |
# File 'lib/vendor/puppet/file_serving/base.rb', line 59 def relative_path @relative_path end |
#source ⇒ Object
This is for external consumers to store the source that was used to retrieve the metadata.
9 10 11 |
# File 'lib/vendor/puppet/file_serving/base.rb', line 9 def source @source end |
Class Method Details
.absolute?(path) ⇒ Boolean
85 86 87 |
# File 'lib/vendor/puppet/file_serving/base.rb', line 85 def self.absolute?(path) Puppet::Util.absolute_path?(path, :posix) or (Puppet.features.microsoft_windows? and Puppet::Util.absolute_path?(path, :windows)) end |
Instance Method Details
#exist? ⇒ Boolean
Does our file exist?
12 13 14 15 16 17 |
# File 'lib/vendor/puppet/file_serving/base.rb', line 12 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.
20 21 22 23 24 25 26 |
# File 'lib/vendor/puppet/file_serving/base.rb', line 20 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.
66 67 68 69 |
# File 'lib/vendor/puppet/file_serving/base.rb', line 66 def stat @stat_method ||= self.links == :manage ? :lstat : :stat File.send(@stat_method, full_path) end |
#to_pson_data_hash ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/vendor/puppet/file_serving/base.rb', line 71 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 |