Class: Tori::Backend::Chain
- Inherits:
-
Object
- Object
- Tori::Backend::Chain
- Defined in:
- lib/tori/backend/chain.rb
Overview
Chain based on ‘exist?` method
Defined Under Namespace
Classes: ExistError
Instance Attribute Summary collapse
-
#backends ⇒ Object
Returns the value of attribute backends.
Instance Method Summary collapse
- #backend(filename) ⇒ Object
- #exist?(filename) ⇒ Boolean
-
#initialize(*backends) ⇒ Chain
constructor
A new instance of Chain.
- #open(filename, &block) ⇒ Object
- #read(filename) ⇒ Object
Constructor Details
#initialize(*backends) ⇒ Chain
Returns a new instance of Chain.
24 25 26 |
# File 'lib/tori/backend/chain.rb', line 24 def initialize(*backends) @backends = backends end |
Instance Attribute Details
#backends ⇒ Object
Returns the value of attribute backends.
22 23 24 |
# File 'lib/tori/backend/chain.rb', line 22 def backends @backends end |
Instance Method Details
#backend(filename) ⇒ Object
28 29 30 31 32 33 34 35 |
# 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) ⇒ Boolean
37 38 39 40 41 42 43 |
# File 'lib/tori/backend/chain.rb', line 37 def exist?(filename) backend(filename) rescue ExistError false else true end |
#open(filename, &block) ⇒ Object
49 50 51 |
# File 'lib/tori/backend/chain.rb', line 49 def open(filename, &block) backend(filename).open(filename, &block) end |
#read(filename) ⇒ Object
45 46 47 |
# File 'lib/tori/backend/chain.rb', line 45 def read(filename) backend(filename).read(filename) end |