Class: Gallerist::Library
- Inherits:
-
Object
- Object
- Gallerist::Library
- Defined in:
- lib/gallerist/library.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #albums ⇒ Object
- #app_id ⇒ Object
- #copy_base_db ⇒ Object
- #copy_extra_dbs ⇒ Object
- #copy_tmp_db(db_name) ⇒ Object
- #db_path ⇒ Object
- #image_proxies_db ⇒ Object
-
#initialize(library_path) ⇒ Library
constructor
A new instance of Library.
- #inspect ⇒ Object
- #iphoto? ⇒ Boolean
- #library_db ⇒ Object
- #person_db ⇒ Object
- #persons ⇒ Object
- #photos ⇒ Object
- #tags ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(library_path) ⇒ Library
Returns a new instance of Library.
14 15 16 17 18 |
# File 'lib/gallerist/library.rb', line 14 def initialize(library_path) @name = File.basename(library_path).rpartition('.').first @path = File. library_path @db_path = File.dirname File.realpath(File.join @path, 'Database', 'Library.apdb') end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
10 11 12 |
# File 'lib/gallerist/library.rb', line 10 def app @app end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/gallerist/library.rb', line 11 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/gallerist/library.rb', line 12 def path @path end |
Instance Method Details
#albums ⇒ Object
20 21 22 |
# File 'lib/gallerist/library.rb', line 20 def albums Gallerist::Album.all end |
#app_id ⇒ Object
24 25 26 27 28 |
# File 'lib/gallerist/library.rb', line 24 def app_id @app_id ||= Gallerist::AdminData. where(propertyArea: 'database', propertyName: 'applicationIdentifier'). pluck(:propertyValue).first end |
#copy_base_db ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/gallerist/library.rb', line 34 def copy_base_db @temp_path = Dir.mktmpdir 'gallerist' temp_path = @temp_path.dup at_exit { FileUtils.rm_rf temp_path } copy_tmp_db 'Library.apdb' end |
#copy_extra_dbs ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/gallerist/library.rb', line 42 def copy_extra_dbs copy_tmp_db 'ImageProxies.apdb' if iphoto? copy_tmp_db 'Faces.db' else copy_tmp_db 'Person.db' end end |
#copy_tmp_db(db_name) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/gallerist/library.rb', line 52 def copy_tmp_db(db_name) source_path = File.join @db_path, db_name dest_path = File.join @temp_path, db_name db = SQLite3::Database.new source_path db.transaction :immediate do |_| FileUtils.cp source_path, dest_path, preserve: true end ensure db.close unless db.nil? end |
#db_path ⇒ Object
30 31 32 |
# File 'lib/gallerist/library.rb', line 30 def db_path @temp_path || @db_path end |
#image_proxies_db ⇒ Object
76 77 78 |
# File 'lib/gallerist/library.rb', line 76 def image_proxies_db File.join db_path, 'ImageProxies.apdb' end |
#inspect ⇒ Object
80 81 82 |
# File 'lib/gallerist/library.rb', line 80 def inspect "#<%s path='%s'>" % [ self.class, path ] end |
#iphoto? ⇒ Boolean
64 65 66 |
# File 'lib/gallerist/library.rb', line 64 def iphoto? app_id == 'com.apple.iPhoto' end |
#library_db ⇒ Object
72 73 74 |
# File 'lib/gallerist/library.rb', line 72 def library_db File.join db_path, 'Library.apdb' end |
#person_db ⇒ Object
84 85 86 |
# File 'lib/gallerist/library.rb', line 84 def person_db File.join db_path, iphoto? ? 'Faces.db' : 'Person.db' end |
#persons ⇒ Object
88 89 90 |
# File 'lib/gallerist/library.rb', line 88 def persons Gallerist::Person.all end |
#photos ⇒ Object
92 93 94 |
# File 'lib/gallerist/library.rb', line 92 def photos Gallerist::Photo.all end |
#type ⇒ Object
96 97 98 |
# File 'lib/gallerist/library.rb', line 96 def type iphoto? ? :iphoto : :photos end |