Class: Runo::Storage
- Inherits:
-
Object
- Object
- Runo::Storage
- Defined in:
- lib/_storage/_storage.rb
Overview
- Author
-
Akira FUNAI
- Copyright
-
Copyright © 2009 Akira FUNAI
Defined Under Namespace
Instance Attribute Summary collapse
-
#sd ⇒ Object
readonly
Returns the value of attribute sd.
Class Method Summary collapse
Instance Method Summary collapse
- #build(v) ⇒ Object
- #clear ⇒ Object
- #delete(id) ⇒ Object
-
#initialize(sd) ⇒ Storage
constructor
A new instance of Storage.
- #last(cid, conds) ⇒ Object
- #navi(conds) ⇒ Object
- #order ⇒ Object
- #persistent? ⇒ Boolean
- #select(conds = {}) ⇒ Object
- #store(id, v) ⇒ Object
Constructor Details
#initialize(sd) ⇒ Storage
Returns a new instance of Storage.
27 28 29 |
# File 'lib/_storage/_storage.rb', line 27 def initialize(sd) @sd = sd end |
Instance Attribute Details
#sd ⇒ Object (readonly)
Returns the value of attribute sd.
25 26 27 |
# File 'lib/_storage/_storage.rb', line 25 def sd @sd end |
Class Method Details
.available? ⇒ Boolean
21 22 23 |
# File 'lib/_storage/_storage.rb', line 21 def self.available? false end |
.instance(sd) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/_storage/_storage.rb', line 8 def self.instance(sd) if folder = sd[:folder] if folder != sd[:parent] Temp.new sd else klass = Runo['storage']['default'].capitalize self.const_get(klass).new sd end else Temp.new sd end end |
Instance Method Details
#build(v) ⇒ Object
47 48 49 |
# File 'lib/_storage/_storage.rb', line 47 def build(v) self end |
#clear ⇒ Object
51 52 53 |
# File 'lib/_storage/_storage.rb', line 51 def clear self end |
#delete(id) ⇒ Object
59 60 61 |
# File 'lib/_storage/_storage.rb', line 59 def delete(id) id end |
#last(cid, conds) ⇒ Object
95 96 97 |
# File 'lib/_storage/_storage.rb', line 95 def last(cid, conds) __send__("_sibs_#{cid}", conds).last end |
#navi(conds) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/_storage/_storage.rb', line 63 def navi(conds) conds[:p] = '1' unless conds[:p] || conds[:id] || (@sd[:p_size].to_i < 1) navi = {} (([:id, :p, :d] & conds.keys) | conds.keys).each {|cid| next unless conds[cid] && respond_to?("_sibs_#{cid}", true) sibs = __send__("_sibs_#{cid}", conds) c = (c.is_a?(::Array) && c.size < 2) ? conds[cid].first : conds[cid] if i = sibs.index(c) if !navi[:prev] && i > 0 navi[:prev] = conds.merge(cid => sibs[i - 1]) if ![:id, :p].include? cid navi[:prev][:id] = _select_without(:id, navi[:prev]).last if conds[:id] navi[:prev][:p] = _p_count(navi[:prev]).to_s if conds[:p] end end if !navi[:next] && i < (sibs.size - 1) navi[:next] = conds.merge(cid => sibs[i + 1]) if ![:id, :p].include? cid navi[:next][:id] = _select_without(:id, navi[:next]).first if conds[:id] navi[:next][:p] = '1' if conds[:p] end end end navi[:sibs] ||= {cid => sibs} if navi[:prev] || navi[:next] break if navi[:prev] && navi[:next] } navi end |
#order ⇒ Object
35 36 37 |
# File 'lib/_storage/_storage.rb', line 35 def order @sd[:order] end |
#persistent? ⇒ Boolean
31 32 33 |
# File 'lib/_storage/_storage.rb', line 31 def persistent? true end |
#select(conds = {}) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/_storage/_storage.rb', line 39 def select(conds = {}) _cast conds item_ids = _select(conds) item_ids = _sort(item_ids, conds) item_ids = _page(item_ids, conds) ((conds[:order] || order) =~ /^-/) ? item_ids.reverse : item_ids end |
#store(id, v) ⇒ Object
55 56 57 |
# File 'lib/_storage/_storage.rb', line 55 def store(id, v) id end |