Class: Skyrocket::AssetFactory
- Inherits:
-
Object
- Object
- Skyrocket::AssetFactory
- Defined in:
- lib/skyrocket/asset_factory.rb
Instance Attribute Summary collapse
-
#asset_dirs ⇒ Object
readonly
Returns the value of attribute asset_dirs.
-
#lib_dirs ⇒ Object
readonly
Returns the value of attribute lib_dirs.
-
#output_dir ⇒ Object
readonly
Returns the value of attribute output_dir.
Instance Method Summary collapse
- #build_asset(filepath) ⇒ Object
- #from_name(name) ⇒ Object
-
#initialize(asset_dirs, lib_dirs = [], output_dir) ⇒ AssetFactory
constructor
A new instance of AssetFactory.
- #name_exist?(name) ⇒ Boolean
Constructor Details
#initialize(asset_dirs, lib_dirs = [], output_dir) ⇒ AssetFactory
Returns a new instance of AssetFactory.
4 5 6 7 8 9 |
# File 'lib/skyrocket/asset_factory.rb', line 4 def initialize(asset_dirs, lib_dirs = [], output_dir) @asset_dirs = asset_dirs @lib_dirs = lib_dirs @output_dir = output_dir @pf = ProcessorFactory.new end |
Instance Attribute Details
#asset_dirs ⇒ Object (readonly)
Returns the value of attribute asset_dirs.
3 4 5 |
# File 'lib/skyrocket/asset_factory.rb', line 3 def asset_dirs @asset_dirs end |
#lib_dirs ⇒ Object (readonly)
Returns the value of attribute lib_dirs.
3 4 5 |
# File 'lib/skyrocket/asset_factory.rb', line 3 def lib_dirs @lib_dirs end |
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
3 4 5 |
# File 'lib/skyrocket/asset_factory.rb', line 3 def output_dir @output_dir end |
Instance Method Details
#build_asset(filepath) ⇒ Object
11 12 13 14 |
# File 'lib/skyrocket/asset_factory.rb', line 11 def build_asset(filepath) dir, file = parts(filepath) Asset.new(dir, file, @output_dir, @pf.processor(file)) end |
#from_name(name) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/skyrocket/asset_factory.rb', line 16 def from_name(name) found = dir_search(name, @asset_dirs + @lib_dirs) if found.length > 0 found.each do |file| if @pf.post_process_name(file) =~ /#{name}$/ || file =~ /#{name}$/ dir, file = parts(file) return Asset.new(dir, file, @output_dir, @pf.processor(file)) end end end raise AssetNotFoundError.new("Asset not found '#{name}'") end |
#name_exist?(name) ⇒ Boolean
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/skyrocket/asset_factory.rb', line 30 def name_exist?(name) found = dir_search(name, @asset_dirs + @lib_dirs) if found.length > 0 found.each do |file| if @pf.post_process_name(file) =~ /#{name}$/ || file =~ /#{name}$/ return true end end end return false end |