Class: Net::SSH::Xlogin::Factory
- Inherits:
-
Object
- Object
- Net::SSH::Xlogin::Factory
show all
- Includes:
- Singleton
- Defined in:
- lib/net/ssh/xlogin/factory.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Factory.
10
11
12
13
|
# File 'lib/net/ssh/xlogin/factory.rb', line 10
def initialize
@inventory = Hash.new
@templates = Hash.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **options) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/net/ssh/xlogin/factory.rb', line 54
def method_missing(method, *args, **options)
super unless args.size == 2
name = args.shift
uri = URI.parse(args.shift)
options[:type] = method
options[:uri] = uri
options[:name] = name
options[:host_name] = uri.host
options[:user] = uri.user
options[:password] = uri.password
set_source(name, **options)
end
|
Instance Attribute Details
#inventory ⇒ Object
Returns the value of attribute inventory.
7
8
9
|
# File 'lib/net/ssh/xlogin/factory.rb', line 7
def inventory
@inventory
end
|
#templates ⇒ Object
Returns the value of attribute templates.
8
9
10
|
# File 'lib/net/ssh/xlogin/factory.rb', line 8
def templates
@templates
end
|
Instance Method Details
#dsl(str) ⇒ Object
50
51
52
|
# File 'lib/net/ssh/xlogin/factory.rb', line 50
def dsl(str)
instance_eval(str)
end
|
#query(q) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/net/ssh/xlogin/factory.rb', line 23
def query(q)
list = inventory.map{|k, v| v}
return list if q.empty?
list.select do |h|
q.any? do |k,v|
case v
when Regexp
h[k] =~ v
else
h[k] == v
end
end
end
end
|
#set_source(name, **args) ⇒ Object
15
16
17
|
# File 'lib/net/ssh/xlogin/factory.rb', line 15
def set_source(name, **args)
@inventory[name] = args
end
|
#set_template(name, klass) ⇒ Object
19
20
21
|
# File 'lib/net/ssh/xlogin/factory.rb', line 19
def set_template(name, klass)
@templates[name] = klass
end
|
#yaml(file) ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/net/ssh/xlogin/factory.rb', line 39
def yaml(file)
raise Error, 'not cofnig file' unless File.exist?(file)
srcs = YAML.load_file(file)
srcs.each do |src|
src = src.inject({}){|h, (k,v)| h = h.merge(k.to_sym => v) }
name = src.delete(:host)
src[:name] = name
set_source(name, **src)
end
end
|