Class: Coyote::Assets::Base
- Inherits:
-
Object
- Object
- Coyote::Assets::Base
- Defined in:
- lib/coyote/assets/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#relative_path ⇒ Object
readonly
Returns the value of attribute relative_path.
Class Method Summary collapse
Instance Method Summary collapse
- #dependencies_have_changed? ⇒ Boolean
- #find_dependencies ⇒ Object
-
#initialize(path) ⇒ Base
constructor
A new instance of Base.
- #update! ⇒ Object
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. path @relative_path = @path.gsub("#{Dir.pwd}/", '') update! end |
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
13 14 15 |
# File 'lib/coyote/assets/base.rb', line 13 def contents @contents end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
14 15 16 |
# File 'lib/coyote/assets/base.rb', line 14 def dependencies @dependencies end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/coyote/assets/base.rb', line 14 def path @path end |
#relative_path ⇒ Object (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
28 29 30 |
# File 'lib/coyote/assets/base.rb', line 28 def dependencies_have_changed? @last_dependencies != @dependencies end |
#find_dependencies ⇒ Object
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 |