Module: Net::SSH::Xlogin
- Defined in:
- lib/net/ssh/xlogin/version.rb,
lib/net/ssh/xlogin/template.rb,
lib/net/ssh/xlogin/connection.rb,
lib/net/ssh/xlogin/factory.rb,
lib/net/ssh/xlogin.rb
Defined Under Namespace
Classes: Connection, Error, Factory, Template
Constant Summary
collapse
- VERSION =
'0.2.6'
Class Method Summary
collapse
Class Method Details
30
31
32
|
# File 'lib/net/ssh/xlogin.rb', line 30
def configure(&block)
instance_eval(&block)
end
|
.get(name, **opts, &block) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/net/ssh/xlogin.rb', line 10
def get(name, **opts, &block)
begin
opts = factory.inventory[name].merge(opts)
type = opts[:type]
template = factory.templates[type]
session = template.build(name, **opts)
return session unless block
yield session
rescue => err
raise Error.new(err)
ensure
session.close rescue nil
end
end
|
.list(**query) ⇒ Object
26
27
28
|
# File 'lib/net/ssh/xlogin.rb', line 26
def list(**query)
factory.query(query)
end
|
.source(*args) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/net/ssh/xlogin.rb', line 34
def source(*args)
args.each do |src|
src = case src
when /\.y(a)?ml$/
factory.yaml(src)
when String
if File.exist?(src)
factory.dsl(IO.read(src))
else
factory.dsl(src)
end
when Hash
name = src.delete(:host)
factory.set_source(name, **src)
end
end
end
|
.template(*templates, **opts, &block) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/net/ssh/xlogin.rb', line 52
def template(*templates, **opts, &block)
name = opts[:type]
if block
template = factory.templates[name] || Template.new(name)
template.instance_eval(&block)
factory.templates[name] = template
return
end
templates = templates.map{|path| Dir.exist?(path) ? Dir.glob(File.join(path, '*.rb')) : path }.flatten
templates.each do |path|
name ||= File.basename(path, '.rb').scan(/\w+/).join('_').to_sym
text = IO.read(path)
template = factory.templates[name] || Template.new(name)
template.instance_eval(text)
factory.templates[name] = template
end
end
|