Class: RIO::State::Base

Inherits:
Object show all
Extended by:
Forwardable
Includes:
Cx::Methods, Ext::Cx, RIO::Symantics, ZipFile::Cx
Defined in:
lib/rio/state.rb,
lib/rio/state.rb,
lib/rio/ext/zipfile.rb

Overview

State

the abstract state from which all are derived this level handles

  • some basic house keeping methods

  • the methods to communicate with the rio object

  • the state changing mechanism

  • and some basic error handling stubs

Constant Summary collapse

KIOSYMS =
[:gets,:getc,:open,:readline,:readlines,:chop,:to_a,:putc,:puts,:print,:printf,
#:split,
:=~,:===,:==,:eql?,:sub,:sub!,:gsub,:gsub!,:load]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ZipFile::Cx

#zipfile

Methods included from RIO::Symantics

#rtn_new, #rtn_reset, #rtn_rio, #rtn_self, #rtn_val

Methods included from Ext::YAML::Cx

#documents, #objects, #skipdocuments, #skipobjects, #yaml, #yaml?, #yamldoc

Methods included from Ext::SplitLines::Cx

#columns, #columns?, #skipcolumns, #splitlines, #splitlines?

Methods included from Ext::CSV::Cx

#columns, #columns?, #csv, #csv?, #skipcolumns

Methods included from Cx::Methods

#+@, #_arg_skip, #_noarg_skip, #a, #a!, #all, #all?, #bytes, #bytes_, #closeoncopy, #closeoncopy?, #closeoneof, #closeoneof?, #copying, #copying?, #copying_done, #copying_from, #copying_from?, #copying_from_done, #copying_to, #copying_to?, #copying_to_done, #dir_iter?, #dirs, #entries, #ext, #ext?, #files, #gzip, #gzip?, #inputmode?, #line, #line_, #lines, #lines_, make_filter_methods, #mode, #mode?, #noall, #noautoclose, #nocloseoncopy, #nocloseoneof, #noext, #norecurse, #nostreamenum, #nostreamenum?, #nosync, #outputmode?, #r, #r!, #record, #record_, #records, #records_, #recurse, #row, #row_, #rows, #rows_, #skip, #skipdirs, #skipentries, #skipfiles, #skiplines, #skipping?, #skiprecords, #skiprecords_, #skiprows, #split, #stream_iter?, #sync, #sync?, #w, #w!

Constructor Details

#initialize(rl = nil, cx = nil, ioh = nil) ⇒ Base

Returns a new instance of Base.



78
79
80
81
82
# File 'lib/rio/state.rb', line 78

def initialize(rl=nil,cx=nil,ioh=nil)
  cx ||= self.class.default_cx
  _init(rl,cx,ioh)
  #        @handled_by = self.class.to_s
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

Raises:

  • (RuntimeError)


142
143
144
145
146
147
148
# File 'lib/rio/state.rb', line 142

def method_missing(sym,*args,&block)
  p method_missing_trace_str(sym,*args) if $trace_states

  obj = when_missing(sym,*args)
  raise RuntimeError,"when_missing returns nil" if obj.nil?
  obj.__send__(sym,*args,&block) #unless obj == self
end

Instance Attribute Details

#cxObject

Returns the value of attribute cx.



71
72
73
# File 'lib/rio/state.rb', line 71

def cx
  @cx
end

#iohObject Also known as: ior, iow

Returns the value of attribute ioh.



69
70
71
# File 'lib/rio/state.rb', line 69

def ioh
  @ioh
end

#rlObject

attr_accessor :handled_by



68
69
70
# File 'lib/rio/state.rb', line 68

def rl
  @rl
end

#try_stateObject

Returns the value of attribute try_state.



65
66
67
# File 'lib/rio/state.rb', line 65

def try_state
  @try_state
end

Class Method Details

.default_cxObject



102
103
104
# File 'lib/rio/state.rb', line 102

def self.default_cx
   Cx::Vars.new( { 'closeoneof' => true, 'closeoncopy' => true } )
end

.new_other(other) ⇒ Object



105
106
107
# File 'lib/rio/state.rb', line 105

def self.new_other(other)
  new(other.rl,other.cx,other.ioh)
end

Instance Method Details

#==(other) ⇒ Object



186
# File 'lib/rio/state.rb', line 186

def ==(other) @rl == other end

#===(other) ⇒ Object



187
# File 'lib/rio/state.rb', line 187

def ===(other) self == other end

#=~(other) ⇒ Object



188
# File 'lib/rio/state.rb', line 188

def =~(other) other =~ self.to_str end

#base_stateObject



153
# File 'lib/rio/state.rb', line 153

def base_state() Factory.instance.reset_state(@rl) end

#became(obj) ⇒ Object



134
135
136
# File 'lib/rio/state.rb', line 134

def became(obj)
  #RIO::Ext.became(obj)
end

#become(new_class, *args) ⇒ Object

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



120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/rio/state.rb', line 120

