Class: Oxidized::Model
Direct Known Subclasses
ACOS, AOS, AOS7, AOSW, Aireos, EOS, FortiOS, IOS, IOSXR, IronWare, JunOS, PowerConnect, Procurve, TiMOS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#vars
Instance Attribute Details
Returns the value of attribute input.
75
76
77
|
# File 'lib/oxidized/model/model.rb', line 75
def input
@input
end
|
#node ⇒ Object
Returns the value of attribute node.
75
76
77
|
# File 'lib/oxidized/model/model.rb', line 75
def node
@node
end
|
Class Method Details
.cfg(*methods, &block) ⇒ Object
20
21
22
23
24
|
# File 'lib/oxidized/model/model.rb', line 20
def cfg *methods, &block
[methods].flatten.each do |method|
@cfg[method.to_s] << block
end
end
|
.cfgs ⇒ Object
25
26
27
|
# File 'lib/oxidized/model/model.rb', line 25
def cfgs
@cfg
end
|
.cmd(_cmd = nil, &block) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/oxidized/model/model.rb', line 28
def cmd _cmd=nil, &block
if _cmd.class == Symbol
@cmd[_cmd] << block
else
@cmd[:cmd] << [_cmd, block]
end
end
|
.cmds ⇒ Object
35
36
37
|
# File 'lib/oxidized/model/model.rb', line 35
def cmds
@cmd
end
|
13
14
15
16
|
# File 'lib/oxidized/model/model.rb', line 13
def ='# '
return @comment if @comment
@comment = block_given? ? yield :
end
|
.expect(re, &block) ⇒ Object
38
39
40
|
# File 'lib/oxidized/model/model.rb', line 38
def expect re, &block
@expect << [re, block]
end
|
.expects ⇒ Object
41
42
43
|
# File 'lib/oxidized/model/model.rb', line 41
def expects
@expect
end
|
.inherited(klass) ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/oxidized/model/model.rb', line 6
def inherited klass
klass.instance_variable_set '@cmd', Hash.new { |h,k| h[k] = [] }
klass.instance_variable_set '@cfg', Hash.new { |h,k| h[k] = [] }
klass.instance_variable_set '@procs', Hash.new { |h,k| h[k] = [] }
klass.instance_variable_set '@expect', []
klass.const_set :CFG, CFG
end
|
.post { ... } ⇒ void
This method returns an undefined value.
calls the block at the end of the model, adding the output of the block to the output string
63
64
65
|
# File 'lib/oxidized/model/model.rb', line 63
def post &block
@procs[:post] << block
end
|
.pre { ... } ⇒ void
This method returns an undefined value.
calls the block at the end of the model, prepending the output of the block to the output string
52
53
54
|
# File 'lib/oxidized/model/model.rb', line 52
def pre &block
@procs[:pre] << block
end
|
.procs ⇒ Hash
Returns hash proc procs :pre+:post to be prepended/postfixed to output.
70
71
72
|
# File 'lib/oxidized/model/model.rb', line 70
def procs
@procs
end
|
.prompt(_prompt = nil) ⇒ Object
17
18
19
|
# File 'lib/oxidized/model/model.rb', line 17
def prompt _prompt=nil
@prompt or @prompt = _prompt
end
|
Instance Method Details
#cfg ⇒ Object
105
106
107
|
# File 'lib/oxidized/model/model.rb', line 105
def cfg
self.class.cfgs
end
|
#cmd(string, &block) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/oxidized/model/model.rb', line 77
def cmd string, &block
out = @input.cmd string
return false unless out
out = Oxidized::String.new out
self.class.cmds[:all].each do |all_block|
out = instance_exec out, string, &all_block
end
if vars :remove_secret
self.class.cmds[:secret].each do |all_block|
out = instance_exec out, string, &all_block
end
end
out = instance_exec out, &block if block
out
end
|
143
144
145
146
147
148
149
|
# File 'lib/oxidized/model/model.rb', line 143
def
data = ''
.each_line do |line|
data << self.class. << line
end
data
end
|
#expect(re, &block) ⇒ Object
101
102
103
|
# File 'lib/oxidized/model/model.rb', line 101
def expect re, &block
self.class.expect re, &block
end
|
#expects(data) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/oxidized/model/model.rb', line 113
def expects data
self.class.expects.each do |re, cb|
if data.match re
if cb.arity == 2
data = instance_exec [data, re], &cb
else
data = instance_exec data, &cb
end
end
end
data
end
|
#get ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/oxidized/model/model.rb', line 126
def get
data, pre = '', ''
procs = self.class.procs
self.class.cmds[:cmd].each do |command, block|
out = cmd command, &block
return false unless out
data << out.to_s
end
procs[:pre].each do |pre_proc|
pre << instance_eval(&pre_proc).to_s
end
procs[:post].each do |post_proc|
data << instance_eval(&post_proc).to_s
end
pre + data
end
|
#output ⇒ Object
93
94
95
|
# File 'lib/oxidized/model/model.rb', line 93
def output
@input.output
end
|
#prompt ⇒ Object
109
110
111
|
# File 'lib/oxidized/model/model.rb', line 109
def prompt
self.class.prompt
end
|
#send(data) ⇒ Object
97
98
99
|
# File 'lib/oxidized/model/model.rb', line 97
def send data
@input.send data
end
|