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 =
kiosyms
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
-
#error(emsg, sym, *args) ⇒ Object
-
#fs ⇒ Object
-
#gofigure(sym, *args) ⇒ Object
-
#hash ⇒ Object
-
#initialize(iv) ⇒ Base
constructor
-
#initialize_copy(other) ⇒ 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_a ⇒ Object
In 1.8 #to_a is inherited from Object For 1.9 we create this – only to undef it immediatly.
-
#to_ary ⇒ Object
-
#to_rl ⇒ Object
-
#to_uri ⇒ Object
-
#to_url ⇒ Object
-
#uri ⇒ Object
-
#when_missing(sym, *args) ⇒ Object
Methods included from Fwd
fwd, fwd_reader, fwd_readers, fwd_writer, fwd_writers
#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?, #fields, #fields?, #headers, #headers?, #skipcolumns, #skipfields
#+@, #_arg_skip, #_noarg_skip, #a, #a!, #all, #all?, #binmode, #binmode?, #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, #enc, #enc?, #enc_opts?, #entries, #ext, #ext?, #ext_enc?, #files, #gzip, #gzip?, #inputmode?, #int_enc?, #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(iv) ⇒ Base
Returns a new instance of Base.
82
83
84
85
86
87
88
|
# File 'lib/rio/state.rb', line 82
def initialize(iv)
@data = State::Data.new
iv.keys.each do |k|
@data[k] = iv[k]
end
@data.cx ||= self.class.default_cx
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
130
131
132
133
134
135
136
|
# File 'lib/rio/state.rb', line 130
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 data.
81
82
83
|
# File 'lib/rio/state.rb', line 81
def data
@data
end
|
#try_state ⇒ Object
Returns the value of attribute try_state.
72
73
74
|
# File 'lib/rio/state.rb', line 72
def try_state
@try_state
end
|
Class Method Details
.default_cx ⇒ Object
104
105
106
|
# File 'lib/rio/state.rb', line 104
def self.default_cx
Cx::Vars.new( { 'closeoneof' => true, 'closeoncopy' => true } )
end
|
.new_other(other) ⇒ Object
107
108
109
|
# File 'lib/rio/state.rb', line 107
def self.new_other(other)
new(other.data)
end
|
Instance Method Details
#==(other) ⇒ Object
169
|
# File 'lib/rio/state.rb', line 169
def ==(other) rl == other end
|
#===(other) ⇒ Object
170
|
# File 'lib/rio/state.rb', line 170
def ===(other) self == other end
|
#=~(other) ⇒ Object
171
|
# File 'lib/rio/state.rb', line 171
def =~(other) other =~ self.to_str end
|
#base_state ⇒ Object
141
|
# File 'lib/rio/state.rb', line 141
def base_state() Factory.instance.reset_state(rl) end
|
#became(obj) ⇒ Object
124
125
|
# File 'lib/rio/state.rb', line 124
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
116
117
118
119
120
121
122
123
|
# File 'lib/rio/state.rb', line 116
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
new_state = try_state[new_class,*args]
became(new_state)
new_state
end
|
#callstr(func, *args) ⇒ Object
219
220
221
|
# File 'lib/rio/state.rb', line 219
def callstr(func,*args)
self.class.to_s+'['+self.to_url+']'+'.'+func.to_s+'('+args.join(',')+')'
end
|
#clone_rio ⇒ Object
194
195
196
197
198
199
|
# File 'lib/rio/state.rb', line 194
def clone_rio()
cp = Rio.new(self.rl)
cp.cx = self.cx.clone
cp.rl = self.rl.clone
cp
end
|
#ensure_cmd_rio(arg) ⇒ Object
208
209
210
211
212
213
214
215
|
# File 'lib/rio/state.rb', line 208
def ensure_cmd_rio(arg)
case arg
when ::String then new_rio("cmdio:"+arg)
when ::Integer then new_rio(arg)
when Rio then arg.clone
else ensure_rio(arg)
end
end
|
#ensure_rio(arg0) ⇒ Object
201
202
203
204
205
206
207
|
# File 'lib/rio/state.rb', line 201
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
|
#error(emsg, sym, *args) ⇒ Object
161
162
163
164
|
# File 'lib/rio/state.rb', line 161
def error(emsg,sym,*args)
require 'rio/state/error'
Error.error(emsg,self,sym,*args)
end
|
167
|
# File 'lib/rio/state.rb', line 167
def fs() self.rl.fs end
|
155
156
157
158
159
|
# File 'lib/rio/state.rb', line 155
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
|
179
|
# File 'lib/rio/state.rb', line 179
def hash() rl.to_s.hash end
|
#initialize_copy(other) ⇒ Object
90
91
92
93
94
95
96
|
# File 'lib/rio/state.rb', line 90
def initialize_copy(other)
super
@data = State::Data.new
data.rl = other.data.rl.clone if other.data.rl
data.cx = other.data.cx.clone if other.data.cx
data.ioh = other.data.ioh.clone if other.data.ioh
end
|
#method_missing_trace_str(sym, *args) ⇒ Object
126
127
128
|
# File 'lib/rio/state.rb', line 126
def method_missing_trace_str(sym,*args)
"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???)
186
187
188
|
# File 'lib/rio/state.rb', line 186
def new_rio(arg0,*args,&block)
Rio.rio(arg0,*args,&block)
end
|
#new_rio_cx(*args) ⇒ Object
189
190
191
192
193
|
# File 'lib/rio/state.rb', line 189
def new_rio_cx(*args)
n = new_rio(*args)
n.cx = self.cx.bequeath(n.cx)
n
end
|
150
151
152
|
# File 'lib/rio/state.rb', line 150
def reset
softreset()
end
|
#retryreset ⇒ Object
147
148
149
|
# File 'lib/rio/state.rb', line 147
def retryreset
become(self.base_state)
end
|
#softreset ⇒ Object
143
144
145
146
|
# File 'lib/rio/state.rb', line 143
def softreset
cx['retrystate'] = nil
become(self.base_state)
end
|
#stream? ⇒ Boolean
181
|
# File 'lib/rio/state.rb', line 181
def stream?() false end
|
In 1.8 #to_a is inherited from Object For 1.9 we create this – only to undef it immediatly. So we end up in the same state for both ruby versions.
64
|
# File 'lib/rio/state.rb', line 64
def to_a() end
|
177
|
# File 'lib/rio/state.rb', line 177
def to_ary() nil end
|
166
|
# File 'lib/rio/state.rb', line 166
def to_rl() self.rl.rl end
|
173
|
# File 'lib/rio/state.rb', line 173
def to_uri() rl.uri end
|
172
|
# File 'lib/rio/state.rb', line 172
def to_url() rl.url end
|
174
|
# File 'lib/rio/state.rb', line 174
def uri() rl.uri end
|
#when_missing(sym, *args) ⇒ Object
138
|
# File 'lib/rio/state.rb', line 138
def when_missing(sym,*args) gofigure(sym,*args) end
|