sconb 1.1.1 → 1.2.0

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
  SHA1:
3
- metadata.gz: 143b5ee22e1aec1cfa3abeda6d574e5184e79b74
4
- data.tar.gz: db168ab3f7df31ed9bf00fc70fb786550f9f24b3
3
+ metadata.gz: ce50a910176ca5f5dbd57e32d2bfc18cfe882f3e
4
+ data.tar.gz: 2c05c98bf6f70c777d3893f020642444bebaa07c
5
5
  SHA512:
6
- metadata.gz: 2194f42a4ff86c5f4f284709ae92e0d3f459277d055fd5bf4b2caf721e06cc4a1554a82a39cc18a1519a0544f358e8a99e84449e79594538dd5a2baded53cae6
7
- data.tar.gz: 4f0308b33c7d137d8168bb8622ff2a2146f6cc6c837e99e3e6819ac29259c80bf2c4245779ef53bbb364e8d9600dda4b603aea79082cd88658eec203d54fd4f6
6
+ metadata.gz: c28afe40de5c5089c6a10d5f1603c7370c0231dc891c25e54d783aeaecc9d390c94ab4e536a9a7ff0cce33158a5850ee243d3e993b357109f52cf70c633693a7
7
+ data.tar.gz: f19acd9534c333f70313eced8c4c9b16fdfcb60feb9b2037675a818f4691b0004dd664b7f1bc7b251b36d914e807569c81f82e55e17c881dfe77681ab8de072e
@@ -4,16 +4,15 @@ module Net
4
4
  class << self
5
5
  # Original code is Net::SSH::Config.load (https://github.com/net-ssh/net-ssh/blob/master/LICENSE.txt)
6
6
  # rubocop:disable all
7
- def load_with_key(path, host, options)
7
+ def parse_with_key(content, host, options)
8
8
  settings = {}
9
- file = File.expand_path(path)
10
- return settings unless File.readable?(file)
9
+ return settings unless content
11
10
 
12
11
  globals = {}
13
12
  matched_host = nil
14
13
  multi_host = []
15
14
  seen_host = false
16
- IO.foreach(file) do |line|
15
+ content.each_line do |line|
17
16
  next if line =~ /^\s*(?:#.*)?$/
18
17
 
19
18
  if line =~ /^\s*(\S+)\s*=(.*)$/
@@ -2,24 +2,28 @@ module Sconb
2
2
  module SSHConfig
3
3
  class << self
4
4
  def load(path, regexp_str = '.*', options = [])
5
- @path = path
5
+ file = File.expand_path(path)
6
+ content = File.readable?(file) ? File.open(file).read : nil
7
+ parse(content, regexp_str, options)
8
+ end
9
+
10
+ def parse(content, regexp_str = '.*', options = [])
6
11
  @regexp = Regexp.new(regexp_str)
7
12
  @options = options
8
- file = File.expand_path(@path)
13
+ @content = content
9
14
  @configs = {}
10
- return @configs unless File.readable?(file)
11
-
12
- @allconfig = Net::SSH::Config.load_with_key(@path, '*', @options)
15
+ return @configs if content.nil?
16
+ @allconfig = Net::SSH::Config.parse_with_key(@content, '*', @options)
13
17
  @configs['*'] = @allconfig unless @allconfig.size <= 1
14
- IO.foreach(file) do |line|
15
- parse(line)
18
+ @content.each_line do |line|
19
+ parse_line(line)
16
20
  end
17
21
  @configs
18
22
  end
19
23
 
20
24
  private
21
25
 
22
- def parse(line)
26
+ def parse_line(line)
23
27
  return if line =~ /^\s*(?:#.*)?$/
24
28
  if line =~ /^\s*(\S+)\s*=(.*)$/
25
29
  key = Regexp.last_match[1]
@@ -35,7 +39,7 @@ module Sconb
35
39
  positive_hosts.each do |host|
36
40
  next if host == '*'
37
41
  next unless host.match @regexp
38
- config = Net::SSH::Config.load_with_key(@path, host, @options)
42
+ config = Net::SSH::Config.parse_with_key(@content, host, @options)
39
43
 
40
44
  @allconfig.each do |k, _v|
41
45
  next unless config.key? k
@@ -50,7 +54,7 @@ module Sconb
50
54
  if key.downcase == 'match'
51
55
  match_key = key + ' ' + value
52
56
  return unless match_key.match @regexp
53
- @configs[match_key] = Net::SSH::Config.load_with_key(@path, value, @options)
57
+ @configs[match_key] = Net::SSH::Config.parse_with_key(@content, value, @options)
54
58
  end
55
59
  end
56
60
  end
data/lib/sconb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sconb
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sconb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW