Class: Boom::Storage::Base
- Inherits:
-
Object
- Object
- Boom::Storage::Base
- Defined in:
- lib/kaboom/storage/base.rb
Instance Attribute Summary collapse
-
#lists ⇒ Object
Public: the list of Lists in your JSON data, sorted by number of items descending.
Instance Method Summary collapse
-
#bootstrap ⇒ Object
run bootstrap tasks for the storage.
- #handle(error, message) ⇒ Object
-
#initialize ⇒ Base
constructor
Public: initializes a Storage instance by loading in your persisted data from adapter.
-
#item_exists?(name) ⇒ Boolean
Public: tests whether a named Item exists.
-
#items ⇒ Object
Public: all Items in storage.
-
#list_exists?(name) ⇒ Boolean
Public: tests whether a named List exists.
-
#populate ⇒ Object
populate the in-memory store with all the lists and items.
-
#save ⇒ Object
save the data.
-
#to_hash ⇒ Object
Public: creates a Hash of the representation of the in-memory data structure.
Constructor Details
Instance Attribute Details
#lists ⇒ Object
Public: the list of Lists in your JSON data, sorted by number of items descending.
Returns an Array of List objects.
43 44 45 |
# File 'lib/kaboom/storage/base.rb', line 43 def lists @lists.sort_by { |list| -list.items.size } end |
Instance Method Details
#bootstrap ⇒ Object
run bootstrap tasks for the storage
22 |
# File 'lib/kaboom/storage/base.rb', line 22 def bootstrap ; end |
#handle(error, message) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/kaboom/storage/base.rb', line 81 def handle error, case error when NoMethodError output cyan config_text when NameError output end end |
#item_exists?(name) ⇒ Boolean
Public: tests whether a named Item exists.
name - the String name of an Item
Returns true if found, false if not.
68 69 70 |
# File 'lib/kaboom/storage/base.rb', line 68 def item_exists?(name) items.detect { |item| item.name == name } end |
#items ⇒ Object
Public: all Items in storage.
Returns an Array of all Items.
59 60 61 |
# File 'lib/kaboom/storage/base.rb', line 59 def items @lists.collect(&:items).flatten end |
#list_exists?(name) ⇒ Boolean
Public: tests whether a named List exists.
name - the String name of a List
Returns true if found, false if not.
52 53 54 |
# File 'lib/kaboom/storage/base.rb', line 52 def list_exists?(name) @lists.detect { |list| list.name == name } end |
#populate ⇒ Object
populate the in-memory store with all the lists and items
25 |
# File 'lib/kaboom/storage/base.rb', line 25 def populate ; end |
#save ⇒ Object
save the data
28 |
# File 'lib/kaboom/storage/base.rb', line 28 def save ; end |
#to_hash ⇒ Object
Public: creates a Hash of the representation of the in-memory data structure. This percolates down to Items by calling to_hash on the List, which in tern calls to_hash on individual Items.
Returns a Hash of the entire data set.
77 78 79 |
# File 'lib/kaboom/storage/base.rb', line 77 def to_hash { :lists => lists.collect(&:to_hash) } end |