Class: Rack::Bundle::DatabaseStore
- Inherits:
-
Object
- Object
- Rack::Bundle::DatabaseStore
- Defined in:
- lib/rack/bundle/database_store.rb
Instance Attribute Summary collapse
-
#bundles ⇒ Object
Returns the value of attribute bundles.
-
#db ⇒ Object
Returns the value of attribute db.
Instance Method Summary collapse
- #add(bundle) ⇒ Object
- #find_bundle_by_hash(hash) ⇒ Object
- #has_bundle?(bundle) ⇒ Boolean
-
#initialize(url = ENV['DATABASE_URL']) ⇒ DatabaseStore
constructor
A new instance of DatabaseStore.
Constructor Details
#initialize(url = ENV['DATABASE_URL']) ⇒ DatabaseStore
Returns a new instance of DatabaseStore.
6 7 8 9 |
# File 'lib/rack/bundle/database_store.rb', line 6 def initialize url = ENV['DATABASE_URL'] @db = Sequel.connect(url) create_table! end |
Instance Attribute Details
#bundles ⇒ Object
Returns the value of attribute bundles.
4 5 6 |
# File 'lib/rack/bundle/database_store.rb', line 4 def bundles @bundles end |
#db ⇒ Object
Returns the value of attribute db.
4 5 6 |
# File 'lib/rack/bundle/database_store.rb', line 4 def db @db end |
Instance Method Details
#add(bundle) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/rack/bundle/database_store.rb', line 18 def add bundle return false if has_bundle? bundle @db[:rack_bundle].insert :contents => bundle.contents, :hash => bundle.hash, :type => bundle.is_a?(Rack::Bundle::JSBundle) ? 'js' : 'css' end |
#find_bundle_by_hash(hash) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/rack/bundle/database_store.rb', line 11 def find_bundle_by_hash hash return nil unless result = @db[:rack_bundle].where(:hash => hash).first result[:type] == 'js' ? Rack::Bundle::JSBundle.new_from_contents(result[:contents]) : Rack::Bundle::CSSBundle.new_from_contents(result[:contents]) end |
#has_bundle?(bundle) ⇒ Boolean
25 26 27 |
# File 'lib/rack/bundle/database_store.rb', line 25 def has_bundle? bundle not find_bundle_by_hash(bundle.hash).nil? end |