uri-ni 0.1.2 → 0.1.5

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: e205294ee6b137c97fca41dfe3017b8fcfe41e28ba949002ba00167d216c3dd8
4
- data.tar.gz: d81cbabc67dc1ed564d790232011119e1b3eec87044531680e6db77f2bc728a6
3
+ metadata.gz: ee2d458c5f63ebc9a63552bc94b0141052952a2729b4647a0d5d5b43859288a4
4
+ data.tar.gz: 21201a539b63b90db525760e20087b37c77167fd054b75bc38d1625dfd0fedd7
5
5
  SHA512:
6
- metadata.gz: 85745faf2e879e90a233f60f937b9f55adcfcca2cb06e4871ebfab119ba98bc88517b8907baafb50412cbdd6af7342dbdadc1f0652382ad96a614cd64084b56c
7
- data.tar.gz: fe3bd0a1fef2939489dc31dc463e7038f632a771f0d9feb17b72617c37bc19cfae78eb19d304b7f06f85694114ea6cafb34d0065e664147c9516bd0078cfe97e
6
+ metadata.gz: 78679d956ad359ca94076ed41d148708c1fe4e8b79afe3cbaf144e3e874b20ae0d90d390414a58ab17b9152944b1ae3147e3e3478f9bc07e111a198ed7039ea5
7
+ data.tar.gz: 832ac38552ef80eccad02eb739da1471ad23c9c0aaa01b570ad2ffd829649ec93c02ee7b961d220e29ce06ad9858af322f829601e9a62da6a36d46bff8966eab
data/exe/ni-uri ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: enh-ruby -*-
3
+
4
+ require 'uri/ni'
5
+ require 'pathname'
6
+ require 'optparse'
7
+
8
+ options = {}
9
+ op = OptionParser.new do |opts|
10
+ opts.banner = "Usage: ni-uri [options] FILES"
11
+
12
+ opts.on("-a", "--algorithm STRING", "algorithm") do |a|
13
+ options[:algorithm] = a.to_sym
14
+ end
15
+ end
16
+
17
+ op.parse!
18
+
19
+ options[:algorithm] ||= :"sha-256"
20
+ unless URI::NI.valid_algo? options[:algorithm]
21
+ $stderr.puts "#{options[:algorithm]} is not a valid algorithm"
22
+ exit 1
23
+ end
24
+
25
+ if ARGV.empty?
26
+ puts op.to_s
27
+ exit 1
28
+ end
29
+
30
+ ARGV.each do |fn|
31
+ fn = Pathname(fn).expand_path
32
+ begin
33
+ fh = fn.open
34
+ ni = URI::NI.compute fh, algorithm: options[:algorithm]
35
+ puts ni.to_s
36
+ rescue SystemCallError => e
37
+ $stderr.puts "Could not compute digest for #{fn}: #{e.message}"
38
+ next
39
+ end
40
+ end
@@ -3,9 +3,13 @@ require 'uri/generic'
3
3
 
4
4
  module URI
5
5
  class NI < Generic
6
- VERSION = "0.1.2"
6
+ VERSION = "0.1.5"
7
7
  end
8
8
 
9
9
  # might as well put this here
10
- @@schemes['NI'] = NI
10
+ if self.respond_to? :register_scheme
11
+ register_scheme 'NI', NI
12
+ else
13
+ @@schemes['NI'] = NI
14
+ end
11
15
  end
data/lib/uri/ni.rb CHANGED
@@ -186,7 +186,7 @@ class URI::NI < URI::Generic
186
186
  # @raise [ArgumentError] if the algorithm is unrecognized
187
187
  def self.context algorithm
188
188
  raise ArgumentError, "Cannot coerce #{algorithm} to a symbol" unless
189
- algorithm.respond_to(:to_s) # cheat: symbols respond to to_s
189
+ algorithm.respond_to? :to_s # cheat: symbols respond to to_s
190
190
  algorithm = algorithm.to_s.to_sym unless algorithm.is_a? Symbol
191
191
  raise ArgumentError, "Unsupported digest algorithm #{algorithm}" unless
192
192
  ctx = DIGESTS[algorithm]
@@ -475,4 +475,16 @@ class URI::NI < URI::Generic
475
475
  to_www https: false, authority: authority
476
476
  end
477
477
 
478
+ # Returns the set of supported algorithms.
479
+ # @return [Array] the algorithms
480
+ def self.algorithms
481
+ DIGESTS.keys
482
+ end
483
+
484
+ # Returns true if the algorithm is supported.
485
+ # @param algorithm [Symbol,String] the algorithm identifier to test
486
+ # @return [true, false] whether it is supported
487
+ def self.valid_algo? algorithm
488
+ DIGESTS.has_key? algorithm.to_s.downcase.to_sym
489
+ end
478
490
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri-ni
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Taylor
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-17 00:00:00.000000000 Z
11
+ date: 2023-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -41,7 +41,8 @@ dependencies:
41
41
  description: ''
42
42
  email:
43
43
  - code@doriantaylor.com
44
- executables: []
44
+ executables:
45
+ - ni-uri
45
46
  extensions: []
46
47
  extra_rdoc_files: []
47
48
  files:
@@ -54,6 +55,7 @@ files:
54
55
  - Rakefile
55
56
  - bin/console
56
57
  - bin/setup
58
+ - exe/ni-uri
57
59
  - lib/uri-ni.rb
58
60
  - lib/uri/ni.rb
59
61
  - lib/uri/ni/version.rb
@@ -63,7 +65,7 @@ licenses:
63
65
  - Apache-2.0
64
66
  metadata:
65
67
  homepage_uri: https://github.com/doriantaylor/rb-uri-ni
66
- post_install_message:
68
+ post_install_message:
67
69
  rdoc_options: []
68
70
  require_paths:
69
71
  - lib
@@ -78,8 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
80
  - !ruby/object:Gem::Version
79
81
  version: '0'
80
82
  requirements: []
81
- rubygems_version: 3.1.2
82
- signing_key:
83
+ rubygems_version: 3.3.15
84
+ signing_key:
83
85
  specification_version: 4
84
86
  summary: URI handler for RFC6920 ni:/// URIs
85
87
  test_files: []