Class: GitChain::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/git_chain/storage.rb

Constant Summary collapse

FILE_NAME =
".git_chains"
FORMAT_VERSION =
"1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: nil, file_name: nil) ⇒ Storage

Returns a new instance of Storage.



7
8
9
10
11
# 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

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



5
6
7
# File 'lib/git_chain/storage.rb', line 5

def file_name
  @file_name
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



5
6
7
# File 'lib/git_chain/storage.rb', line 5

def file_path
  @file_path
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/git_chain/storage.rb', line 5

def path
  @path
end

Instance Method Details



31
32
33
# File 'lib/git_chain/storage.rb', line 31

def print
  pp data
end


35
36
37
# File 'lib/git_chain/storage.rb', line 35

def print_branch(branch: )
  pp record_for(branch)
end

#record_for(child) ⇒ Object



13
14
15
# File 'lib/git_chain/storage.rb', line 13

def record_for(child)
  records[child.to_sym]
end

#save_dataObject



27
28
29
# File 'lib/git_chain/storage.rb', line 27

def save_data
  File.write(file_path, data.to_json)
end

#update_record(child:, parent:, base:) ⇒ Object



17
18
19
20
21
22
23
24
25
# 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