ll 0.0.3 → 0.0.4

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: 7a9c96ac0bda2425338cd0312cc63c2f731332853ad6d9f5e8043e281fedafd0
4
- data.tar.gz: af61f5a74e8939b56479c24e6cb2f126e02c0615a67831941d80462a16cfe4ac
3
+ metadata.gz: 88c6d3677c49c8b6f9977add7a3716bedaae5d2b9b802cc695bdb84312b2069e
4
+ data.tar.gz: 30b346cce42bce4ad8a63f441be831abb838363ad4ddf9b001cd2f91d1090295
5
5
  SHA512:
6
- metadata.gz: '0030849c4e589aebd29b086d1a39b03c0258e0bbebaed789f96222a3b6314ca7f51f0591452b552c9640e278c021ed7ad871e5bff011052f6889c7c540d32e1d'
7
- data.tar.gz: 1006dab7dee8774be6d1cd1ff93585d7b1483d0dc9ae81f3012bc3ee1cfdc6db261a650b453bae1dba23cb0e8358cb4aac01157b8c676eee565a2fed30ecc72a
6
+ metadata.gz: 85b41f41dcd5e55cfa489302082d8ebe075f6e46a9e29c42dd17f5627a2350783efea37cdb91313ccbef41bb6c226c59e164deeb0d905a0c6c07e2951d79d4bf
7
+ data.tar.gz: e17e043551d74fe86613b18077a5b89c3ef43a4ec7b39def328c6d886cadd9c090bc05580ab585759b09294666a9890fa1581c8941a8e2793970fb536dcca9c1
data/lib/ll.rb CHANGED
@@ -2,3 +2,12 @@ require "pry"
2
2
  require "vv"
3
3
 
4
4
  Gem.require_files "ll/*.rb"
5
+
6
+ module LL
7
+
8
+ def default_authority
9
+ "github.com/zachaysan/ll"
10
+ end
11
+ module_function :default_authority
12
+
13
+ end
data/lib/ll/checklist.rb CHANGED
@@ -1,6 +1,14 @@
1
1
  class LL::Checklist
2
2
 
3
- attr_reader :name
3
+ attr_reader :name,
4
+ :authority,
5
+ :title,
6
+ :description,
7
+ :identifier,
8
+ :action_at,
9
+ :steps,
10
+ :document_version,
11
+ :serialization_identifier
4
12
 
5
13
  def self.load( dir: )
6
14
  filepaths = Dir.glob(File.join dir, "checklists/*")
@@ -9,14 +17,111 @@ class LL::Checklist
9
17
  end
10
18
  end
11
19
 
12
- def initialize json_document=nil, name: nil
13
- # TODO: Parse the document
20
+ # Maybe abstract the versioning here into VV?
21
+ def initialize document: nil,
22
+ name: nil,
23
+ authority: nil
14
24
  @name = name
15
25
  @name ||= "Prototypical"
26
+
27
+ @authority = authority
28
+ @authority ||= LL.default_authority
29
+
30
+ @document_version = nil
31
+
32
+ self.parse_document! document if document
33
+
34
+ yield self if block_given?
35
+
36
+ self.reformat! unless self.document_current?
37
+ end
38
+
39
+ def reformat!
40
+ @document_version = self.current_version
41
+
42
+ # Because the same checklist may be serialized multiple times,
43
+ # by different clients it will get tricky tracing problems, so
44
+ # we include an identifier that clients should generate, but never
45
+ # manipulate.
46
+ @serialization_identifier = Random.identifier
47
+
48
+ self.steps
49
+ end
50
+
51
+ def document_current?
52
+ return nil if @document_version.nil?
53
+
54
+ @document_version == self.current_version
55
+ end
56
+
57
+ def parse_document! document
58
+ if document.is_a? String
59
+ document = document.parse_json
60
+ elsif document.is_a? Hash
61
+ else
62
+ fail TypeError, "Checklist expects string or hash document"
63
+ end
64
+
65
+ document.symbolize_keys!
66
+
67
+ attrs = %i[ meta
68
+ title
69
+ description
70
+ identifier
71
+ serialization_identifier
72
+ action_at
73
+ steps ]
74
+
75
+ self.set_attrs_via attrs, document: document
76
+ end
77
+
78
+ def current_version
79
+ LL::VERSION
80
+ end
81
+
82
+ def supported_versions
83
+ %w[ 0.0.2
84
+ 0.0.3 ]
16
85
  end
17
86
 
