Class: Alexandria::LibraryCollection
- Inherits:
-
Object
- Object
- Alexandria::LibraryCollection
- Includes:
- Observable, Singleton
- Defined in:
- lib/alexandria/library_collection.rb
Constant Summary collapse
- LIBRARY_ADDED =
1
- LIBRARY_REMOVED =
2
Instance Attribute Summary collapse
-
#all_libraries ⇒ Object
readonly
Returns the value of attribute all_libraries.
-
#deleted_books ⇒ Object
readonly
Returns the value of attribute deleted_books.
-
#library_store ⇒ Object
Returns the value of attribute library_store.
-
#ruined_books ⇒ Object
readonly
Returns the value of attribute ruined_books.
Instance Method Summary collapse
- #add_library(library) ⇒ Object
- #all_regular_libraries ⇒ Object
- #all_smart_libraries ⇒ Object
- #really_delete_deleted_libraries ⇒ Object
- #really_save_all_books ⇒ Object
- #reload ⇒ Object
- #remove_library(library) ⇒ Object
Instance Attribute Details
#all_libraries ⇒ Object (readonly)
Returns the value of attribute all_libraries.
12 13 14 |
# File 'lib/alexandria/library_collection.rb', line 12 def all_libraries @all_libraries end |
#deleted_books ⇒ Object (readonly)
Returns the value of attribute deleted_books.
12 13 14 |
# File 'lib/alexandria/library_collection.rb', line 12 def deleted_books @deleted_books end |
#library_store ⇒ Object
Returns the value of attribute library_store.
13 14 15 |
# File 'lib/alexandria/library_collection.rb', line 13 def library_store @library_store end |
#ruined_books ⇒ Object (readonly)
Returns the value of attribute ruined_books.
12 13 14 |
# File 'lib/alexandria/library_collection.rb', line 12 def ruined_books @ruined_books end |
Instance Method Details
#add_library(library) ⇒ Object
46 47 48 49 |
# File 'lib/alexandria/library_collection.rb', line 46 def add_library(library) @all_libraries << library notify(LIBRARY_ADDED, library) end |
#all_regular_libraries ⇒ Object
35 36 37 |
# File 'lib/alexandria/library_collection.rb', line 35 def all_regular_libraries @all_libraries.select { |x| x.is_a?(Library) } end |
#all_smart_libraries ⇒ Object
39 40 41 |
# File 'lib/alexandria/library_collection.rb', line 39 def all_smart_libraries @all_libraries.select { |x| x.is_a?(SmartLibrary) } end |
#really_delete_deleted_libraries ⇒ Object
56 57 58 59 |
# File 'lib/alexandria/library_collection.rb', line 56 def really_delete_deleted_libraries Library.really_delete_deleted_libraries SmartLibrary.really_delete_deleted_libraries end |
#really_save_all_books ⇒ Object
61 62 63 64 65 |
# File 'lib/alexandria/library_collection.rb', line 61 def really_save_all_books all_regular_libraries.each do |library| library.each { |book| library.save(book, true) } end end |
#reload ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/alexandria/library_collection.rb', line 18 def reload @all_libraries.clear @all_libraries.concat(library_store.load_all_libraries) @all_libraries.concat(library_store.load_all_smart_libraries) ruined = [] deleted = [] all_regular_libraries.each do |library| ruined += library.ruined_books # make deleted books from each library accessible so we don't crash on # smart libraries deleted += library.deleted_books end @ruined_books = ruined @deleted_books = deleted end |
#remove_library(library) ⇒ Object
51 52 53 54 |
# File 'lib/alexandria/library_collection.rb', line 51 def remove_library(library) @all_libraries.delete(library) notify(LIBRARY_REMOVED, library) end |