Class: Bricolage::FileResource
- Defined in:
- lib/bricolage/resource.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #content ⇒ Object
- #hash ⇒ Object
-
#initialize(path, name = nil) ⇒ FileResource
constructor
A new instance of FileResource.
- #inspect ⇒ Object
- #name ⇒ Object
Methods inherited from Resource
Constructor Details
#initialize(path, name = nil) ⇒ FileResource
Returns a new instance of FileResource.
12 13 14 15 |
# File 'lib/bricolage/resource.rb', line 12 def initialize(path, name = nil) @path = path @name = name end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
17 18 19 |
# File 'lib/bricolage/resource.rb', line 17 def path @path end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
33 34 35 36 |
# File 'lib/bricolage/resource.rb', line 33 def ==(other) return false unless other.kind_of?(FileResource) @path == other.path end |
#content ⇒ Object
23 24 25 26 27 |
# File 'lib/bricolage/resource.rb', line 23 def content @content ||= File.read(@path) rescue SystemCallError => err raise ParameterError, "could not open a file: #{@path}: #{err.message}" end |
#hash ⇒ Object
40 41 42 |
# File 'lib/bricolage/resource.rb', line 40 def hash @path.hash end |
#inspect ⇒ Object
29 30 31 |
# File 'lib/bricolage/resource.rb', line 29 def inspect "\#<#{self.class} #{@path}>" end |
#name ⇒ Object
19 20 21 |
# File 'lib/bricolage/resource.rb', line 19 def name @name || @path end |