Class: RIO::State::Base
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
Direct Known Subclasses
CmdPipe::Stream::Reset, Dir::Base, Ext::YAML::Doc::Base, File::Base, Path::Empty, Path::NonExisting, Path::Reset, Path::Str, Error, RIO::Stream::Base, RIO::Stream::Close, Temp::Reset, ZipFile::State::Reset
Constant Summary
collapse
- KIOSYMS =
[:gets,:getc,:open,:readline,:readlines,:chop,:to_a,:putc,:puts,:print,:printf,
:=~,:===,:==,:eql?,:sub,:sub!,:gsub,:gsub!,:load]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#==(other) ⇒ Object
-
#===(other) ⇒ Object
-
#=~(other) ⇒ Object
-
#base_state ⇒ Object
-
#became(obj) ⇒ Object
-
#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.
-
#callstr(func, *args) ⇒ Object
-
#clone_rio ⇒ Object
-
#ensure_cmd_rio(arg) ⇒ Object
-
#ensure_rio(arg0) ⇒ Object
-
#eql?(other) ⇒ Boolean
-
#error(emsg, sym, *args) ⇒ Object
-
#fs ⇒ Object
-
#gofigure(sym, *args) ⇒ Object
-
#hash ⇒ Object
-
#initialize(rl = nil, cx = nil, ioh = nil) ⇒ Base
constructor
-
#initialize_copy(*args) ⇒ Object
-
#method_missing(sym, *args, &block) ⇒ Object
-
#method_missing_trace_str(sym, *args) ⇒ Object
-
#new_rio(arg0, *args, &block) ⇒ Object
Section: Rio Interface gives states the ability to create new rio objects (should this be here???).
-
#new_rio_cx(*args) ⇒ Object
-
#reset ⇒ Object
-
#retryreset ⇒ Object
-
#softreset ⇒ Object
-
#stream? ⇒ Boolean
-
#to_rl ⇒ Object
-
#to_uri ⇒ Object
-
#to_url ⇒ Object
-
#when_missing(sym, *args) ⇒ Object
#zipfile
#rtn_new, #rtn_reset, #rtn_rio, #rtn_self, #rtn_val
#document, #documents, #object, #objects, #skipdocuments, #skipobjects, #yaml, #yaml?, #yamldoc
#columns, #columns?, #skipcolumns, #splitlines, #splitlines?
#columns, #columns?, #csv, #csv?, #skipcolumns
#+@, #_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)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
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) end
|
Instance Attribute Details
Returns the value of attribute cx.
71
72
73
|
# File 'lib/rio/state.rb', line 71
def cx
@cx
end
|
#ioh ⇒ Object
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
|
attr_accessor :handled_by
68
69
70
|
# File 'lib/rio/state.rb', line 68
def rl
@rl
end
|
#try_state ⇒ Object
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_cx ⇒ Object
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_state ⇒ Object
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)
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
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_rio ⇒ Object
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
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
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
|
181
|
# File 'lib/rio/state.rb', line 181
def fs() self.rl.fs end
|
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
|
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)
super
@rl = @rl.clone unless @rl.nil?
@cx = @cx.clone unless @cx.nil?
@ioh = @ioh.clone unless @ioh.nil?
end
|
#method_missing_trace_str(sym, *args) ⇒ Object
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(',')+')'
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)
nrio = Rio.rio(arg0,*args,&block)
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)
n.cx = self.cx.bequeath(n.cx)
n
end
|
164
165
166
|
# File 'lib/rio/state.rb', line 164
def reset
softreset()
end
|
#retryreset ⇒ Object
160
161
162
163
|
# File 'lib/rio/state.rb', line 160
def retryreset
become(self.base_state)
end
|
#softreset ⇒ Object
155
156
157
158
159
|
# File 'lib/rio/state.rb', line 155
def softreset
cx['retrystate'] = nil
become(self.base_state)
end
|
#stream? ⇒ Boolean
196
|
# File 'lib/rio/state.rb', line 196
def stream?() false end
|
180
|
# File 'lib/rio/state.rb', line 180
def to_rl() self.rl.rl end
|
190
|
# File 'lib/rio/state.rb', line 190
def to_uri() @rl.uri end
|
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
|