Class: PickynodeBCHD

Inherits:
Object
  • Object
show all
Defined in:
lib/pickynode_bchd.rb

Overview

Allows you to easily add/remove/connect/disconnect nodes based on User Agent.

Constant Summary collapse

VERSION =
'0.2.2'

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ PickynodeBCHD

Returns a new instance of PickynodeBCHD.



14
15
16
# File 'lib/pickynode_bchd.rb', line 14

def initialize(opts = {})
  @opts = opts
end

Instance Method Details

#add(filter, limit = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pickynode_bchd.rb', line 18

def add(filter, limit = nil)
  return unless filter

  validate_limit(limit)

  blockchair_addr_types
    .select { |_, v| v.include?(filter) }
    .each_with_index do |(k, _), i|
      break if limit == i

      run_cmd(%(bchctl addnode "#{k}" add))
    end
end

#clear_cacheObject



92
93
94
95
# File 'lib/pickynode_bchd.rb', line 92

def clear_cache
  @addr_types = nil
  @blockchair_addr_types = nil
end

#connect(filter, limit = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pickynode_bchd.rb', line 46

def connect(filter, limit = nil)
  return unless filter

  validate_limit(limit)

  blockchair_addr_types
    .select { |_, v| v.include?(filter) }
    .each_with_index do |(k, _), i|
      break if limit == i

      run_cmd(%(bchctl node connect "#{k}"))
    end
end

#disconnect(filter, limit = nil) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pickynode_bchd.rb', line 60

def disconnect(filter, limit = nil)
  return unless filter

  validate_limit(limit)

  addr_types
    .select { |_, v| v.include?(filter) }
    .each_with_index do |(k, _), i|
      break if limit == i

      run_cmd(%(bchctl node disconnect "#{k}"))
    end
end

#displayObject



74
75
76
# File 'lib/pickynode_bchd.rb', line 74

def display
  ap addr_types
end

#infoObject



78
79
80
# File 'lib/pickynode_bchd.rb', line 78

def info
  ap getinfo
end

#remove(filter, limit = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/pickynode_bchd.rb', line 32

def remove(filter, limit = nil)
  return unless filter

  validate_limit(limit)

  addr_types
    .select { |_, v| v.include?(filter) }
    .each_with_index do |(k, _), i|
      break if limit == i

      run_cmd(%(bchctl node remove "#{k}"))
    end
end

#runObject



82
83
84
85
86
87
88
89
90
# File 'lib/pickynode_bchd.rb', line 82

def run
  add(@opts[:add], @opts[:limit])
  connect(@opts[:connect], @opts[:limit])

  remove(@opts[:remove], @opts[:limit])
  disconnect(@opts[:disconnect], @opts[:limit])

  display_info
end