Class: Ccp::Persistent::Versioned
- Inherits:
-
Object
- Object
- Ccp::Persistent::Versioned
- Defined in:
- lib/ccp/persistent/versioned.rb
Defined Under Namespace
Modules: StorageScanner Classes: Storage
Instance Attribute Summary collapse
-
#ext ⇒ Object
readonly
Returns the value of attribute ext.
-
#kvs ⇒ Object
readonly
Returns the value of attribute kvs.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#[](key) ⇒ Object
指定したストレージを返す。存在しなければ作成して返す.
-
#default ⇒ Object
最新のストレージを返す。存在しなければ作成.
-
#initialize(dir, options = {}) ⇒ Versioned
constructor
A new instance of Versioned.
- #inspect ⇒ Object
-
#latest ⇒ Object
最新のストレージを返す。存在しなければnil.
-
#latest! ⇒ Object
最新のストレージを返す。存在しなければ例外.
-
#now ⇒ Object
現在の時刻で新しいストレージを作成して返す.
Constructor Details
#initialize(dir, options = {}) ⇒ Versioned
Returns a new instance of Versioned.
54 55 56 57 58 59 60 61 |
# File 'lib/ccp/persistent/versioned.rb', line 54 def initialize(dir, = {}) @path = Pathname(dir) @kvs = [:kvs] || :dir @ext = [:ext] || :msgpack @storages = {} @path.mkpath end |
Instance Attribute Details
#ext ⇒ Object (readonly)
Returns the value of attribute ext.
52 53 54 |
# File 'lib/ccp/persistent/versioned.rb', line 52 def ext @ext end |
#kvs ⇒ Object (readonly)
Returns the value of attribute kvs.
51 52 53 |
# File 'lib/ccp/persistent/versioned.rb', line 51 def kvs @kvs end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/ccp/persistent/versioned.rb', line 4 def path @path end |
Instance Method Details
#[](key) ⇒ Object
指定したストレージを返す。存在しなければ作成して返す
85 86 87 88 |
# File 'lib/ccp/persistent/versioned.rb', line 85 def [](key) storage = Storage.complete(key, path, @kvs, @ext) @storages[storage.to_s] ||= storage.create end |
#default ⇒ Object
最新のストレージを返す。存在しなければ作成
75 76 77 |
# File 'lib/ccp/persistent/versioned.rb', line 75 def default latest || now end |
#inspect ⇒ Object
90 91 92 |
# File 'lib/ccp/persistent/versioned.rb', line 90 def inspect "<Kvs::Versioned dir=#{path} kvs=#{@kvs} ext=#{@ext}>" end |
#latest ⇒ Object
最新のストレージを返す。存在しなければnil
64 65 66 67 |
# File 'lib/ccp/persistent/versioned.rb', line 64 def latest storage = StorageScanner.scan(path).last storage ? self[storage] : nil end |
#latest! ⇒ Object
最新のストレージを返す。存在しなければ例外
70 71 72 |
# File 'lib/ccp/persistent/versioned.rb', line 70 def latest! latest.must.exist { raise Ccp::Persistent::NotFound, "#{path}/*" } end |
#now ⇒ Object
現在の時刻で新しいストレージを作成して返す
80 81 82 |
# File 'lib/ccp/persistent/versioned.rb', line 80 def now self[Time.now.to_i] end |