multicodecs 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ae87450a3251c123d99fe7a050eaef36023d16a80c359030a366ae6b000e72d
4
- data.tar.gz: 86afee1666905ea25f2e82b1b584a80a9baeb6e0faea9300eec60769090530ab
3
+ metadata.gz: bf3dc42c444e7e1b15dfe8fd6687e5d32956fa86b46bcabb4609733bf05ff5f3
4
+ data.tar.gz: ffc283a7ee473362b89cadaf90841a967c5340fcdb36047f046af120da42c432
5
5
  SHA512:
6
- metadata.gz: 478732cd67ee4cb967239307a1497f56d02537798e28a0741341675278bb199e0b865d94c779cbb5544655b584a7326cacc9e7702a70f1b9086bbde84875f65e
7
- data.tar.gz: 0f585a08ca3f75e07d2caf1a2fabdcc80af9582d6a0c09a4c3e51e89c5314beeb350e0b8297941304882fd766b4b473204651027b938d4dcec4a7ae8a7435b91
6
+ metadata.gz: 0b19f680c406fbabb5918243f6b959681d845dfe2416a334561c2c7cf059bb02c9edb58390cebba81fdb99a5d5c3385ad925d5d6380785210ba1298d8a3c79b1
7
+ data.tar.gz: 9b8d9da86ecf101230e4778a3c349b69f19a7856e4e04c88bc56f9c0868770118f93912059eb0d58d275c7f8e61a079b587e59134683c4ea74851f9ade5e724d
@@ -0,0 +1,7 @@
1
+ {
2
+ "cSpell.words": [
3
+ "kwargs",
4
+ "Multicodecs",
5
+ "multihash"
6
+ ]
7
+ }
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.0
4
+
5
+ - Update multicodec table
6
+ - Implement `status` and `description`
7
+ - Remove `Struct` usage
8
+
3
9
  ## 0.2.1
4
10
 
5
11
  - Fix deprecation warning in update rake task ([#3][pr-3])
data/README.md CHANGED
@@ -58,20 +58,20 @@ also allows you to bring your own values.
58
58
  require 'multicodecs'
59
59
 
60
60
  Multicodecs['identity']
61
- # => #<struct Multicodecs::Registration code=0, name="identity", tag="multihash">
61
+ # => 0x0 identity (multihash/permanent): raw binary
62
62
 
63
63
  Multicodecs[0x12]
64
- # => #<struct Multicodecs::Registration code=18, name="sha2-256", tag="multihash">
64
+ # => 0x12 sha2-256 (multihash/permanent): (no description)
65
65
 
66
66
  Multicodecs.find_by(name: 'protobuf')
67
- # => #<struct Multicodecs::Registration code=80, name="protobuf", tag="serialization">
67
+ # => 0x50 protobuf (serialization/draft): Protocol Buffers
68
68
  ```
69
69
 
70
70
  You can `register` your own values
71
71
 
72
72
  ```ruby
73
- Multicodecs.register(code: 0x12345, name: 'xxx', tag: 'vendor')
74
- # => #<struct Multicodecs::Registration code=74565, name="xxx", tag="vendor">
73
+ Multicodecs.register(code: 0x12345, name: 'xxx', tag: 'vendor', status: 'draft', description: nil)
74
+ # => 0x12345 xxx (vendor/draft): (no description)
75
75
  ```
76
76
 
77
77
  Convenience methods exist:
@@ -141,5 +141,3 @@ mailing lists is expected to follow the [code of conduct][git-self-coc].
141
141
  [web-coc]: http://contributor-covenant.org
142
142
  [web-mit]: https://opensource.org/licenses/MIT
143
143
  [web-rubygems]: https://rubygems.org
144
-
145
-
@@ -8,14 +8,18 @@ module Multicodecs
8
8
 
9
9
  def load_csv(csv, radix: 16)
10
10
  csv.each do |row|
11
- name = row['name'] || row[0]
12
- tag = row['tag'] || row[1]
13
- code = row['code'] || row[2]
11
+ name = row['name'] || row[0]
12
+ tag = row['tag'] || row[1]
13
+ code = row['code'] || row[2]
14
+ status = row['status'] || row[3]
15
+ description = row['description'] || row[4]
14
16
 
15
17
  Multicodecs.register(
16
18
  name: name.strip,
17
19
  tag: tag.strip,
18
- code: code.strip.to_i(16)
20
+ code: code.strip.to_i(16),
21
+ status: status.strip,
22
+ description: description&.strip
19
23
  )
20
24
  end
21
25
  end
@@ -13,7 +13,28 @@ module Multicodecs
13
13
  REGISTRATIONS_PER_TAG = AutoHashCollection.new
14
14
  # rubocop:enable Style/MutableConstant
15
15
 
16
- Registration = Struct.new(:code, :name, :tag) do
16
+ class Registration
17
+ STATUS_DRAFT = 'draft'
18
+ STATUS_PERMANENT = 'permanent'
19
+
20
+ attr_reader :code, :tag, :name, :status, :description
21
+
22
+ def initialize(code:, name:, tag:, status:, description:)
23
+ self.code = code
24
+ self.name = name
25
+ self.tag = tag
26
+ self.status = status
27
+ self.description = description
28
+ end
29
+
30
+ def permanent?
31
+ status == STATUS_PERMANENT
32
+ end
33
+
34
+ def draft?
35
+ status == STATUS_DRAFT
36
+ end
37
+
17
38
  def hash
18
39
  name.hash
19
40
  end
@@ -28,6 +49,18 @@ module Multicodecs
28
49
  def eql?(other)
29
50
  other.is_a?(Registration) && other.name == name
30
51
  end
52
+
53
+ def to_s
54
+ "0x#{code.to_s(16)}"
55
+ end
56
+
57
+ def inspect
58
+ "#{to_s} #{name} (#{tag}/#{status}): #{description || '(no description)'}"
59
+ end
60
+
61
+ private
62
+
63
+ attr_writer :code, :tag, :name, :status, :description
31
64
  end
32
65
 
33
66
  module_function
@@ -36,8 +69,8 @@ module Multicodecs
36
69
  find_by(code: entry, name: entry)
37
70
  end
38
71
 
39
- def register(code:, name:, tag:)
40
- Registration.new(code, name, tag).tap do |registration|
72
+ def register(name:, tag:, **kwargs)
73
+ Registration.new(name: name, tag: tag, **kwargs).tap do |registration|
41
74
  Multicodecs::REGISTRATIONS[name] = registration
42
75
  Multicodecs::REGISTRATIONS_PER_TAG[tag] << registration
43
76
  end
@@ -51,6 +84,8 @@ module Multicodecs
51
84
  end
52
85
  end
53
86
 
87
+ alias find_by! fetch_by!
88
+
54
89
  def find_by(code: nil, name: nil)
55
90
  Multicodecs::REGISTRATIONS.values.find do |v|
56
91
  v == code || v == name
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Multicodecs
4
- VERSION = '0.2.1'
4
+ VERSION = '1.0.0'
5
5
  end