class Gallerist::App
Public Class Methods
setup_default_middleware(builder)
click to toggle source
# File lib/gallerist/app.rb, line 143 def self.setup_default_middleware(builder) builder.use Sinatra::ExtendedRack builder.use Gallerist::ShowExceptions if show_exceptions? builder.use Gallerist::RaiseWarmupExceptions setup_logging builder end
Public Instance Methods
library()
click to toggle source
# File lib/gallerist/app.rb, line 68 def library unless settings.respond_to? :library settings.set :library, Gallerist::Library.new(settings.library_path) logger.info "Loading library from \"#{library.path}\"" if settings.copy_dbs logger.debug 'Creating temporary copy of the main library database...' library.copy_base_db logger.debug ' Completed.' end ActiveRecord::Base.establish_connection({ adapter: 'sqlite3', database: library.library_db }) ActiveRecord::Base.connection.exec_query 'PRAGMA journal_mode="MEMORY";' if settings.copy_dbs logger.debug 'Creating temporary copies of additional library databases...' library.copy_extra_dbs logger.debug ' Completed.' end logger.info " Found library with type '%s'." % [ library.app_id ] Gallerist.load_models Gallerist::BaseModel.descendants.each do |model| logger.debug "Setting up %s for library type '%s'" % [ model, library.type ] model.setup_for library.type end Gallerist::ImageProxiesModel.establish_connection({ adapter: 'sqlite3', database: library.image_proxies_db }) Gallerist::ImageProxiesModel.connection.exec_query 'PRAGMA journal_mode="MEMORY";' Gallerist::PersonModel.establish_connection({ adapter: 'sqlite3', database: library.person_db }) Gallerist::PersonModel.connection.exec_query 'PRAGMA journal_mode="MEMORY";' end settings.library end
photo(id)
click to toggle source
# File lib/gallerist/app.rb, line 136 def photo(id) Gallerist::Photo.find id rescue ActiveRecord::RecordNotFound logger.error 'Could not find the photo with ID #%s.' % [ id ] not_found end
send_library_file(file, options = {})
click to toggle source
# File lib/gallerist/app.rb, line 56 def send_library_file(file, options = {}) logger.debug "Serving file '%s' from library..." % [ file ] file_path = File.join(library.path, file) response = catch(:halt) { send_file file_path, options } if response == 404 logger.error "File '%s' could not be served, because it does not exist." % file end halt response end