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,:open,:readline,:readlines,:putc,:puts,:print,:printf,
:=~,:===,:==,:eql?,: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.
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)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
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) end
|
Instance Attribute Details
Returns the value of attribute cx.
70
71
72
|
# File 'lib/rio/state.rb', line 70
def cx
@cx
end
|
#ioh ⇒ Object
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
|
attr_accessor :handled_by
67
68
69
|
# File 'lib/rio/state.rb', line 67
def rl
@rl
end
|
#try_state ⇒ Object
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_cx ⇒ Object
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_state ⇒ Object
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)
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
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_rio ⇒ Object
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
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
|
180
|
# File 'lib/rio/state.rb', line 180
def fs() self.rl.fs end
|
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
|
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)
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
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(',')+')'
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
|
163
164
165
|
# File 'lib/rio/state.rb', line 163
def reset
softreset()
end
|
#retryreset ⇒ Object
159
160
161
162
|
# File 'lib/rio/state.rb', line 159
def retryreset
become(self.base_state)
end
|
#softreset ⇒ Object
154
155
156
157
158
|
# File 'lib/rio/state.rb', line 154
def softreset
cx['retrystate'] = nil
become(self.base_state)
end
|
#stream? ⇒ Boolean
195
|
# File 'lib/rio/state.rb', line 195
def stream?() false end
|
179
|
# File 'lib/rio/state.rb', line 179
def to_rl() self.rl.rl end
|
189
|
# File 'lib/rio/state.rb', line 189
def to_uri() @rl.uri end
|
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
|