Class: Coyote::Asset
- Inherits:
-
Object
- Object
- Coyote::Asset
- Defined in:
- lib/coyote/asset.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#absolute_directory ⇒ Object
readonly
Returns the value of attribute absolute_directory.
-
#absolute_path ⇒ Object
readonly
Returns the value of attribute absolute_path.
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#relative_directory ⇒ Object
readonly
Returns the value of attribute relative_directory.
-
#relative_path ⇒ Object
readonly
Returns the value of attribute relative_path.
Class Method Summary collapse
-
.select_and_init(path) ⇒ Object
Determine the type of file based on the file extension and return an instance of the proper asset class.
Instance Method Summary collapse
-
#initialize(relative_path) ⇒ Asset
constructor
A new instance of Asset.
- #update! ⇒ Object
Constructor Details
#initialize(relative_path) ⇒ Asset
Returns a new instance of Asset.
21 22 23 24 25 26 27 |
# File 'lib/coyote/asset.rb', line 21 def initialize(relative_path) @relative_path = File.(relative_path).gsub("#{Dir.pwd}/", '') @absolute_path = File.(@relative_path) @relative_directory = File.dirname(@relative_path) @absolute_directory = File.("#{Dir.pwd}/#{@relative_directory}") update! end |
Instance Attribute Details
#absolute_directory ⇒ Object (readonly)
Returns the value of attribute absolute_directory.
7 8 9 |
# File 'lib/coyote/asset.rb', line 7 def absolute_directory @absolute_directory end |
#absolute_path ⇒ Object (readonly)
Returns the value of attribute absolute_path.
7 8 9 |
# File 'lib/coyote/asset.rb', line 7 def absolute_path @absolute_path end |
#contents ⇒ Object
Returns the value of attribute contents.
8 9 10 |
# File 'lib/coyote/asset.rb', line 8 def contents @contents end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
7 8 9 |
# File 'lib/coyote/asset.rb', line 7 def dependencies @dependencies end |
#relative_directory ⇒ Object (readonly)
Returns the value of attribute relative_directory.
7 8 9 |
# File 'lib/coyote/asset.rb', line 7 def relative_directory @relative_directory end |
#relative_path ⇒ Object (readonly)
Returns the value of attribute relative_path.
7 8 9 |
# File 'lib/coyote/asset.rb', line 7 def relative_path @relative_path end |
Class Method Details
.select_and_init(path) ⇒ Object
Determine the type of file based on the file extension and return an instance of the proper asset class
12 13 14 15 16 17 18 |
# File 'lib/coyote/asset.rb', line 12 def self.select_and_init(path) case File.extname(path) when /\.js/i ; JavaScript.new(path) when /\.coffee/i ; CoffeeScript.new(path) else ; self.new(path) end end |
Instance Method Details
#update! ⇒ Object
30 31 32 33 |
# File 'lib/coyote/asset.rb', line 30 def update! @contents = File.exists?(@absolute_path) ? File.open(@absolute_path, 'r').read : "" find_dependencies end |