class Gallerist::Library

Attributes

app[R]
name[R]
path[R]

Public Class Methods

new(library_path) click to toggle source
# 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

Public Instance Methods

albums() click to toggle source
# File lib/gallerist/library.rb, line 20
def albums
  Gallerist::Album.all
end
app_id() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/gallerist/library.rb, line 30
def db_path
  @temp_path || @db_path
end
image_proxies_db() click to toggle source
# File lib/gallerist/library.rb, line 76
def image_proxies_db
  File.join db_path, 'ImageProxies.apdb'
end
inspect() click to toggle source
# File lib/gallerist/library.rb, line 80
def inspect
  "#<%s path='%s'>" % [ self.class, path ]
end
iphoto?() click to toggle source
# File lib/gallerist/library.rb, line 64
def iphoto?
  app_id == 'com.apple.iPhoto'
end
library_db() click to toggle source
# File lib/gallerist/library.rb, line 72
def library_db
  File.join db_path, 'Library.apdb'
end
person_db() click to toggle source
# File lib/gallerist/library.rb, line 84
def person_db
  File.join db_path, iphoto? ? 'Faces.db' : 'Person.db'
end
persons() click to toggle source
# File lib/gallerist/library.rb, line 88
def persons
  Gallerist::Person.all
end
photos() click to toggle source
# File lib/gallerist/library.rb, line 92
def photos
  Gallerist::Photo.all
end
tags() click to toggle source
# File lib/gallerist/library.rb, line 68
def tags
  Gallerist::Tag.all
end
type() click to toggle source
# File lib/gallerist/library.rb, line 96
def type
  iphoto? ? :iphoto : :photos
end