Class: Bricolage::FileResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/bricolage/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#each_line

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

#pathObject (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

#contentObject



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

#hashObject



40
41
42
# File 'lib/bricolage/resource.rb', line 40

def hash
  @path.hash
end

#inspectObject



29
30
31
# File 'lib/bricolage/resource.rb', line 29

def inspect
  "\#<#{self.class} #{@path}>"
end

#nameObject



19
20
21
# File 'lib/bricolage/resource.rb', line 19

def name
  @name || @path
end