multicodecs 0.1.0 → 0.2.0
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 +4 -4
- data/Gemfile +1 -1
- data/README.md +14 -6
- data/Rakefile +7 -7
- data/bin/console +5 -4
- data/lib/multicodecs/bare.rb +6 -2
- data/lib/multicodecs/registry.rb +30 -5
- data/lib/multicodecs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c00bbb236838d2e04b43906e147ba2c3572ccec437c4c50b58c74446a04a6c08
|
|
4
|
+
data.tar.gz: f6a5ecbb16cdf71dba833efe72b9f1b53585f590f56d1ad5b09ab6ac03939189
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 226df7a1dcb3ab951fe86c15f13cb532619602c735455b5a0ee9902b7574e28baea8df7cb312efc3db03fea272a0d32444e87d460dccaa1867b84a00f4c93dcd
|
|
7
|
+
data.tar.gz: e61b4b1d0a58fe12145adc89787cc893e5508244f47ad8212c61b5c158fa0a9bdb543db150f2a046c191c0f4faed7f334844092d61ad4c309af0d4e14423d438
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
# Multicodecs
|
|
2
2
|
|
|
3
|
-
[][shield-link-travis]
|
|
4
4
|
[][shield-link-gem]
|
|
5
5
|
[][shield-link-license]
|
|
6
|
-
[][shield-link-codeclimate]
|
|
7
7
|
|
|
8
8
|
[shield-link-travis]: https://travis-ci.com/SleeplessByte/ruby-multicodec
|
|
9
9
|
[shield-link-gem]: https://badge.fury.io/rb/multicodecs
|
|
10
10
|
[shield-link-license]: http://opensource.org/licenses/MIT
|
|
11
|
-
[shield-link-codeclimate]: https://codeclimate.com/
|
|
11
|
+
[shield-link-codeclimate]: https://codeclimate.com/github/SleeplessByte/ruby-multicodec/maintainability
|
|
12
12
|
|
|
13
13
|
> Canonical table of of codecs used by various multiformats
|
|
14
14
|
|
|
15
15
|
`Multicodecs` is the ruby implementation of [multiformats/multicodec][spec].
|
|
16
16
|
|
|
17
|
+
> 🙌🏽 This is called `multicodecs` instead of the singular form, to stay
|
|
18
|
+
> consistent with the `multihashes` gem, which was _forced_ to take a different
|
|
19
|
+
> name has `multihash` was already taken, which is also the case for `multibase`
|
|
20
|
+
> and others. In the future, this might be renamed to `multiformats-codec`, with
|
|
21
|
+
> a backwards-compatible interface.
|
|
22
|
+
|
|
17
23
|
## Installation
|
|
18
24
|
|
|
19
25
|
Add this line to your application's Gemfile:
|
|
@@ -79,6 +85,7 @@ Convenience methods exist:
|
|
|
79
85
|
## Related
|
|
80
86
|
|
|
81
87
|
- [`multiformats/multicodec`][git-multicodec]: the spec repository
|
|
88
|
+
- [`multiformats/ruby-multiaddr`][git-ruby-multiaddr]: the ruby implementation of [`multiformats/multiaddr`][git-multiaddr]
|
|
82
89
|
- [`multiformats/ruby-multibase`][git-ruby-multibase]: the ruby implementation of [`multiformats/multibase`][git-multibase]
|
|
83
90
|
- [`multiformats/ruby-multihash`][git-ruby-multihash]: the ruby implementation of [`multiformats/multihash`][git-multihash]
|
|
84
91
|
|
|
@@ -116,13 +123,14 @@ The gem is available as open source under the terms of the [MIT License][web-mit
|
|
|
116
123
|
|
|
117
124
|
## Code of Conduct
|
|
118
125
|
|
|
119
|
-
Everyone interacting in
|
|
120
|
-
|
|
121
|
-
[code of conduct][git-self-coc].
|
|
126
|
+
Everyone interacting in this project’s codebases, issue trackers, chat rooms and
|
|
127
|
+
mailing lists is expected to follow the [code of conduct][git-self-coc].
|
|
122
128
|
|
|
123
129
|
[spec]: https://github.com/multiformats/multicodec
|
|
124
130
|
[git-self-coc]: https://github.com/SleeplessByte/ruby-multibase/blob/master/CODE_OF_CONDUCT.md
|
|
125
131
|
[git-self]: https://github.com/SleeplessByte/ruby-multibase
|
|
132
|
+
[git-ruby-multiaddr]: https://github.com/SleeplessByte/ruby-multiaddr
|
|
133
|
+
[git-multiaddr]: https://github.com/multiformats/multiaddr
|
|
126
134
|
[git-ruby-multicodec]: https://github.com/SleeplessByte/ruby-multicodec
|
|
127
135
|
[git-multicodec-table]: https://github.com/multiformats/multicodec/blob/master/multicodec.csv
|
|
128
136
|
[git-multicodec]: https://github.com/multiformats/multicodec
|
data/Rakefile
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
2
|
+
require 'rake/testtask'
|
|
3
3
|
|
|
4
4
|
Rake::TestTask.new(:test) do |t|
|
|
5
|
-
t.libs <<
|
|
6
|
-
t.libs <<
|
|
7
|
-
t.test_files = FileList[
|
|
5
|
+
t.libs << 'test'
|
|
6
|
+
t.libs << 'lib'
|
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
Rake::Task.define_task(:update) do |t|
|
|
@@ -12,8 +12,8 @@ Rake::Task.define_task(:update) do |t|
|
|
|
12
12
|
|
|
13
13
|
SOURCE_FILE = 'https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv'
|
|
14
14
|
|
|
15
|
-
File.open(File.join(__dir__, 'lib', 'table.csv'),
|
|
16
|
-
open(SOURCE_FILE,
|
|
15
|
+
File.open(File.join(__dir__, 'lib', 'table.csv'), 'wb') do |saved_file|
|
|
16
|
+
open(SOURCE_FILE, 'rb') do |read_file|
|
|
17
17
|
saved_file.write(read_file.read)
|
|
18
18
|
end
|
|
19
19
|
end
|
data/bin/console
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'multicodecs'
|
|
5
6
|
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
|
8
9
|
|
|
9
10
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
-
# require
|
|
11
|
+
# require 'pry'
|
|
11
12
|
# Pry.start
|
|
12
13
|
|
|
13
|
-
require
|
|
14
|
+
require 'irb'
|
|
14
15
|
IRB.start(__FILE__)
|
data/lib/multicodecs/bare.rb
CHANGED
|
@@ -9,10 +9,14 @@ module Multicodecs
|
|
|
9
9
|
def load_csv(csv, radix: 16)
|
|
10
10
|
csv.each do |row|
|
|
11
11
|
name = row['name'] || row[0]
|
|
12
|
-
tag = row['tag']
|
|
12
|
+
tag = row['tag'] || row[1]
|
|
13
13
|
code = row['code'] || row[2]
|
|
14
14
|
|
|
15
|
-
Multicodecs.register(
|
|
15
|
+
Multicodecs.register(
|
|
16
|
+
name: name.strip,
|
|
17
|
+
tag: tag.strip,
|
|
18
|
+
code: code.strip.to_i(16)
|
|
19
|
+
)
|
|
16
20
|
end
|
|
17
21
|
end
|
|
18
22
|
end
|
data/lib/multicodecs/registry.rb
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Multicodecs
|
|
4
|
+
class AutoHashCollection < Hash
|
|
5
|
+
def [](key)
|
|
6
|
+
self[key] = [] unless key?(key)
|
|
7
|
+
super
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
4
11
|
# rubocop:disable Style/MutableConstant
|
|
5
12
|
REGISTRATIONS = {}
|
|
13
|
+
REGISTRATIONS_PER_TAG = AutoHashCollection.new
|
|
6
14
|
# rubocop:enable Style/MutableConstant
|
|
7
15
|
|
|
8
16
|
Registration = Struct.new(:code, :name, :tag) do
|
|
@@ -29,11 +37,10 @@ module Multicodecs
|
|
|
29
37
|
end
|
|
30
38
|
|
|
31
39
|
def register(code:, name:, tag:)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
)
|
|
40
|
+
Registration.new(code, name, tag).tap do |registration|
|
|
41
|
+
Multicodecs::REGISTRATIONS[name] = registration
|
|
42
|
+
Multicodecs::REGISTRATIONS_PER_TAG[tag] << registration
|
|
43
|
+
end
|
|
37
44
|
end
|
|
38
45
|
|
|
39
46
|
def fetch_by!(code: nil, name: nil)
|
|
@@ -57,4 +64,22 @@ module Multicodecs
|
|
|
57
64
|
def names
|
|
58
65
|
Multicodecs::REGISTRATIONS.keys
|
|
59
66
|
end
|
|
67
|
+
|
|
68
|
+
def tags
|
|
69
|
+
Multicodecs::REGISTRATIONS_PER_TAG.keys
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def where(tag:)
|
|
73
|
+
Multicodecs::REGISTRATIONS_PER_TAG[tag]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def each(tag: nil)
|
|
77
|
+
arr = tag.nil? ? Multicodecs::REGISTRATIONS.values : Multicodecs.where(tag: tag)
|
|
78
|
+
|
|
79
|
+
if block_given?
|
|
80
|
+
return arr.each { |registration| yield registration }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
arr.each
|
|
84
|
+
end
|
|
60
85
|
end
|
data/lib/multicodecs/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: multicodecs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Derk-Jan Karrenbeld
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-07-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|