multicodecs 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -9
- data/.travis.yml +7 -7
- data/.vscode/settings.json +7 -0
- data/CHANGELOG.md +28 -0
- data/Gemfile +4 -4
- data/README.md +143 -145
- data/Rakefile +22 -22
- data/bin/console +15 -15
- data/bin/setup +8 -8
- data/lib/multicodecs/bare.rb +8 -4
- data/lib/multicodecs/registry.rb +38 -3
- data/lib/multicodecs/version.rb +5 -5
- data/lib/multicodecs.rb +9 -9
- data/lib/table.csv +586 -423
- data/multicodecs.gemspec +48 -48
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf3dc42c444e7e1b15dfe8fd6687e5d32956fa86b46bcabb4609733bf05ff5f3
|
4
|
+
data.tar.gz: ffc283a7ee473362b89cadaf90841a967c5340fcdb36047f046af120da42c432
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b19f680c406fbabb5918243f6b959681d845dfe2416a334561c2c7cf059bb02c9edb58390cebba81fdb99a5d5c3385ad925d5d6380785210ba1298d8a3c79b1
|
7
|
+
data.tar.gz: 9b8d9da86ecf101230e4778a3c349b69f19a7856e4e04c88bc56f9c0868770118f93912059eb0d58d275c7f8e61a079b587e59134683c4ea74851f9ade5e724d
|
data/.gitignore
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/_yardoc/
|
4
|
-
/coverage/
|
5
|
-
/doc/
|
6
|
-
/pkg/
|
7
|
-
/spec/reports/
|
8
|
-
/tmp/
|
9
|
-
Gemfile.lock
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
Gemfile.lock
|
data/.travis.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
sudo: false
|
3
|
-
language: ruby
|
4
|
-
cache: bundler
|
5
|
-
rvm:
|
6
|
-
- 2.6.3
|
7
|
-
before_install: gem install bundler -v 2.0.1
|
1
|
+
---
|
2
|
+
sudo: false
|
3
|
+
language: ruby
|
4
|
+
cache: bundler
|
5
|
+
rvm:
|
6
|
+
- 2.6.3
|
7
|
+
before_install: gem install bundler -v 2.0.1
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 1.0.0
|
4
|
+
|
5
|
+
- Update multicodec table
|
6
|
+
- Implement `status` and `description`
|
7
|
+
- Remove `Struct` usage
|
8
|
+
|
9
|
+
## 0.2.1
|
10
|
+
|
11
|
+
- Fix deprecation warning in update rake task ([#3][pr-3])
|
12
|
+
- Update [multicodec table](https://github.com/SleeplessByte/ruby-multicodec/blob/master/lib/table.csv) ([#1][pr-1])
|
13
|
+
- Update dev dependency ([#2][pr-2])
|
14
|
+
|
15
|
+
[pr-1]: https://github.com/SleeplessByte/ruby-multicodec/pull/1
|
16
|
+
[pr-2]: https://github.com/SleeplessByte/ruby-multicodec/pull/2
|
17
|
+
[pr-3]: https://github.com/SleeplessByte/ruby-multicodec/pull/3
|
18
|
+
|
19
|
+
## 0.2.0
|
20
|
+
|
21
|
+
- Add tests for registry
|
22
|
+
- Add `where(tag:)` to create a _live_ sub selection of the registry
|
23
|
+
- Add `tags` to return the tags that exist
|
24
|
+
- Add `each(tag: nil)` to iterate the registry, optionally on a tag
|
25
|
+
|
26
|
+
## 0.1.0
|
27
|
+
|
28
|
+
:baby: initial release
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in multicodecs.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in multicodecs.gemspec
|
4
|
+
gemspec
|
data/README.md
CHANGED
@@ -1,145 +1,143 @@
|
|
1
|
-
# Multicodecs
|
2
|
-
|
3
|
-
[![Build Status](https://travis-ci.com/SleeplessByte/ruby-multicodec.svg?branch=master)][shield-link-travis]
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/multicodecs.svg)][shield-link-gem]
|
5
|
-
[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg)][shield-link-license]
|
6
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/e5b0e892f0c098edd78c/maintainability)][shield-link-codeclimate]
|
7
|
-
|
8
|
-
[shield-link-travis]: https://travis-ci.com/SleeplessByte/ruby-multicodec
|
9
|
-
[shield-link-gem]: https://badge.fury.io/rb/multicodecs
|
10
|
-
[shield-link-license]: http://opensource.org/licenses/MIT
|
11
|
-
[shield-link-codeclimate]: https://codeclimate.com/github/SleeplessByte/ruby-multicodec/maintainability
|
12
|
-
|
13
|
-
> Canonical table of of codecs used by various multiformats
|
14
|
-
|
15
|
-
`Multicodecs` is the ruby implementation of [multiformats/multicodec][spec].
|
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
|
-
|
23
|
-
## Installation
|
24
|
-
|
25
|
-
Add this line to your application's Gemfile:
|
26
|
-
|
27
|
-
```Ruby
|
28
|
-
gem 'multicodecs', require: false
|
29
|
-
```
|
30
|
-
|
31
|
-
Or if you want to autoload the last known table:
|
32
|
-
|
33
|
-
```Ruby
|
34
|
-
gem 'multicodecs'
|
35
|
-
```
|
36
|
-
|
37
|
-
Or if you want the PORO _without_ any values:
|
38
|
-
|
39
|
-
```Ruby
|
40
|
-
gem 'multicodecs', require: 'multicodecs/bare'
|
41
|
-
```
|
42
|
-
|
43
|
-
And then execute:
|
44
|
-
|
45
|
-
$ bundle
|
46
|
-
|
47
|
-
Or install it yourself as:
|
48
|
-
|
49
|
-
$ gem install multicodecs
|
50
|
-
|
51
|
-
## Usage
|
52
|
-
|
53
|
-
This is just a codec, not a protocol. This means that this gem only provides
|
54
|
-
a nice-to-use mapping from the [single source of truth][table] to a PORO. It
|
55
|
-
also allows you to bring your own values.
|
56
|
-
|
57
|
-
```ruby
|
58
|
-
require 'multicodecs'
|
59
|
-
|
60
|
-
Multicodecs['identity']
|
61
|
-
# =>
|
62
|
-
|
63
|
-
Multicodecs[0x12]
|
64
|
-
# =>
|
65
|
-
|
66
|
-
Multicodecs.find_by(name: 'protobuf')
|
67
|
-
# =>
|
68
|
-
```
|
69
|
-
|
70
|
-
You can `register` your own values
|
71
|
-
|
72
|
-
```ruby
|
73
|
-
Multicodecs.register(code: 0x12345, name: 'xxx', tag: 'vendor')
|
74
|
-
# =>
|
75
|
-
```
|
76
|
-
|
77
|
-
Convenience methods exist:
|
78
|
-
|
79
|
-
- `Multicodecs.names`: returns all the known names
|
80
|
-
- `Multicodecs.codes`: returns all the known codes
|
81
|
-
- `Multicodecs.find_by(code: nil, name: nil)`: same as `[]`
|
82
|
-
- `Multicodecs.fetch_by!(code: nil, name: nil)`: same as `[]` but errors if not found
|
83
|
-
- `Multicodecs.load_csv(csv, radix: 16)`: loads table.csv like data
|
84
|
-
|
85
|
-
## Related
|
86
|
-
|
87
|
-
- [`multiformats/multicodec`][git-multicodec]: the spec repository
|
88
|
-
- [`multiformats/ruby-multiaddr`][git-ruby-multiaddr]: the ruby implementation of [`multiformats/multiaddr`][git-multiaddr]
|
89
|
-
- [`multiformats/ruby-multibase`][git-ruby-multibase]: the ruby implementation of [`multiformats/multibase`][git-multibase]
|
90
|
-
- [`multiformats/ruby-multihash`][git-ruby-multihash]: the ruby implementation of [`multiformats/multihash`][git-multihash]
|
91
|
-
|
92
|
-
## Development
|
93
|
-
|
94
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
95
|
-
`rake test` to run the tests. You can also run `bin/console` for an interactive
|
96
|
-
prompt that will allow you to experiment.
|
97
|
-
|
98
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
99
|
-
To release a new version, update the version number in `version.rb`, and then
|
100
|
-
run `bundle exec rake release`, which will create a git tag for the version,
|
101
|
-
push git commits and tags, and push the `.gem` file to [rubygems.org][web-rubygems].
|
102
|
-
|
103
|
-
### Updating the table
|
104
|
-
|
105
|
-
The `Rakefile` provides an easy way of updating the `table.csv`, using a `rake`
|
106
|
-
command.
|
107
|
-
|
108
|
-
```ruby
|
109
|
-
rake update
|
110
|
-
# => updated lib/table.csv
|
111
|
-
```
|
112
|
-
|
113
|
-
## Contributing
|
114
|
-
|
115
|
-
Bug reports and pull requests are welcome on GitHub at [SleeplessByte/ruby-multicodec][git-self].
|
116
|
-
This project is intended to be a safe, welcoming space for collaboration, and
|
117
|
-
contributors are expected to adhere to the [Contributor Covenant][web-coc] code
|
118
|
-
of conduct.
|
119
|
-
|
120
|
-
## License
|
121
|
-
|
122
|
-
The gem is available as open source under the terms of the [MIT License][web-mit].
|
123
|
-
|
124
|
-
## Code of Conduct
|
125
|
-
|
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].
|
128
|
-
|
129
|
-
[spec]: https://github.com/multiformats/multicodec
|
130
|
-
[git-self-coc]: https://github.com/SleeplessByte/ruby-multibase/blob/master/CODE_OF_CONDUCT.md
|
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
|
134
|
-
[git-ruby-multicodec]: https://github.com/SleeplessByte/ruby-multicodec
|
135
|
-
[git-multicodec-table]: https://github.com/multiformats/multicodec/blob/master/multicodec.csv
|
136
|
-
[git-multicodec]: https://github.com/multiformats/multicodec
|
137
|
-
[git-ruby-multibase]: https://github.com/SleeplessByte/ruby-multibase
|
138
|
-
[git-multibase]: https://github.com/multiformats/multibase
|
139
|
-
[git-ruby-multihash]: https://github.com/multiformats/ruby-multihash
|
140
|
-
[git-multihash]: https://github.com/multiformats/multihash
|
141
|
-
[web-coc]: http://contributor-covenant.org
|
142
|
-
[web-mit]: https://opensource.org/licenses/MIT
|
143
|
-
[web-rubygems]: https://rubygems.org
|
144
|
-
|
145
|
-
|
1
|
+
# Multicodecs
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.com/SleeplessByte/ruby-multicodec.svg?branch=master)][shield-link-travis]
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/multicodecs.svg)][shield-link-gem]
|
5
|
+
[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg)][shield-link-license]
|
6
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/e5b0e892f0c098edd78c/maintainability)][shield-link-codeclimate]
|
7
|
+
|
8
|
+
[shield-link-travis]: https://travis-ci.com/SleeplessByte/ruby-multicodec
|
9
|
+
[shield-link-gem]: https://badge.fury.io/rb/multicodecs
|
10
|
+
[shield-link-license]: http://opensource.org/licenses/MIT
|
11
|
+
[shield-link-codeclimate]: https://codeclimate.com/github/SleeplessByte/ruby-multicodec/maintainability
|
12
|
+
|
13
|
+
> Canonical table of of codecs used by various multiformats
|
14
|
+
|
15
|
+
`Multicodecs` is the ruby implementation of [multiformats/multicodec][spec].
|
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
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
```Ruby
|
28
|
+
gem 'multicodecs', require: false
|
29
|
+
```
|
30
|
+
|
31
|
+
Or if you want to autoload the last known table:
|
32
|
+
|
33
|
+
```Ruby
|
34
|
+
gem 'multicodecs'
|
35
|
+
```
|
36
|
+
|
37
|
+
Or if you want the PORO _without_ any values:
|
38
|
+
|
39
|
+
```Ruby
|
40
|
+
gem 'multicodecs', require: 'multicodecs/bare'
|
41
|
+
```
|
42
|
+
|
43
|
+
And then execute:
|
44
|
+
|
45
|
+
$ bundle
|
46
|
+
|
47
|
+
Or install it yourself as:
|
48
|
+
|
49
|
+
$ gem install multicodecs
|
50
|
+
|
51
|
+
## Usage
|
52
|
+
|
53
|
+
This is just a codec, not a protocol. This means that this gem only provides
|
54
|
+
a nice-to-use mapping from the [single source of truth][table] to a PORO. It
|
55
|
+
also allows you to bring your own values.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
require 'multicodecs'
|
59
|
+
|
60
|
+
Multicodecs['identity']
|
61
|
+
# => 0x0 identity (multihash/permanent): raw binary
|
62
|
+
|
63
|
+
Multicodecs[0x12]
|
64
|
+
# => 0x12 sha2-256 (multihash/permanent): (no description)
|
65
|
+
|
66
|
+
Multicodecs.find_by(name: 'protobuf')
|
67
|
+
# => 0x50 protobuf (serialization/draft): Protocol Buffers
|
68
|
+
```
|
69
|
+
|
70
|
+
You can `register` your own values
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
Multicodecs.register(code: 0x12345, name: 'xxx', tag: 'vendor', status: 'draft', description: nil)
|
74
|
+
# => 0x12345 xxx (vendor/draft): (no description)
|
75
|
+
```
|
76
|
+
|
77
|
+
Convenience methods exist:
|
78
|
+
|
79
|
+
- `Multicodecs.names`: returns all the known names
|
80
|
+
- `Multicodecs.codes`: returns all the known codes
|
81
|
+
- `Multicodecs.find_by(code: nil, name: nil)`: same as `[]`
|
82
|
+
- `Multicodecs.fetch_by!(code: nil, name: nil)`: same as `[]` but errors if not found
|
83
|
+
- `Multicodecs.load_csv(csv, radix: 16)`: loads table.csv like data
|
84
|
+
|
85
|
+
## Related
|
86
|
+
|
87
|
+
- [`multiformats/multicodec`][git-multicodec]: the spec repository
|
88
|
+
- [`multiformats/ruby-multiaddr`][git-ruby-multiaddr]: the ruby implementation of [`multiformats/multiaddr`][git-multiaddr]
|
89
|
+
- [`multiformats/ruby-multibase`][git-ruby-multibase]: the ruby implementation of [`multiformats/multibase`][git-multibase]
|
90
|
+
- [`multiformats/ruby-multihash`][git-ruby-multihash]: the ruby implementation of [`multiformats/multihash`][git-multihash]
|
91
|
+
|
92
|
+
## Development
|
93
|
+
|
94
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
95
|
+
`rake test` to run the tests. You can also run `bin/console` for an interactive
|
96
|
+
prompt that will allow you to experiment.
|
97
|
+
|
98
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
99
|
+
To release a new version, update the version number in `version.rb`, and then
|
100
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
101
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org][web-rubygems].
|
102
|
+
|
103
|
+
### Updating the table
|
104
|
+
|
105
|
+
The `Rakefile` provides an easy way of updating the `table.csv`, using a `rake`
|
106
|
+
command.
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
rake update
|
110
|
+
# => updated lib/table.csv
|
111
|
+
```
|
112
|
+
|
113
|
+
## Contributing
|
114
|
+
|
115
|
+
Bug reports and pull requests are welcome on GitHub at [SleeplessByte/ruby-multicodec][git-self].
|
116
|
+
This project is intended to be a safe, welcoming space for collaboration, and
|
117
|
+
contributors are expected to adhere to the [Contributor Covenant][web-coc] code
|
118
|
+
of conduct.
|
119
|
+
|
120
|
+
## License
|
121
|
+
|
122
|
+
The gem is available as open source under the terms of the [MIT License][web-mit].
|
123
|
+
|
124
|
+
## Code of Conduct
|
125
|
+
|
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].
|
128
|
+
|
129
|
+
[spec]: https://github.com/multiformats/multicodec
|
130
|
+
[git-self-coc]: https://github.com/SleeplessByte/ruby-multibase/blob/master/CODE_OF_CONDUCT.md
|
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
|
134
|
+
[git-ruby-multicodec]: https://github.com/SleeplessByte/ruby-multicodec
|
135
|
+
[git-multicodec-table]: https://github.com/multiformats/multicodec/blob/master/multicodec.csv
|
136
|
+
[git-multicodec]: https://github.com/multiformats/multicodec
|
137
|
+
[git-ruby-multibase]: https://github.com/SleeplessByte/ruby-multibase
|
138
|
+
[git-multibase]: https://github.com/multiformats/multibase
|
139
|
+
[git-ruby-multihash]: https://github.com/multiformats/ruby-multihash
|
140
|
+
[git-multihash]: https://github.com/multiformats/multihash
|
141
|
+
[web-coc]: http://contributor-covenant.org
|
142
|
+
[web-mit]: https://opensource.org/licenses/MIT
|
143
|
+
[web-rubygems]: https://rubygems.org
|
data/Rakefile
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
2
|
-
require 'rake/testtask'
|
3
|
-
|
4
|
-
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs << 'test'
|
6
|
-
t.libs << 'lib'
|
7
|
-
t.test_files = FileList['test/**/*_test.rb']
|
8
|
-
end
|
9
|
-
|
10
|
-
Rake::Task.define_task(:update) do |t|
|
11
|
-
require 'open-uri'
|
12
|
-
|
13
|
-
SOURCE_FILE = 'https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv'
|
14
|
-
|
15
|
-
File.open(File.join(__dir__, 'lib', 'table.csv'), 'wb') do |saved_file|
|
16
|
-
open(SOURCE_FILE, 'rb') do |read_file|
|
17
|
-
saved_file.write(read_file.read)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
task :default => :test
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << 'test'
|
6
|
+
t.libs << 'lib'
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
|
+
end
|
9
|
+
|
10
|
+
Rake::Task.define_task(:update) do |t|
|
11
|
+
require 'open-uri'
|
12
|
+
|
13
|
+
SOURCE_FILE = 'https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv'
|
14
|
+
|
15
|
+
File.open(File.join(__dir__, 'lib', 'table.csv'), 'wb') do |saved_file|
|
16
|
+
URI.open(SOURCE_FILE, 'rb') do |read_file|
|
17
|
+
saved_file.write(read_file.read)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
task :default => :test
|
data/bin/console
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'bundler/setup'
|
5
|
-
require 'multicodecs'
|
6
|
-
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
9
|
-
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
-
# require 'pry'
|
12
|
-
# Pry.start
|
13
|
-
|
14
|
-
require 'irb'
|
15
|
-
IRB.start(__FILE__)
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'multicodecs'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require 'pry'
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install
|
7
|
-
|
8
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
7
|
+
|
8
|
+
# Do any other automated setup that you need to do here
|
data/lib/multicodecs/bare.rb
CHANGED
@@ -8,14 +8,18 @@ module Multicodecs
|
|
8
8
|
|
9
9
|
def load_csv(csv, radix: 16)
|
10
10
|
csv.each do |row|
|
11
|
-
name
|
12
|
-
tag
|
13
|
-
code
|
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
|
data/lib/multicodecs/registry.rb
CHANGED
@@ -13,7 +13,28 @@ module Multicodecs
|
|
13
13
|
REGISTRATIONS_PER_TAG = AutoHashCollection.new
|
14
14
|
# rubocop:enable Style/MutableConstant
|
15
15
|
|
16
|
-
Registration
|
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(
|
40
|
-
Registration.new(
|
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
|
data/lib/multicodecs/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Multicodecs
|
4
|
-
VERSION = '0.
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Multicodecs
|
4
|
+
VERSION = '1.0.0'
|
5
|
+
end
|
data/lib/multicodecs.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'multicodecs/version'
|
4
|
-
require 'multicodecs/bare'
|
5
|
-
require 'csv'
|
6
|
-
|
7
|
-
module Multicodecs
|
8
|
-
load_csv CSV.open(File.join(__dir__, 'table.csv'), headers: true)
|
9
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'multicodecs/version'
|
4
|
+
require 'multicodecs/bare'
|
5
|
+
require 'csv'
|
6
|
+
|
7
|
+
module Multicodecs
|
8
|
+
load_csv CSV.open(File.join(__dir__, 'table.csv'), headers: true)
|
9
|
+
end
|