Class: RIO::Factory
Overview
:nodoc: all
Constant Summary collapse
- STATE2FILE =
{ 'Path::Reset' => 'rio/path/reset', 'Path::Empty' => 'rio/path', 'Path::Str' => 'rio/path', 'Path::NonExisting' => 'rio/path', 'File::Existing' => 'rio/file', 'File::NonExisting' => 'rio/file', 'Dir::Existing' => 'rio/dir', 'Dir::Open' => 'rio/dir', 'Dir::Close' => 'rio/dir', 'Dir::Stream' => 'rio/dir', 'Dir::NonExisting' => 'rio/dir', 'Stream::Close' => 'rio/stream/open', 'Stream::Reset' => 'rio/stream', 'Stream::Open' => 'rio/stream/open', 'Stream::Input' => 'rio/stream', 'Stream::Output' => 'rio/stream', 'Stream::InOut' => 'rio/stream', 'Stream::Duplex::Open' => 'rio/stream/duplex', 'Path::Stream::Open' => 'rio/scheme/path', 'StrIO::Stream::Open' => 'rio/scheme/strio', 'Null::Stream::Open' => 'rio/scheme/null', 'CmdPipe::Stream::Reset' => 'rio/scheme/cmdpipe', 'HTTP::Stream::Input' => 'rio/scheme/http', 'HTTP::Stream::Open' => 'rio/scheme/http', 'Temp::Reset' => 'rio/scheme/temp', 'Temp::Stream::Open' => 'rio/scheme/temp', 'Ext::YAML::Doc::Existing' => 'rio/ext/yaml/doc', 'Ext::YAML::Doc::Open' => 'rio/ext/yaml/doc', 'Ext::YAML::Doc::Stream' => 'rio/ext/yaml/doc', 'Ext::YAML::Doc::Close' => 'rio/ext/yaml/doc', }
Instance Method Summary collapse
- #clone_state(state) ⇒ Object
- #create_handle(new_state) ⇒ Object
- #create_state(*args) ⇒ Object
-
#create_state1(*args) ⇒ Object
factory creates a state from args.
-
#initialize ⇒ Factory
constructor
A new instance of Factory.
- #reset_state(rl) ⇒ Object
- #riorl_class(sch) ⇒ Object
- #state2class(state_name) ⇒ Object
- #subscheme_module(sch) ⇒ Object
- #try_state_proc(current_state, rio_handle) ⇒ Object
- #try_state_proc1(current_state, rio_handle) ⇒ Object
Constructor Details
#initialize ⇒ Factory
Returns a new instance of Factory.
252 253 254 255 256 257 |
# File 'lib/rio/factory.rb', line 252 def initialize() @ss_module = {} @reset_class = {} @state_class = {} @ss_class = {} end |
Instance Method Details
#clone_state(state) ⇒ Object
416 417 418 |
# File 'lib/rio/factory.rb', line 416 def clone_state(state) create_handle(state.target.clone) end |
#create_handle(new_state) ⇒ Object
419 420 421 422 423 |
# File 'lib/rio/factory.rb', line 419 def create_handle(new_state) hndl = Handle.new(new_state) new_state.try_state = try_state_proc(new_state,hndl) hndl end |
#create_state(*args) ⇒ Object
412 413 414 415 |
# File 'lib/rio/factory.rb', line 412 def create_state(*args) riorl = RIO::RL::Builder.build(*args) create_handle(state2class(reset_state(riorl)).new(riorl)) end |
#create_state1(*args) ⇒ Object
factory creates a state from args
408 409 410 411 |
# File 'lib/rio/factory.rb', line 408 def create_state1(*args) riorl = RIO::RL::Builder.build(*args) create_handle(state2class(reset_state(riorl)).new(riorl)) end |
#reset_state(rl) ⇒ Object
368 369 370 371 |
# File 'lib/rio/factory.rb', line 368 def reset_state(rl) mod = subscheme_module(rl.scheme) mod.const_get(:RESET_STATE) unless mod.nil? end |
#riorl_class(sch) ⇒ Object
364 365 366 |
# File 'lib/rio/factory.rb', line 364 def riorl_class(sch) subscheme_module(sch).const_get(:RL) end |
#state2class(state_name) ⇒ Object
373 374 375 376 377 378 379 380 381 |
# File 'lib/rio/factory.rb', line 373 def state2class(state_name) return @state_class[state_name] if @state_class.has_key?(state_name) if STATE2FILE.has_key?(state_name) require STATE2FILE[state_name] return @state_class[state_name] = RIO.module_eval(state_name) else raise ArgumentError,"Unknown State Name (#{state_name})" end end |
#subscheme_module(sch) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/rio/factory.rb', line 259 def subscheme_module(sch) #p "subscheme_module(#{sch})" @ss_module[sch] ||= case sch when 'file','path' require 'rio/scheme/path' Path when 'zipfile' require 'rio/ext/zipfile/rl' ZipFile::RootDir when 'stdio','stdin','stdout' require 'rio/scheme/stdio' StdIO when 'stderr' require 'rio/scheme/stderr' StdErr when 'null' require 'rio/scheme/null' Null when 'tempfile' require 'rio/scheme/temp' Temp::File when 'temp' require 'rio/scheme/temp' Temp when 'tempdir' require 'rio/scheme/temp' Temp::Dir when 'strio','stringio','string' require 'rio/scheme/strio' StrIO when 'cmdpipe' require 'rio/scheme/cmdpipe' CmdPipe when 'aryio' require 'rio/scheme/aryio' AryIO when 'http','https' require 'rio/scheme/http' HTTP when 'ftp' require 'rio/scheme/ftp' FTP when 'tcp' require 'rio/scheme/tcp' TCP when 'sysio' require 'rio/scheme/sysio' SysIO when 'fd' require 'rio/scheme/fd' FD when 'cmdio' require 'rio/scheme/cmdio' CmdIO else require 'rio/scheme/path' Path end end |
#try_state_proc(current_state, rio_handle) ⇒ Object
389 390 391 392 393 394 |
# File 'lib/rio/factory.rb', line 389 def try_state_proc(current_state,rio_handle) proc { |new_state_name| # new_state_class = state2class(new_state_name) _change_state(state2class(new_state_name),current_state,rio_handle) } end |
#try_state_proc1(current_state, rio_handle) ⇒ Object
382 383 384 385 386 387 388 |
# File 'lib/rio/factory.rb', line 382 def try_state_proc1(current_state,rio_handle) #p "try_state_proc cur=#{current_state}[#{current_state.class}] han=#{rio_handle}[#{rio_handle.class}]" proc { |new_state_name| # new_state_class = state2class(new_state_name) _change_state(state2class(new_state_name,rio_handle),current_state,rio_handle) } end |