nchan_tools 0.1.9 → 0.1.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec4e4cc624f57a6d6a6684bf71db8d75b58a4e2e823e258490b9be66eb5de396
4
- data.tar.gz: bea9e679190cff5749804e8f8e3ef14ca825edd197ef0381d4c8225f87a07ca8
3
+ metadata.gz: e17f44cb591b9f74d1791e1f9ec8574613fbc840c6aac91953c8a526a8a63006
4
+ data.tar.gz: 405aabdbc70b14571c6cc545ca13f0ea7e5ad65b130ab37194fee1ed7ccf7d5c
5
5
  SHA512:
6
- metadata.gz: 38c2d66f98c4eb30a48968197d16513ba080d68bdaf417f884fd4af72f7d63ab0788c46554d636f1a5e6c344861e7c08d885432e9e5e6d44cdb0bd1b630bc4de
7
- data.tar.gz: 02fb75182dacf15033c6d5fe3b0191b9c62063aec06fe67942ba2b6c0559368ce86af93b0ab507f3924e524a180e6bed9b2a7dd7b77fbdeca3af702abb141807
6
+ metadata.gz: 31e391ad81b9a43519d014a538f77b87b25706a009180b83239eea014c174497d8d7e3c9ca26d173b075cd42cba4e82ab92dc696ce459058080a325c29f808e3
7
+ data.tar.gz: 66654049eaf6f7f26e16fd98df88b1570a5d80f7168cc2f774e5d7168ae4d42a668b1384c3280fd82b8473f78e63ec4774b005f9971be4db7e9a2d4d65a01264
@@ -4,25 +4,26 @@ require "redis"
4
4
  require "optparse"
5
5
  require 'nchan_tools/rdsck'
6
6
 
7
- $opt = {
7
+ opt = {
8
8
  url: "redis://127.0.0.1:6379/",
9
9
  verbose: false,
10
10
  command: nil
11
11
  }
12
12
 
13
13
  opt_parser=OptionParser.new do |opts|
14
- opts.on("--url", "--url REDIS_URL (#{$opt[:url]})", "Redis server and port..") do |v|
15
- $opt[:url]=v
14
+ opts.on("--url", "--url REDIS_URL (#{opt[:url]})", "Redis server and port..") do |v|
15
+ opt[:url]=v
16
16
  end
17
17
  opts.on("-q", "--quiet", "output only results without any other information") do
18
- $opt[:quiet]=false
18
+ opt[:quiet]=false
19
+ opts[:verbose] = !opt[:quiet]
19
20
  end
20
21
  opts.on("--list-channels", "list all Nchan channels on Redis server or cluster") do |v|
21
- $opt[:command]=:filter_channels
22
+ opt[:command]=:filter_channels
22
23
  end
23
24
  opts.on("--filter-channels-min-subscribers=[NUMBER]") do |v|
24
- $opt[:command]=:filter_channels
25
- $opt[:min_subscribers]=v.to_i
25
+ opt[:command]=:filter_channels
26
+ opt[:min_subscribers]=v.to_i
26
27
  end
27
28
  end
28
29
  opt_parser.banner= <<~EOB
@@ -39,16 +40,16 @@ opt_parser.banner= <<~EOB
39
40
  EOB
40
41
  opt_parser.parse!
41
42
 
42
- rdsck = Rdsck.new $opt
43
+ rdsck = Rdsck.new opt
43
44
  if not rdsck.connect
44
- STDERR.puts "failed to connect to #{$opt[:url]}"
45
+ STDERR.puts "failed to connect to #{opt[:url]}"
45
46
  exit 1
46
47
  end
47
48
 
48
- case $opt[:command]
49
+ case opt[:command]
49
50
  when :filter_channels
50
- puts "# scanning for channels #{$opt[:min_subscribers] && "with subscribers >= #{$opt[:min_subscribers]}"}"
51
- chans = rdsck.filter_channels(min_subscribers: $opt[:min_subscribers])
51
+ puts "# scanning for channels #{opt[:min_subscribers] && "with subscribers >= #{opt[:min_subscribers]}"}"
52
+ chans = rdsck.filter_channels(min_subscribers: opt[:min_subscribers])
52
53
  puts "# found #{chans.count} channel#{chans.count != 1 && "s"}#{chans.count == 0 ? "." : ":"}"
53
54
  puts chans.join("\n")
54
55
  else
@@ -3,7 +3,7 @@ class Rdsck
3
3
  attr_accessor :redis, :masters
4
4
 
5
5
  def dbg(*args)
6
- if $opt[:verbose]
6
+ if @verbose
7
7
  print("# ")
8
8
  puts(*args)
9
9
  end
@@ -13,6 +13,7 @@ class Rdsck
13
13
  @url=opt[:url]
14
14
  @verbose=opt[:verbose]
15
15
  @namespace=opt[:namespace]
16
+ @channel_id=opt[:channel_id]
16
17
  end
17
18
 
18
19
  def cluster?
@@ -21,7 +22,7 @@ class Rdsck
21
22
 
22
23
  def connect
23
24
  begin
24
- @redis=Redis.new url: $opt[:url]
25
+ @redis=Redis.new url: @url
25
26
  mode = redis.info["redis_mode"]
26
27
  rescue StandardError => e
27
28
  STDERR.puts e.message
@@ -31,7 +32,7 @@ class Rdsck
31
32
  if mode == "cluster"
32
33
  @redis.close
33
34
  begin
34
- @redis=Redis.new cluster: [$opt[:url]]
35
+ @redis=Redis.new cluster: [@url]
35
36
  @redis.ping
36
37
  rescue StandardError => e
37
38
  STDERR.puts e.message
@@ -57,7 +58,7 @@ class Rdsck
57
58
  end
58
59
 
59
60
  def key(subkey=nil)
60
- k = "{channel:#{$opt[:namespace]}/#{$opt[:channel_id]}}"
61
+ k = "{channel:#{@namespace}/#{@channel_id}}"
61
62
  return subkey ? "#{k}:#{subkey}" : k
62
63
  end
63
64
 
@@ -1,3 +1,3 @@
1
1
  module NchanTools
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nchan_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leo Ponomarev