Class: Holdify::Store
- Inherits:
-
Object
- Object
- Holdify::Store
- Extended by:
- Forwardable
- Defined in:
- lib/holdify/store.rb
Overview
Interface to the Source (code) and the Ledger (data)
Defined Under Namespace
Classes: NoAliasVisitor
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #get_values(lineno) ⇒ Object
-
#initialize(path) ⇒ Store
constructor
A new instance of Store.
- #persist ⇒ Object
- #set_values(lineno, values) ⇒ Object
Constructor Details
#initialize(path) ⇒ Store
Returns a new instance of Store.
24 25 26 27 28 29 |
# File 'lib/holdify/store.rb', line 24 def initialize(path) @path = "#{path}#{Holdify.store_ext}" @source = Source.new(path) FileUtils.rm_f(@path) if Holdify.reconcile @data = File.exist?(@path) ? load_and_align : {} end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
22 23 24 |
# File 'lib/holdify/store.rb', line 22 def path @path end |
Class Method Details
.hold_dump(obj) ⇒ Object
14 15 16 17 18 |
# File 'lib/holdify/store.rb', line 14 def self.hold_dump(obj) visitor = NoAliasVisitor.create visitor << obj visitor.tree.to_yaml end |
Instance Method Details
#get_values(lineno) ⇒ Object
31 |
# File 'lib/holdify/store.rb', line 31 def get_values(lineno) = @data[lineno] |
#persist ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/holdify/store.rb', line 35 def persist return FileUtils.rm_f(@path) if @data.empty? output = {} @data.keys.sort.each do |lineno| xxh = @source.xxh(lineno) next unless xxh output["L#{lineno}-#{xxh}"] = @data[lineno] end File.write(@path, self.class.hold_dump(output)) end |
#set_values(lineno, values) ⇒ Object
33 |
# File 'lib/holdify/store.rb', line 33 def set_values(lineno, values) = (@data[lineno] = values) |