Class: Gallerist::Library

Inherits:
Object
  • Object
show all
Defined in:
lib/gallerist/library.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.expand_path library_path
  @db_path = File.dirname File.realpath(File.join @path, 'Database', 'Library.apdb')
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



10
11
12
# File 'lib/gallerist/library.rb', line 10

def app
  @app
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/gallerist/library.rb', line 11

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/gallerist/library.rb', line 12

def path
  @path
end

Instance Method Details

#albumsObject



20
21
22
# File 'lib/gallerist/library.rb', line 20

def albums
  Gallerist::Album.all
end

#app_idObject



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_dbObject



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_dbsObject



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_pathObject



30
31
32
# File 'lib/gallerist/library.rb', line 30

def db_path
  @temp_path || @db_path
end

#image_proxies_dbObject



76
77
78
# File 'lib/gallerist/library.rb', line 76

def image_proxies_db
  File.join db_path, 'ImageProxies.apdb'
end

#inspectObject



80
81
82
# File 'lib/gallerist/library.rb', line 80

def inspect
  "#<%s path='%s'>" % [ self.class, path ]
end

#iphoto?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/gallerist/library.rb', line 64

def iphoto?
  app_id == 'com.apple.iPhoto'
end

#library_dbObject



72
73
74
# File 'lib/gallerist/library.rb', line 72

def library_db
  File.join db_path, 'Library.apdb'
end

#person_dbObject



84
85
86
# File 'lib/gallerist/library.rb', line 84

def person_db
  File.join db_path, iphoto? ? 'Faces.db' : 'Person.db'
end

#personsObject



88
89
90
# File 'lib/gallerist/library.rb', line 88

def persons
  Gallerist::Person.all
end

#photosObject



92
93
94
# File 'lib/gallerist/library.rb', line 92

def photos
  Gallerist::Photo.all
end

#tagsObject



68
69
70
# File 'lib/gallerist/library.rb', line 68

def tags
  Gallerist::Tag.all
end

#typeObject



96
97
98
# File 'lib/gallerist/library.rb', line 96

def type
  iphoto? ? :iphoto : :photos
end