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', 'Stream::Duplex::Input' => 'rio/stream/duplex', 'Stream::Duplex::Output' => 'rio/stream/duplex', 'Stream::Duplex::InOut' => 'rio/stream/duplex', 'Stream::Duplex::Close' => 'rio/stream/duplex', 'Stream::Duplex::Reset' => '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
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.
34 35 36 37 38 39 |
# File 'lib/rio/factory.rb', line 34 def initialize() @ss_module = {} @reset_class = {} @state_class = {} @ss_class = {} end |
Instance Method Details
#clone_state(state) ⇒ Object
202 203 204 |
# File 'lib/rio/factory.rb', line 202 def clone_state(state) create_handle(state.target.clone) end |
#create_handle(new_state) ⇒ Object
205 206 207 208 209 |
# File 'lib/rio/factory.rb', line 205 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
factory creates a state from args
198 199 200 201 |
# File 'lib/rio/factory.rb', line 198 def create_state(*args) riorl = RIO::RRL::Builder.build(*args) create_handle(state2class(reset_state(riorl)).new(rl:riorl)) end |
#reset_state(rl) ⇒ Object
158 159 160 161 |
# File 'lib/rio/factory.rb', line 158 def reset_state(rl) mod = subscheme_module(rl.scheme) mod.const_get(:RESET_STATE) unless mod.nil? end |
#riorl_class(sch) ⇒ Object
151 152 153 154 155 156 |
# File 'lib/rio/factory.rb', line 151 def riorl_class(sch) ssm = subscheme_module(sch) cls = ssm.const_get(:RRL) cls end |
#state2class(state_name) ⇒ Object
163 164 165 166 167 168 169 170 171 |
# File 'lib/rio/factory.rb', line 163 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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rio/factory.rb', line 41 def subscheme_module(sch) #p "subscheme_module(#{sch})" @ss_module[sch] ||= case sch when 'file','path' require 'rio/rrl/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/rrl/path' Path end end |
#try_state_proc(current_state, rio_handle) ⇒ Object
177 178 179 180 181 |
# File 'lib/rio/factory.rb', line 177 def try_state_proc(current_state,rio_handle) proc { |new_state_name| _change_state(state2class(new_state_name),current_state,rio_handle) } end |
#try_state_proc1(current_state, rio_handle) ⇒ Object
172 173 174 175 176 |
# File 'lib/rio/factory.rb', line 172 def try_state_proc1(current_state,rio_handle) proc { |new_state_name| _change_state(state2class(new_state_name,rio_handle),current_state,rio_handle) } end |