class GitChain::Storage
Constants
- FILE_NAME
- FORMAT_VERSION
- UPGRADES
Attributes
file_name[R]
file_path[R]
path[R]
Public Class Methods
new(path: nil, file_name: nil)
click to toggle source
# File lib/git_chain/storage.rb, line 7 def initialize(path: nil, file_name: nil) @path = path || %x{pwd}.strip @file_name = file_name || FILE_NAME @file_path = @path + "/" + @file_name end
Public Instance Methods
print()
click to toggle source
# File lib/git_chain/storage.rb, line 31 def print pp data end
print_branch(branch: )
click to toggle source
# File lib/git_chain/storage.rb, line 35 def print_branch(branch: ) pp record_for(branch) end
record_for(child)
click to toggle source
# File lib/git_chain/storage.rb, line 13 def record_for(child) records[child.to_sym] end
save_data()
click to toggle source
# File lib/git_chain/storage.rb, line 27 def save_data File.write(file_path, data.to_json) end
update_record(child:, parent:, base:)
click to toggle source
# File lib/git_chain/storage.rb, line 17 def update_record(child:, parent:, base:) records[child.to_sym] = { parent: parent, child: child, base: base, } save_data end
Private Instance Methods
data()
click to toggle source
# File lib/git_chain/storage.rb, line 45 def data @_data ||= load_data || { format_version: FORMAT_VERSION, records: {} } end
load_data()
click to toggle source
# File lib/git_chain/storage.rb, line 49 def load_data json_data = File.read(file_path) if File.exist?(file_path) if json_data.nil? || json_data.empty? nil else post_process( JSON.parse(json_data, symbolize_names: true) ) end end
post_process(loaded_data)
click to toggle source
# File lib/git_chain/storage.rb, line 61 def post_process(loaded_data) while upgrade = UPGRADES[loaded_data[:format_version] || 0] loaded_data = upgrade.call(loaded_data) end return loaded_data end
records()
click to toggle source
# File lib/git_chain/storage.rb, line 41 def records data[:records] end