git_chain 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d85a7c86255d54f43461fb946ccdda25046436573311884057cc5152882d72c6
4
- data.tar.gz: dc21fe06c6a067f91eca4aba3a53b716d22f6d5d4be3e019e083e15ff3457756
3
+ metadata.gz: 39beb1bd625ee428f7c842e9da4d0e156f36841bd6b34a695a8b39aebe084f63
4
+ data.tar.gz: 392fa9912685006163752ad506ed02e3a032bc5fd775e8ca37798c9c6d1cc79e
5
5
  SHA512:
6
- metadata.gz: 5b8b48b7b2f8a056f6b82784da379a7b5ae39ad185089aaa39b3b4e9f873aafb70bdd1b12e5c1982ed442a6c32458aafad5d3cd07ecce213a71c490a91a4e802
7
- data.tar.gz: a2bcc8999be97eb6a81dbd20b83306d6b6b665e5282f97d658d21a4cc6f2870274a5abb471126aa05433b8998d6734794b033b14ceff7ff4ee896eb33fc43f82
6
+ metadata.gz: 5c3a0bab7113d83a59f78efe0829cd4cca75824b1d63841afc95217c85eaf75e74369e87c8e58b9f8800cf176b4792f9d5dc1c6fccbefb12511d075fe0178f5e
7
+ data.tar.gz: e2e1b0521c2a9ef2f3fd6d1339a14440e4b759f537965a826e8932a23a1266c72eeb09d0d6abb76db7ea1aba013090090b44f6800a5231071335f8de54d9198d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git_chain (0.1.1)
4
+ git_chain (0.1.2)
5
5
  git
6
6
 
7
7
  GEM
@@ -10,7 +10,8 @@ class GitChain::Runner
10
10
  def call(command, *args)
11
11
  case command
12
12
  when 'list'
13
- puts storage.data
13
+ # storage.save_data
14
+ storage.print
14
15
  when 'add'
15
16
  chain.mark_branch_as_dependent(
16
17
  child: git.current_branch,
@@ -1,7 +1,9 @@
1
1
  class GitChain::Storage
2
- FILE_NAME='.git_chains'
2
+ FILE_NAME = ".git_chains"
3
+ FORMAT_VERSION = "1"
3
4
 
4
5
  attr_reader :path, :file_name, :file_path
6
+
5
7
  def initialize(path: nil, file_name: nil)
6
8
  @path = path || %x{pwd}.strip
7
9
  @file_name = file_name || FILE_NAME
@@ -9,36 +11,63 @@ class GitChain::Storage
9
11
  end
10
12
 
11
13
  def record_for(child)
12
- data[child.to_sym]
14
+ records[child.to_sym]
13
15
  end
14
16
 
15
- def update_record(child:, parent:, base: )
16
- data[child.to_sym] = {
17
+ def update_record(child:, parent:, base:)
18
+ records[child.to_sym] = {
17
19
  parent: parent,
18
20
  child: child,
19
- base: base
21
+ base: base,
20
22
  }
21
23
 
22
24
  save_data
23
25
  end
24
26
 
25
- def data
26
- @_data ||= load_data || {}
27
- end
28
-
29
27
  def save_data
30
28
  File.write(file_path, data.to_json)
31
29
  end
32
30
 
31
+ def print
32
+ pp data
33
+ end
34
+
33
35
  private
34
36
 
37
+ def records
38
+ data[:records]
39
+ end
40
+
41
+ def data
42
+ @_data ||= load_data || { format_version: FORMAT_VERSION, records: {} }
43
+ end
44
+
35
45
  def load_data
36
46
  json_data = File.read(file_path) if File.exist?(file_path)
37
47
 
38
48
  if json_data.nil? || json_data.empty?
39
49
  nil
40
50
  else
41
- JSON.parse(json_data, symbolize_names: true)
51
+ post_process(
52
+ JSON.parse(json_data, symbolize_names: true)
53
+ )
54
+ end
55
+ end
56
+
57
+ def post_process(loaded_data)
58
+ while upgrade = UPGRADES[loaded_data[:format_version] || 0]
59
+ loaded_data = upgrade.call(loaded_data)
42
60
  end
61
+ return loaded_data
43
62
  end
44
- end
63
+
64
+ UPGRADES =
65
+ {
66
+ 0 => Proc.new do |d|
67
+ {
68
+ format_version: 1,
69
+ records: d,
70
+ }
71
+ end,
72
+ }
73
+ end
@@ -1,3 +1,3 @@
1
1
  module GitChain
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_chain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan McGarvey