diff options
author | Neil Lathwood <neil@lathwood.co.uk> | 2018-04-27 11:38:06 +0100 |
---|---|---|
committer | Neil Lathwood <neil@lathwood.co.uk> | 2018-04-27 11:38:06 +0100 |
commit | b1194745929043b578c409f794ecb433aa515fa9 (patch) | |
tree | 133e7103073b707aaca855eb3df4d5025bebae06 /lib/oxidized/model/model.rb | |
parent | 9156243b9debfc0bc2b05dfe98a910ce5153bf49 (diff) | |
parent | 34fd5369feee94ab45c5a81d7769b1df717e4c8c (diff) |
Rebased and fixed conflicts
Diffstat (limited to 'lib/oxidized/model/model.rb')
-rw-r--r-- | lib/oxidized/model/model.rb | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/oxidized/model/model.rb b/lib/oxidized/model/model.rb index a2a71cb..438357f 100644 --- a/lib/oxidized/model/model.rb +++ b/lib/oxidized/model/model.rb @@ -7,29 +7,34 @@ module Oxidized class << self 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 '@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.instance_variable_set '@comment', nil klass.instance_variable_set '@prompt', nil end - def comment _comment='# ' + + def comment _comment = '# ' return @comment if @comment @comment = block_given? ? yield : _comment end - def prompt _prompt=nil + + def prompt _prompt = nil @prompt or @prompt = _prompt end + def cfg *methods, &block [methods].flatten.each do |method| @cfg[method.to_s] << block end end + def cfgs @cfg end - def cmd _cmd=nil, &block + + def cmd _cmd = nil, &block if _cmd.class == Symbol @cmd[_cmd] << block else @@ -37,12 +42,15 @@ module Oxidized end Oxidized.logger.debug "lib/oxidized/model/model.rb Added #{_cmd} to the commands list" end + def cmds @cmd end + def expect re, &block @expect << [re, block] end + def expects @expect end @@ -83,6 +91,7 @@ module Oxidized Oxidized.logger.debug "lib/oxidized/model/model.rb Executing #{string}" out = @input.cmd(string) return false unless out + out = out.b unless Oxidized.config.input.utf8_encoded? self.class.cmds[:all].each do |all_block| out = instance_exec Oxidized::String.new(out), string, &all_block end @@ -166,6 +175,5 @@ module Oxidized output.set_cmd(name) output end - end end |