18
- def parse_document json_document
19
- raise NotImplementedError
87
+ def kind
88
+ "checklist"
89
+ end
90
+
91
+ def meta= meta
92
+ meta.symbolize_keys!
93
+ meta_authority = meta.fetch :authority
94
+ meta_version = meta.fetch :version
95
+ meta_kind = meta.fetch :kind
96
+ meta_format = meta.fetch :format
97
+
98
+ authority_ok = meta_authority == self.authority
99
+ message = "Document authority `#{meta_authority}` unknown."
100
+ fail message unless authority_ok
101
+
102
+ format_ok = meta_format == "json"
103
+ message = \
104
+ "Document format `#{meta_format}` not supported, must be `json`."
105
+ fail message unless format_ok
106
+
107
+ version_ok = meta_version.one_of?( *supported_versions )
108
+ message = "Document version `#{meta_version}` not supported."
109
+ fail message unless version_ok
110
+
111
+ kind_ok = meta_kind == "checklist"
112
+ message = \
113
+ "Document kind `#{meta_kind}` not supported, must be `checklist`."
114
+ fail message unless kind_ok
115
+
116
+ @document_version = meta_version
117
+ end
118
+
119
+ def steps= steps
120
+ fail "Expecting steps to be an array." unless steps.is_a? Array
121
+ @steps = steps.map do |step|
122
+ fail "Expecting step to be a hash." unless step.is_a? Hash
123
+ LL::Step.new step, document_version: @document_version
124
+ end
20
125
  end
21
126
 
22
127
  def to_s
@@ -24,11 +129,30 @@ class LL::Checklist
24
129
  end
25
130
 
26
131
  def to_h
27
- { name: self.name }
132
+ message = \
133
+ "Checklist in indeterminate state. This should never happen."
134
+ fail message unless self.document_current?
135
+
136
+ format = "hash"
137
+ meta = { version: self.current_version,
138
+ kind: self.kind,
139
+ authority: self.authority,
140
+ format: format }
141
+
142
+ { meta: meta,
143
+ title: self.title,
144
+ description: self.description,
145
+ identifier: self.identifier,
146
+ serialization_identifier: self.serialization_identifier,
147
+ action_at: self.action_at,
148
+ steps: self.steps }
28
149
  end
29
150
 
30
- def to_json
31
- JSON.dump self.to_hash
151
+ def vv_json
152
+ format = "json"
153
+ response = self.to_h
154
+ response[:meta][:format] = format
155
+ response.vv_json
32
156
  end
33
157
 
34
158
  end
data/lib/ll/step.rb CHANGED
@@ -12,10 +12,12 @@ class LL::Step
12
12
  :action_at,
13
13
  :version
14
14
 
15
- def initialize json_document
15
+ def initialize json_document, document_version:
16
16
  # TODO: Auto convert dasherized to underscore
17
17
  data = json_document.to_h.symbolize_keys
18
18
 
19
+ @document_version = document_version || LL::VERSION
20
+
19
21
  @title = data[:title]
20
22
  @description = data[:description]
21
23
  @action = data[:action]
@@ -27,7 +29,6 @@ class LL::Step
27
29
  @via = data[:via]
28
30
  @os = data[:via]
29
31
  @with = data[:via]
30
- @doc_version = data[:doc_version]
31
32
  @action_at = data[:action_at]
32
33
  end
33
34
 
@@ -36,4 +37,20 @@ class LL::Step
36
37
  raise NotImplementedError
37
38
  end
38
39
 
40
+ def to_h
41
+ { title: title,
42
+ description: description,
43
+ action: action,
44
+ kind: kind,
45
+ status: status,
46
+ identifier: identifier,
47
+ by: by,
48
+ via: via,
49
+ action_at: action_at }
50
+ end
51
+
52
+ def vv_json
53
+ self.to_h.vv_json
54
+ end
55
+
39
56
  end
data/lib/ll/version.rb CHANGED
@@ -1,3 +1,21 @@
1
1
  module LL
2
- VERSION = '0.0.3'
2
+
3
+ VERSION = '0.0.4'
4
+ Version = VERSION
5
+
6
+ def version
7
+ LL::VERSION
8
+ end
9
+ module_function :version
10
+
11
+ def Version
12
+ LL::VERSION
13
+ end
14
+ module_function :Version
15
+
16
+ def VERSION
17
+ LL::VERSION
18
+ end
19
+ module_function :VERSION
20
+
3
21
  end
