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
-
#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.
51 52 53 54 55 56 57 58 |
# File 'lib/ccp/persistent/versioned.rb', line 51 def initialize(dir, = {}) @path = Pathname(dir) @default_kvs = [:kvs] || :dir @default_ext = [:ext] || :json @storages = {} @path.mkpath end |
Instance Attribute Details
#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
指定したストレージを返す。存在しなければ作成して返す
82 83 84 85 |
# File 'lib/ccp/persistent/versioned.rb', line 82 def [](key) storage = Storage.complete(key, path, @default_kvs, @default_ext) @storages[storage.to_s] ||= storage.create end |
#default ⇒ Object
最新のストレージを返す。存在しなければ作成
72 73 74 |
# File 'lib/ccp/persistent/versioned.rb', line 72 def default latest || now end |
#inspect ⇒ Object
87 88 89 |
# File 'lib/ccp/persistent/versioned.rb', line 87 def inspect "<Kvs::Versioned dir=#{path} kvs=#{@default_kvs} ext=#{@default_ext}>" end |
#latest ⇒ Object
最新のストレージを返す。存在しなければnil
61 62 63 64 |
# File 'lib/ccp/persistent/versioned.rb', line 61 def latest storage = StorageScanner.scan(path).last storage ? self[storage] : nil end |
#latest! ⇒ Object
最新のストレージを返す。存在しなければ例外
67 68 69 |
# File 'lib/ccp/persistent/versioned.rb', line 67 def latest! latest.must.exist { raise Ccp::Persistent::NotFound, "#{path}/*" } end |
#now ⇒ Object
現在の時刻で新しいストレージを作成して返す
77 78 79 |
# File 'lib/ccp/persistent/versioned.rb', line 77 def now self[Time.now.to_i] end |