Class: Coyote::Bundles::Base
- Inherits:
-
Object
- Object
- Coyote::Bundles::Base
- Defined in:
- lib/coyote/bundles/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#assets ⇒ Object
readonly
Returns the value of attribute assets.
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Class Method Summary collapse
Instance Method Summary collapse
- #add(input) ⇒ Object
- #add_dependencies(asset) ⇒ Object
- #add_directory(dir_path) ⇒ Object
- #add_file(path) ⇒ Object
- #compress! ⇒ Object
- #empty! ⇒ Object
- #files ⇒ Object
-
#initialize(target) ⇒ Base
constructor
A new instance of Base.
- #manifest ⇒ Object
- #path_is_directory_or_kosher_file?(path) ⇒ Boolean
- #rebuild! ⇒ Object
- #reset! ⇒ Object
- #save! ⇒ Object
- #update!(changed_files = []) ⇒ Object
Constructor Details
#initialize(target) ⇒ Base
Returns a new instance of Base.
17 18 19 20 |
# File 'lib/coyote/bundles/base.rb', line 17 def initialize(target) @target = target empty! end |
Instance Attribute Details
#assets ⇒ Object (readonly)
Returns the value of attribute assets.
15 16 17 |
# File 'lib/coyote/bundles/base.rb', line 15 def assets @assets end |
#contents ⇒ Object
Returns the value of attribute contents.
14 15 16 |
# File 'lib/coyote/bundles/base.rb', line 14 def contents @contents end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
15 16 17 |
# File 'lib/coyote/bundles/base.rb', line 15 def target @target end |
Class Method Details
.filetypes(*args) ⇒ Object
7 8 9 |
# File 'lib/coyote/bundles/base.rb', line 7 def filetypes(*args) @filetypes ||= args.map { |arg| arg.to_s.gsub('.','') } || [] end |
Instance Method Details
#add(input) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/coyote/bundles/base.rb', line 22 def add(input) path = File.(input) if File.directory? path add_directory path elsif File.exists? path add_file path else notify "Could not find #{path}", :failure end end |
#add_dependencies(asset) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/coyote/bundles/base.rb', line 53 def add_dependencies(asset) asset.dependencies.each do |dependency_path| relative_directory = File.dirname asset.relative_path add File.join relative_directory, dependency_path end end |
#add_directory(dir_path) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/coyote/bundles/base.rb', line 44 def add_directory(dir_path) Dir.foreach(dir_path) do |path| next if path == '.' or path == '..' path = "#{dir_path}/#{path}" add path if path_is_directory_or_kosher_file?(path) end end |
#add_file(path) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/coyote/bundles/base.rb', line 34 def add_file(path) return false unless path_is_directory_or_kosher_file?(path) asset = Coyote::Asset.new(path) @files.delete(path) @files << path @assets[path] = asset add_dependencies(asset) end |
#compress! ⇒ Object
118 119 120 |
# File 'lib/coyote/bundles/base.rb', line 118 def compress! self end |
#empty! ⇒ Object
67 68 69 70 |
# File 'lib/coyote/bundles/base.rb', line 67 def empty! @assets = {} @files = [] end |
#files ⇒ Object
73 74 75 |
# File 'lib/coyote/bundles/base.rb', line 73 def files @files ||= [] end |
#manifest ⇒ Object
93 94 95 |
# File 'lib/coyote/bundles/base.rb', line 93 def manifest files.reverse.map { |path| "+ #{path}" }.join("\n") end |
#path_is_directory_or_kosher_file?(path) ⇒ Boolean
61 62 63 64 |
# File 'lib/coyote/bundles/base.rb', line 61 def path_is_directory_or_kosher_file?(path) return true if File.directory?(path) self.class.filetypes.include? File.extname(path).gsub('.','') end |
#rebuild! ⇒ Object
103 104 105 106 107 108 |
# File 'lib/coyote/bundles/base.rb', line 103 def rebuild! notify "Dependencies have changed. Refreshing bundle and recompiling...", :timestamp, :warning entry_point = files.first empty! add entry_point end |
#reset! ⇒ Object
98 99 100 |
# File 'lib/coyote/bundles/base.rb', line 98 def reset! @contents = nil end |
#save! ⇒ Object
111 112 113 114 115 |
# File 'lib/coyote/bundles/base.rb', line 111 def save! File.open target, 'w+' do |file| file.write contents end end |
#update!(changed_files = []) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/coyote/bundles/base.rb', line 83 def update!(changed_files=[]) reset! changed_files.each do |path| asset = assets[path] asset.update! rebuild! and return if asset.dependencies_have_changed? end end |