diff options
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 |