@@ -1,10 +1,13 @@
1
- {"title": "Gem Tasks",
1
+ {"meta": { "authority": "github.com/zachaysan/ll",
2
+ "kind": "checklist",
3
+ "format": "json",
4
+ "version": "0.0.2" },
5
+ "title": "Gem Tasks",
2
6
  "description": "Finicky gem build details",
3
7
  "action": "create",
4
- "kind": "checklist",
5
8
  "identifier": "vux25anby00000000000000000",
9
+ "serialization_identifier": "zcte2zaw23xkyvcbpz2vc94i9qbi3xnkgtfxzvld",
6
10
  "action_at": "2019-02-21T19:42:06Z",
7
- "format": "json-v0.0.2",
8
11
  "steps": [ { "title": "Bump version",
9
12
  "description": null,
10
13
  "action": "create",
@@ -9,4 +9,72 @@ class ChecklistTest < Minitest::Test
9
9
  assert_equal expected_string, checklist.to_s
10
10
  end
11
11
 
12
+ def test_current_version_is_supported
13
+ checklist = LL::Checklist.new
14
+ assert_includes checklist.supported_versions,
15
+ checklist.current_version
16
+ end
17
+
18
+ def test_loads_latest_checklist
19
+ fixture = LL::Fixtures.previous_checklist
20
+
21
+ former_serialization_identifier = serialization_identifier = \
22
+ "zcte2zaw23xkyvcbpz2vc94i9qbi3xnkgtfxzvld"
23
+
24
+ checklist = LL::Checklist.new document: fixture do | checklist |
25
+ refute checklist.document_current?
26
+ expected_version = "0.0.2"
27
+ assert_equal expected_version, checklist.document_version
28
+ assert_equal serialization_identifier,
29
+ checklist.serialization_identifier
30
+ end
31
+
32
+ expected_version = LL::VERSION
33
+ assert_equal expected_version, checklist.document_version
34
+
35
+ json = checklist.vv_json
36
+ parsed_json = JSON.parse json
37
+
38
+
39
+ expected_authority = "github.com/zachaysan/ll"
40
+ expected_kind = "checklist"
41
+ expected_format = "json"
42
+ expected_version = LL::VERSION
43
+
44
+ assert_includes parsed_json, "meta"
45
+ meta = parsed_json["meta"]
46
+
47
+ assert_equal expected_authority, meta["authority"]
48
+ assert_equal expected_kind, meta["kind"]
49
+ assert_equal expected_format, meta["format"]
50
+ assert_equal expected_version, meta["version"]
51
+
52
+ expected_title = "Gem Tasks"
53
+ expected_description = "Finicky gem build details"
54
+ expected_identifier = "vux25anby00000000000000000"
55
+ expected_action_at = "2019-02-21T19:42:06Z"
56
+
57
+ assert_equal expected_title, parsed_json["title"]
58
+ assert_equal expected_description, parsed_json["description"]
59
+ assert_equal expected_identifier, parsed_json["identifier"]
60
+ assert_equal expected_action_at, parsed_json["action_at"]
61
+
62
+ refute_equal former_serialization_identifier,
63
+ parsed_json["serialization_identifier"]
64
+
65
+ assert_includes parsed_json, "steps"
66
+ steps = parsed_json["steps"]
67
+
68
+ expected_count = 3
69
+ assert_equal expected_count, steps.count
70
+
71
+ expected_title = "Bump version"
72
+ assert_equal expected_title, steps.first["title"]
73
+
74
+ expected_title = "Tweet about upcoming release"
75
+ assert_equal expected_title, steps.second["title"]
76
+
77
+ assert_nil steps.third["title"]
78
+ end
79
+
12
80
  end
data/test/test_helper.rb CHANGED
@@ -5,3 +5,23 @@ begin
5
5
  require "pry"
6
6
  rescue LoadError
7
7
  end
8
+
9
+ class LL::Fixtures
10
+
11
+ def self.read_checklist version
12
+ File.read File.join("test", "fixtures", "checklists", version)
13
+ end
14
+
15
+ # Keep these staggered
16
+ def self.checklist
17
+ self.read_checklist "v0.0.2.json"
18
+ end
19
+ def self.previous_checklist
20
+ self.read_checklist "v0.0.2.json"
21
+ end
22
+
23
+ def self.latest_checklist
24
+ self.checklist
25
+ end
26
+
27
+ end
data/test/test_ll.rb CHANGED
@@ -14,4 +14,15 @@ class LLTest < Minitest::Test
14
14
  assert String.vv_included?
15
15
  end
16
16
 
17
+ def test_version
18
+ refute_nil LL::VERSION
19
+
20
+ assert_equal LL::VERSION, LL::Version
21
+ assert_equal LL::VERSION, LL::version
22
+
23
+ assert_equal LL::VERSION, LL.VERSION
24
+ assert_equal LL::VERSION, LL.Version
25
+ assert_equal LL::VERSION, LL.version
26
+ end
27
+
17
28
  end
data/test/test_step.rb CHANGED
@@ -17,7 +17,7 @@ class StepTest < Minitest::Test
17
17
  "doc_version": "0.0.2",
18
18
  "action_at": "2019-02-21T19:41:06Z"}.to_json
19
19
 
20
- step = LL::Step.new step_input
20
+ step = LL::Step.new step_input, document_version: nil
21
21
  expected_status = "boot"
22
22
  assert_equal expected_status, step.status
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ll
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Aysan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-05 00:00:00.000000000 Z
11
+ date: 2019-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vv
@@ -106,8 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.7.7
109
+ rubygems_version: 3.0.3
111
110
  signing_key:
112
111
  specification_version: 4
113
112
  summary: Listy List