class Tori::Backend::Chain
Chain
based on `exist?` method @example
class Book < ActiveRecord::Base include Tori::Backend # short cut # If exist "lib/pdf" load this, # But nothing, Load from S3 "book" bucket. chain_backend = Chain.new( FileSystem.new(Pathname("lib/pdf")), S3.new(bucket: "book"), ) tori :pdf, chain_backend do |model| "book/#{__tori__}/#{model.id}" end end
Attributes
backends[RW]
Public Class Methods
new(*backends)
click to toggle source
# File lib/tori/backend/chain.rb, line 24 def initialize(*backends) @backends = backends end
Public Instance Methods
backend(filename)
click to toggle source
# File lib/tori/backend/chain.rb, line 28 def backend(filename) @backends.each do |b| if b.exist?(filename) return b end end raise ExistError, "exist(#{filename}) backend not found" end
exist?(filename)
click to toggle source
# File lib/tori/backend/chain.rb, line 37 def exist?(filename) backend(filename) rescue ExistError false else true end
open(filename, &block)
click to toggle source
# File lib/tori/backend/chain.rb, line 49 def open(filename, &block) backend(filename).open(filename, &block) end
read(filename)
click to toggle source
# File lib/tori/backend/chain.rb, line 45 def read(filename) backend(filename).read(filename) end