Class: Coyote::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/coyote/asset.rb

Direct Known Subclasses

CoffeeScript, JavaScript

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.expand_path(relative_path).gsub("#{Dir.pwd}/", '')
  @absolute_path      = File.expand_path(@relative_path)
  @relative_directory = File.dirname(@relative_path)
  @absolute_directory = File.expand_path("#{Dir.pwd}/#{@relative_directory}")
  update!
end

Instance Attribute Details

#absolute_directoryObject (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_pathObject (readonly)

Returns the value of attribute absolute_path.



7
8
9
# File 'lib/coyote/asset.rb', line 7

def absolute_path
  @absolute_path
end

#contentsObject

Returns the value of attribute contents.



8
9
10
# File 'lib/coyote/asset.rb', line 8

def contents
  @contents
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



7
8
9
# File 'lib/coyote/asset.rb', line 7

def dependencies
  @dependencies
end

#relative_directoryObject (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_pathObject (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