multicodecs 0.1.0 → 0.2.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: 0cbc0820c14127379a2a107103b88cfa5201c3f22d3942adcf35f5f0a1cb22ae
4
- data.tar.gz: 59245217741f176d4b6c07095efa14bf1abf02dae2ef1b0accbe230611512b1a
3
+ metadata.gz: c00bbb236838d2e04b43906e147ba2c3572ccec437c4c50b58c74446a04a6c08
4
+ data.tar.gz: f6a5ecbb16cdf71dba833efe72b9f1b53585f590f56d1ad5b09ab6ac03939189
5
5
  SHA512:
6
- metadata.gz: c2bbbd3a0b3c79d2a1e5281142b3366b55156da6fb300869253366e1a35d37914462dacb74c66da6847c993dfa6816aeb86d8d54040d337f43aa1e1d22f68c31
7
- data.tar.gz: c9c3fc2b00c4cc40a23d1151454fe15235b8bedd0aaccecc3dc002071b3ce79fdba37b2331e9cfd92aedfa86a31f014b144ef5fe518543eddc2eeac3bb0e7a9e
6
+ metadata.gz: 226df7a1dcb3ab951fe86c15f13cb532619602c735455b5a0ee9902b7574e28baea8df7cb312efc3db03fea272a0d32444e87d460dccaa1867b84a00f4c93dcd
7
+ data.tar.gz: e61b4b1d0a58fe12145adc89787cc893e5508244f47ad8212c61b5c158fa0a9bdb543db150f2a046c191c0f4faed7f334844092d61ad4c309af0d4e14423d438
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in multicodecs.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -1,19 +1,25 @@
1
1
  # Multicodecs
2
2
 
3
- [![Build Status](https://travis-ci.com/SleeplessByte/ruby-multicodec.svg?token=FpDLv4Yva15pzqYpq9Hk&branch=master)][shield-link-travis]
3
+ [![Build Status](https://travis-ci.com/SleeplessByte/ruby-multicodec.svg?branch=master)][shield-link-travis]
4
4
  [![Gem Version](https://badge.fury.io/rb/multicodecs.svg)][shield-link-gem]
5
5
  [![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg)][shield-link-license]
6
- [![Maintainability](https://api.codeclimate.com/v1/badges/-/maintainability)][shield-link-codeclimate]
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/e5b0e892f0c098edd78c/maintainability)][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/repos/-/maintainability
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 the Shrine::ConfigurableStorage project’s codebases,
120
- issue trackers, chat rooms and mailing lists is expected to follow the
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 "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
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'), "wb") do |saved_file|
16
- open(SOURCE_FILE, "rb") do |read_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
@@ -1,14 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "multicodecs"
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 "pry"
11
+ # require 'pry'
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -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'] || row[1]
12
+ tag = row['tag'] || row[1]
13
13
  code = row['code'] || row[2]
14
14
 
15
- Multicodecs.register(name: name.strip, tag: tag.strip, code: code.strip.to_i(16))
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
@@ -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
- Multicodecs::REGISTRATIONS[name] = Registration.new(
33
- code,
34
- name,
35
- tag
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Multicodecs
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
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.1.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-06-20 00:00:00.000000000 Z
11
+ date: 2019-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler