Module: Xssh
- Defined in:
- lib/xssh.rb,
lib/xssh/cli.rb,
lib/xssh/factory.rb,
lib/xssh/version.rb,
lib/xssh/template.rb,
lib/xssh/connection.rb
Defined Under Namespace
Classes: CLI, Connection, Error, Factory, Template
Constant Summary
collapse
- VERSION =
'0.1.1'
Class Method Summary
collapse
Class Method Details
38
39
40
|
# File 'lib/xssh.rb', line 38
def configure(&block)
instance_eval(&block)
end
|
.find(**query) ⇒ Object
34
35
36
|
# File 'lib/xssh.rb', line 34
def find(**query)
list(**query).first
end
|
.get(name, **opts, &block) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/xssh.rb', line 12
def get(name, **opts, &block)
opts = factory.inventory[name].merge(opts)
type = opts[:type]
template = factory.templates[type]
session = template.build(name, **opts)
return session unless block
yield session
begin
session.close
rescue StandardError
nil
end
rescue StandardError => e
raise Error, e
end
|
.list(**query) ⇒ Object
30
31
32
|
# File 'lib/xssh.rb', line 30
def list(**query)
factory.query(query)
end
|
.source(*args) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/xssh.rb', line 42
def source(*args)
args.flatten.each do |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(:name)
factory.set_source(name, **src)
when Array
src.each do |s|
name = s.delete(:name)
factory.set_source(name, **s)
end
end
end
end
|
.template(*templates, **opts, &block) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/xssh.rb', line 65
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
|