Class: Coyote::Assets::Base

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

Direct Known Subclasses

CoffeeScript, JavaScript, Less

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Base

Returns a new instance of Base.



16
17
18
19
20
# File 'lib/coyote/assets/base.rb', line 16

def initialize(path)
  @path = File.expand_path path
  @relative_path = @path.gsub("#{Dir.pwd}/", '')
  update!
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



13
14
15
# File 'lib/coyote/assets/base.rb', line 13

def contents
  @contents
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



14
15
16
# File 'lib/coyote/assets/base.rb', line 14

def dependencies
  @dependencies
end

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/coyote/assets/base.rb', line 14

def path
  @path
end

#relative_pathObject (readonly)

Returns the value of attribute relative_path.



14
15
16
# File 'lib/coyote/assets/base.rb', line 14

def relative_path
  @relative_path
end

Class Method Details

.require_pattern(pattern = nil) ⇒ Object



5
6
7
# File 'lib/coyote/assets/base.rb', line 5

def require_pattern(pattern = nil)
  @require_pattern ||= pattern || Regexp.new(/\/\/=\s*require\s*(.*)$/i)
end

Instance Method Details

#dependencies_have_changed?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/coyote/assets/base.rb', line 28

def dependencies_have_changed?
  @last_dependencies != @dependencies
end

#find_dependenciesObject



22
23
24
25
26
# File 'lib/coyote/assets/base.rb', line 22

def find_dependencies
  @last_dependencies = @dependencies
  matches = self.contents.scan self.class.require_pattern
  @dependencies = matches.reverse.map { |match| match.last.strip }
end

#update!Object



32
33
34
35
# File 'lib/coyote/assets/base.rb', line 32

def update!
  self.contents = IO.read(@path)
  find_dependencies
end