xlogin 0.12.2 → 0.12.3

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: a3f7355fe67c656f25da151d83442fbe6cdc9c2ae442e10550191230653991da
4
- data.tar.gz: b46b07acfdaea0ccbc0bff01dd27518ab4fdd1cd227a8654eb5be878b79ffe9f
3
+ metadata.gz: f7bce41012494be0a8efad4624674f5677a0830b7d3ebff88df664a2cbe5131e
4
+ data.tar.gz: 4f08a126e596f227ae6ff97361995ef48e3a588f2cf13746979cddf379851f32
5
5
  SHA512:
6
- metadata.gz: 6bfa4af5ffa2bdd7a56e751b0add6be766f481840b17a91779b7ade1b546745a1c46492c73ca63a5f3a83ef2a3a859aff4963480b0a2cdcf162ca1172211bcf4
7
- data.tar.gz: 3ce180fa56f5599937b52176366cac3a449c1d2a6cbc078861b3f7a8e8a3c1cc2f79738bd8d3a5a141121af707691127360b6efe3fb86ea3523d895a94be60fd
6
+ metadata.gz: 848c4161be59adabd9931374d26deec1e67efa9a0be44c50f58237c96c7c84857987213ea5c34ded3ca683e971dbdfa3e2bb68dd83e243286aac612c15833068
7
+ data.tar.gz: ab6627e2a78435ee709d19e8cb230ac9b3645da9fe991cbc879667e62355985efdbaf63a544afa9318ce12733b11c9ac5b58a372a113c1888386c0e9ddbb9ffa
data/lib/xlogin.rb CHANGED
@@ -20,6 +20,10 @@ module Xlogin
20
20
  factory.list_inventory(*patterns)
21
21
  end
22
22
 
23
+ def find(*patterns)
24
+ list(*patterns).first
25
+ end
26
+
23
27
  def get(args, **opts, &block)
24
28
  session = case args
25
29
  when Hash then factory.build(**args.merge(**opts))
@@ -57,32 +61,41 @@ module Xlogin
57
61
  @authorized = boolean == true || (block && block.call == true)
58
62
  end
59
63
 
60
- def source(*source_files, &block)
61
- return source_file(*source_files) unless block
62
- factory.instance_eval(&block) if source_files.empty?
63
- end
64
-
65
- def source_file(*source_files)
66
- source_files.compact.each do |file|
67
- raise SessionError.new("Inventory file not found: #{file}") unless File.exist?(file)
68
- factory.instance_eval(IO.read(file), file) if File.exist?(file)
64
+ def source(*sources, &block)
65
+ unless block
66
+ return sources.each do |path|
67
+ raise SessionError.new("Inventory file not found: #{path}") unless File.exist?(path)
68
+ factory.instance_eval(IO.read(path), path)
69
+ end
69
70
  end
71
+
72
+ factory.instance_eval(&block)
70
73
  end
71
74
 
72
- def template(name, *args, &block)
75
+ def template(*templates, **opts, &block)
73
76
  unless block
74
- return template_url(name, *args) if name =~ URI.regexp(['http', 'https'])
75
- return template_dir(name, *args)
77
+ templates.each do |template|
78
+ return template_url(template, **opts) if template =~ URI.regexp(['http', 'https'])
79
+ raise TemplateError.new("Template file or directory not found: #{template}") unless File.exist?(template)
80
+
81
+ files = [template] if File.file?(template)
82
+ files = Dir.glob(File.join(template, '*.rb')) if File.directory?(template)
83
+ files.each do |file|
84
+ name = opts[:type] || File.basename(file, '.rb').scan(/\w+/).join('_')
85
+ factory.set_template(name, IO.read(file))
86
+ end
87
+ end
76
88
  end
77
89
 
78
- raise ArgumentError.new('missing template name') unless name
90
+ name = opts[:type] || templates.first
91
+ raise ArgumentError.new('Missing template name') unless name
79
92
  factory.set_template(name, &block)
80
93
  end
81
94
 
82
- def template_url(*template_urls)
95
+ def template_url(*template_urls, **opts)
83
96
  template_urls.compact.each do |url|
84
97
  uri = URI(url.to_s)
85
- name = File.basename(uri.path, '.rb').scan(/\w+/).join('_')
98
+ name = opts[:type] || File.basename(uri.path, '.rb').scan(/\w+/).join('_')
86
99
  text = Net::HTTP.get(uri)
87
100
  if text =~ /\w+.rb$/
88
101
  uri.path = File.join(File.dirname(uri.path), text.lines.first.chomp)
@@ -92,19 +105,6 @@ module Xlogin
92
105
  end
93
106
  end
94
107
 
95
- def template_file(*template_files)
96
- template_files.compact.each do |file|
97
- raise TemplateError.new("Template file not found: #{file}") unless File.exist?(file)
98
- name = File.basename(file, '.rb').scan(/\w+/).join('_')
99
- factory.set_template(name, IO.read(file))
100
- end
101
- end
102
-
103
- def template_dir(*template_dirs)
104
- files = template_dirs.flat_map { |dir| Dir.glob(File.join(dir, '*.rb')) }
105
- template_file(*files)
106
- end
107
-
108
108
  end
109
109
 
110
110
  end
data/lib/xlogin/cli.rb CHANGED
@@ -47,7 +47,7 @@ module Xlogin
47
47
  Xlogin.configure do
48
48
  authorize(config.auth)
49
49
  source(File.expand_path(config.inventory, ENV['PWD']))
50
- template_dir(File.expand_path(config.template_dir, ENV['PWD']))
50
+ template(File.expand_path(config.template_dir, ENV['PWD']))
51
51
  end
52
52
 
53
53
  config.hosts = Xlogin.list(*args)
@@ -1,3 +1,3 @@
1
1
  module Xlogin
2
- VERSION = "0.12.2"
2
+ VERSION = "0.12.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlogin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - haccht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-26 00:00:00.000000000 Z
11
+ date: 2019-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-telnet