def become(new_class,*args)
  p "become : #{self.class.to_s} => #{new_class.to_s} (#{self.mode?})" if $trace_states
  #p "BECOME #{new_class}: #{cx['ss_type']}"
  return self if new_class == self.class

  begin
    new_state = try_state[new_class,*args]
  rescue Exception::FailedCheck => ex
    p "not a valid "+new_class.to_s+": "+ex.to_s+" '"+self.to_s+"'"
    raise
  end
  became(new_state)
  new_state
end

#callstr(func, *args) ⇒ Object



242
243
244
# File 'lib/rio/state.rb', line 242

def callstr(func,*args)
  self.class.to_s+'['+self.to_url+']'+'.'+func.to_s+'('+args.join(',')+')'
end

#clone_rioObject



215
216
217
218
219
220
221
222
# File 'lib/rio/state.rb', line 215

def clone_rio()
  cp = Rio.new(self.rl)
  cp.cx = self.cx.clone
  cp.ioh = self.ioh.clone unless self.ioh.nil?
  cp.rl = self.rl.clone
  #cp.fs = self.fs
  cp
end

#ensure_cmd_rio(arg) ⇒ Object



231
232
233
234
235
236
237
238
# File 'lib/rio/state.rb', line 231

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

#ensure_rio(arg0) ⇒ Object



224
225
226
227
228
229
230
# File 'lib/rio/state.rb', line 224

def ensure_rio(arg0)
  case arg0
  when RIO::Rio then arg0
  when RIO::State::Base then arg0.clone_rio
  else new_rio(arg0)
  end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


194
# File 'lib/rio/state.rb', line 194

def eql?(other) @rl.to_s.eql?(other.to_s) end

#error(emsg, sym, *args) ⇒ Object



175
176
177
178
# File 'lib/rio/state.rb', line 175

def error(emsg,sym,*args)
  require 'rio/state/error'
  Error.error(emsg,self,sym,*args)
end

#fsObject



181
# File 'lib/rio/state.rb', line 181

def fs() self.rl.fs end

#gofigure(sym, *args) ⇒ Object

Section: Error Handling



169
170
171
172
173
# File 'lib/rio/state.rb', line 169

def gofigure(sym,*args)
  cs = "#{sym}("+args.map{|el| el.to_s}.join(',')+")"
  msg = "Go Figure! rio('#{self.to_s}').#{cs} Failed"
  error(msg,sym,*args)
end

#hashObject



193
# File 'lib/rio/state.rb', line 193

def hash() @rl.to_s.hash end

#initialize_copy(*args) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/rio/state.rb', line 93

def 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?
  # @fs = @fs
end

#method_missing_trace_str(sym, *args) ⇒ Object

RIO::Ext.became(obj)



137
138
139
140
# File 'lib/rio/state.rb', line 137

def method_missing_trace_str(sym,*args)
  "missing: "+self.class.to_s+'['+self.to_url+" {#{self.rl.fs}}"+']'+'.'+sym.to_s+'('+args.join(',')+')'
  #"missing: "+self.class.to_s+'['+self.to_url+""+']'+'.'+sym.to_s+'('+args.join(',')+')'
end

#new_rio(arg0, *args, &block) ⇒ Object

Section: Rio Interface gives states the ability to create new rio objects (should this be here???)



201
202
203
204
205
206
# File 'lib/rio/state.rb', line 201

def new_rio(arg0,*args,&block)
  #return arg0 if arg0.nil? # watch out for dir.read! if you remove this line
  nrio = Rio.rio(arg0,*args,&block)
  #nrio.fs = self.fs
  nrio
end

#new_rio_cx(*args) ⇒ Object



207
208
209
210
211
212
213
214
# File 'lib/rio/state.rb', line 207

def new_rio_cx(*args)
  n = new_rio(*args)
  #p "new_rio_cx 1: #{n.cx.inspect}"
  n.cx = self.cx.bequeath(n.cx)
  #p "new_rio_cx 2: #{n.cx.inspect}"
  #n.fs = self.fs
  n
end

#resetObject



164
165
166
# File 'lib/rio/state.rb', line 164

def reset
  softreset()
end

#retryresetObject



160
161
162
163
# File 'lib/rio/state.rb', line 160

def retryreset 
  #p "retryreset(#{self.class}) => #{self.base_state}"
  become(self.base_state) 
end

#softresetObject



155
156
157
158
159
# File 'lib/rio/state.rb', line 155

def softreset 
  #p "softreset(#{self.class}) => #{self.base_state}"
  cx['retrystate'] = nil
  become(self.base_state) 
end

#stream?Boolean

Returns:

  • (Boolean)


196
# File 'lib/rio/state.rb', line 196

def stream?() false end

#to_rlObject



180
# File 'lib/rio/state.rb', line 180

def to_rl() self.rl.rl end

#to_uriObject



190
# File 'lib/rio/state.rb', line 190

def to_uri() @rl.uri end

#to_urlObject



189
# File 'lib/rio/state.rb', line 189

def to_url() @rl.url end

#when_missing(sym, *args) ⇒ Object



150
# File 'lib/rio/state.rb', line 150

def when_missing(sym,*args) gofigure(sym,*args) end