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,:open,:readline,:readlines,:putc,:puts,:print,:printf,
:=~,:===,:==,:eql?,: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

#document, #documents, #object, #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.



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

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)


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

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.



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

def cx
  @cx
end

#iohObject Also known as: ior, iow

Returns the value of attribute ioh.



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

def ioh
  @ioh
end

#rlObject

attr_accessor :handled_by



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

def rl
  @rl
end

#try_stateObject

Returns the value of attribute try_state.



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

def try_state
  @try_state
end

Class Method Details

.default_cxObject



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

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

.new_other(other) ⇒ Object



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

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

Instance Method Details

#==(other) ⇒ Object



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

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

#===(other) ⇒ Object



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

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

#=~(other) ⇒ Object



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

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

#base_stateObject



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

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

#became(obj) ⇒ Object



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

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



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

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



234
235
236
# File 'lib/rio/state.rb', line 234

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

#clone_rioObject



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

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
end

#ensure_cmd_rio(arg) ⇒ Object



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

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



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

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)


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

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

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



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

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

#fsObject



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

def fs() self.rl.fs end

#gofigure(sym, *args) ⇒ Object

Section: Error Handling



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

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



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

def hash() @rl.to_s.hash end

#initialize_copy(*args) ⇒ Object



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

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)



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

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???)



200
201
202
# File 'lib/rio/state.rb', line 200

def new_rio(arg0,*args,&block)
  Rio.rio(arg0,*args,&block)
end

#new_rio_cx(*args) ⇒ Object



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

def new_rio_cx(*args)
  n = new_rio(*args)
  n.cx = self.cx.bequeath(n.cx)
  n
end

#resetObject



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

def reset
  softreset()
end

#retryresetObject



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

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

#softresetObject



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

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

#stream?Boolean

Returns:

  • (Boolean)


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

def stream?() false end

#to_rlObject



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

def to_rl() self.rl.rl end

#to_uriObject



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

def to_uri() @rl.uri end

#to_urlObject



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

def to_url() @rl.url end

#when_missing(sym, *args) ⇒ Object



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

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