lib/rio/state.rb in rio-0.3.4 vs lib/rio/state.rb in rio-0.3.6

- old
+ new

@@ -39,11 +39,11 @@ require 'rio/context' require 'rio/context/methods' require 'rio/ext' require 'rio/symantics' require 'rio/filter' -$trace_states = false + module RIO module State #:nodoc: all # = State @@ -53,11 +53,11 @@ # * the methods to communicate with the rio object # * the state changing mechanism # * and some basic error handling stubs class Base KIOSYMS = [:gets,:open,:readline,:readlines,:chop,:to_a,:putc,:puts,:print,:printf,:split, - :=~,:===,:==,:eql?,:sub,:sub!,:gsub,:gsub!] + :=~,:===,:==,:eql?,:sub,:sub!,:gsub,:gsub!,:load] @@kernel_cleaned ||= KIOSYMS.each { |sym| undef_method(sym) } end class Base attr_accessor :rl @@ -77,21 +77,26 @@ @rl = @cx = @ioh = nil # @handled_by = self.class.to_s end def initialize_copy(*args) - #p callstr('enter state initialize_copy',*args) + #p callstr('initialize_copy',args[0].inspect) super @rl = @rl.clone unless @rl.nil? @cx = @cx.clone unless @cx.nil? @ioh = @ioh.clone unless @ioh.nil? end def self.new_r(riorl) new.init(riorl,Cx::Vars.new( { 'closeoneof' => true, 'closeoncopy' => true } )) end - + def clone_rio() + cp = Rio.new(self.rl) + cp.cx = self.cx + cp.ioh = self.ioh.clone unless self.ioh.nil? + cp + end def init(riorl,cntx,iohandle=nil) @rl = riorl @cx = cntx @ioh = iohandle # raise Exception::FailedCheck.new(self) unless check? @@ -104,10 +109,15 @@ def copy_state(other) init(other.rl,other.cx,other.ioh) end + alias :ior :ioh + alias :iow :ioh + + + # Section: State Switching # the method for changing states # it's job is create an instance of the next state # and change the value in the handle that is shared with the rio object @@ -168,11 +178,11 @@ def to_rl() self.rl.rl end extend Forwardable - def_instance_delegators(:rl,:path,:to_s,:fspath,:length) + def_instance_delegators(:rl,:path,:to_s,:fspath,:urlpath,:length) def ==(other) @rl == other end def ===(other) self == other end def =~(other) other =~ self.to_str end def to_url() @rl.url end @@ -197,9 +207,17 @@ n end def ensure_rio(arg0) return arg0 if arg0.kind_of?(::RIO::Rio) new_rio(arg0) + end + def ensure_cmd_rio(arg) + case arg + when ::String then new_rio(:cmdio,arg) + when ::Fixnum then new_rio(arg) + when Rio then arg.clone + else ensure_rio(arg) + end end include Symantics def callstr(func,*args)