Class: Rack::Bundle::FileSystemStore
- Inherits:
-
Object
- Object
- Rack::Bundle::FileSystemStore
- Defined in:
- lib/rack/bundle/file_system_store.rb
Instance Attribute Summary collapse
-
#bundles ⇒ Object
Returns the value of attribute bundles.
-
#dir ⇒ Object
Returns the value of attribute dir.
Instance Method Summary collapse
- #add(bundle) ⇒ Object
- #find_bundle_by_hash(hash) ⇒ Object
- #has_bundle?(bundle) ⇒ Boolean
-
#initialize(dir = Dir.tmpdir) ⇒ FileSystemStore
constructor
A new instance of FileSystemStore.
Constructor Details
#initialize(dir = Dir.tmpdir) ⇒ FileSystemStore
Returns a new instance of FileSystemStore.
6 7 8 9 |
# File 'lib/rack/bundle/file_system_store.rb', line 6 def initialize dir = Dir.tmpdir @dir = dir clear_existing_bundles end |
Instance Attribute Details
#bundles ⇒ Object
Returns the value of attribute bundles.
4 5 6 |
# File 'lib/rack/bundle/file_system_store.rb', line 4 def bundles @bundles end |
#dir ⇒ Object
Returns the value of attribute dir.
4 5 6 |
# File 'lib/rack/bundle/file_system_store.rb', line 4 def dir @dir end |
Instance Method Details
#add(bundle) ⇒ Object
22 23 24 25 26 |
# File 'lib/rack/bundle/file_system_store.rb', line 22 def add bundle File.open("#{dir}/rack-bundle-#{bundle.hash}.#{bundle.extension}", 'w') do |file| file << bundle.contents end end |
#find_bundle_by_hash(hash) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/rack/bundle/file_system_store.rb', line 11 def find_bundle_by_hash hash found = Dir["#{dir}/rack-bundle-#{hash}.*"] return nil unless found.any? type, contents = File.extname(found.first).sub(/^./, ''), File.read(File.join(dir, File.basename(found.first))) type == 'js' ? Rack::Bundle::JSBundle.new_from_contents(contents) : Rack::Bundle::CSSBundle.new_from_contents(contents) end |
#has_bundle?(bundle) ⇒ Boolean
18 19 20 |
# File 'lib/rack/bundle/file_system_store.rb', line 18 def has_bundle? bundle File.exists? "#{dir}/rack-bundle-#{bundle.hash}.#{bundle.extension}" end |