Module: RaptorIO::Protocol::HTTP::Request::Manipulators
- Extended by:
- Enumerable
- Defined in:
- lib/raptor-io/protocol/http/request/manipulators.rb,
lib/raptor-io/protocol/http/request/manipulators/authenticator.rb,
lib/raptor-io/protocol/http/request/manipulators/redirect_follower.rb,
lib/raptor-io/protocol/http/request/manipulators/authenticators/ntlm.rb,
lib/raptor-io/protocol/http/request/manipulators/authenticators/basic.rb,
lib/raptor-io/protocol/http/request/manipulators/authenticators/digest.rb,
lib/raptor-io/protocol/http/request/manipulators/authenticators/negotiate.rb
Overview
Namespace holding all Request manipulators and providing some helper methods for management.
Defined Under Namespace
Modules: Authenticators Classes: Authenticator, RedirectFollower
Class Attribute Summary collapse
-
.library ⇒ String
Directory of the manipulators’ repository.
Class Method Summary collapse
-
.available ⇒ Array<Symbol>
Names of all manipulators.
-
.class_to_name(klass) ⇒ String?
Manipulator shortname, ‘nil` if the manipulator isn’t loaded.
-
.each(&block) ⇒ Enumerator, Manipulators
‘Enumerator` if no `block` is given, `self` otherwise.
-
.exist?(name) ⇒ Bool
‘true` if the given manipulator exists, `false` otherwise.
-
.load(manipulator) ⇒ Class
Loaded manipulator.
-
.load_all ⇒ Hash
Loads all manipulators.
-
.loaded ⇒ Hash
All manipulators as a frozen hash.
-
.name_to_path(name) ⇒ String
Manipulator FS path.
-
.normalize_name(name) ⇒ String
Manipulator name.
-
.path_to_name(path) ⇒ String
Manipulator shortname.
-
.paths ⇒ Array<String>
Paths of all manipulators.
- .process(manipulator, client, request, options = {}) ⇒ Object
-
.register(name, klass) ⇒ Manipulator
Registers a manipulator.
-
.reset ⇒ Object
Resets the manipulators by unloading all and settings the #library to its default setting.
-
.unload(manipulator) ⇒ Bool
‘true` if the manipulator was unloaded successfully, `false` if no matching one was found.
-
.unload_all ⇒ Object
Unloads all manipulators.
-
.validate_batch_options(manipulators, client) ⇒ Hash{String=>Hash}
Performs batch validation of manipulator options.
-
.validate_batch_options!(manipulators, client) ⇒ Object
Same as Manipulators.validate_batch_options but raises exception on errors.
-
.validate_options(manipulator, options, client) ⇒ Hash{Symbol=>Array<String>}
Option names keys for and error messages for values.
Class Attribute Details
.library ⇒ String
Returns Directory of the manipulators’ repository.
18 19 20 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 18 def library @library end |
Class Method Details
.available ⇒ Array<Symbol>
Returns Names of all manipulators.
81 82 83 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 81 def available paths.map { |path| path_to_name path } end |
.class_to_name(klass) ⇒ String?
Returns Manipulator shortname, ‘nil` if the manipulator isn’t loaded.
194 195 196 197 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 194 def class_to_name( klass ) @manipulators.select { |name, k| return name if k == klass } nil end |
.each(&block) ⇒ Enumerator, Manipulators
Returns ‘Enumerator` if no `block` is given, `self` otherwise.
146 147 148 149 150 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 146 def each( &block ) return enum_for( __method__ ) if !block_given? @manipulators.each( &block ) self end |
.exist?(name) ⇒ Bool
Returns ‘true` if the given manipulator exists, `false` otherwise.
181 182 183 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 181 def exist?( name ) File.exist? name_to_path( name ) end |
.load(manipulator) ⇒ Class
Returns Loaded manipulator.
89 90 91 92 93 94 95 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 89 def load( manipulator ) manipulator = normalize_name( manipulator ) return @manipulators[manipulator] if @manipulators.include? manipulator Kernel.load name_to_path( manipulator ) @manipulators[manipulator] end |
.load_all ⇒ Hash
Loads all manipulators.
100 101 102 103 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 100 def load_all paths.each { |path| load path_to_name( path ) } loaded end |
.loaded ⇒ Hash
Returns All manipulators as a frozen hash.
153 154 155 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 153 def loaded @manipulators.dup.freeze end |
.name_to_path(name) ⇒ String
Returns Manipulator FS path.
201 202 203 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 201 def name_to_path( name ) File. "#{library}/#{name}.rb" end |
.normalize_name(name) ⇒ String
Returns Manipulator name.
207 208 209 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 207 def normalize_name( name ) name.to_s end |
.path_to_name(path) ⇒ String
Returns Manipulator shortname.
187 188 189 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 187 def path_to_name( path ) normalize_name path.gsub( library, '' ).gsub( /(.+)\.rb$/, '\1' ) end |
.paths ⇒ Array<String>
Returns Paths of all manipulators.
76 77 78 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 76 def paths Dir.glob( "#{library}**/*.rb" ) end |
.process(manipulator, client, request, options = {}) ⇒ Object
28 29 30 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 28 def process( manipulator, client, request, = {} ) load( manipulator ).new( client, request, ).run end |
.register(name, klass) ⇒ Manipulator
Registers a manipulator.
165 166 167 168 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 165 def register( name, klass ) @manipulators[normalize_name( name )] = klass self end |
.reset ⇒ Object
Resets the manipulators by unloading all and settings the #library to its default setting.
172 173 174 175 176 177 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 172 def reset unload_all if @manipulators @library = File.( File.dirname( __FILE__ ) + '/manipulators' ) + '/' @manipulators = {} end |
.unload(manipulator) ⇒ Bool
Returns ‘true` if the manipulator was unloaded successfully, `false` if no matching one was found.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 111 def unload( manipulator ) klass = @manipulators.delete( normalize_name( manipulator ) ) return false if !klass container = self klass.to_s.gsub( "#{self}::", '' ).split( '::' )[0...-1].each do |c| container = container.const_get( c.to_sym ) end container.instance_eval do remove_const klass.to_s.split( ':' ).last.to_sym end # Remove the container namespaces themselves if they're now empty. container = self klass.to_s.gsub( "#{self}::", '' ).split( '::' )[0...-1].each do |c| container = container.const_get( c.to_sym ) if container != self && container.constants.empty? remove_const container.to_s.split( ':' ).last.to_sym end end true end |
.unload_all ⇒ Object
Unloads all manipulators.
137 138 139 140 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 137 def unload_all @manipulators.keys.each { |manipulator| unload manipulator } nil end |
.validate_batch_options(manipulators, client) ⇒ Hash{String=>Hash}
Performs batch validation of manipulator options.
42 43 44 45 46 47 48 49 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 42 def ( manipulators, client ) errors = {} manipulators.each do |manipulator, | errors[manipulator] = ( manipulator, , client ) end errors.reject { |_, errs| errs.empty? } end |
.validate_batch_options!(manipulators, client) ⇒ Object
Same as validate_batch_options but raises exception on errors.
52 53 54 55 56 57 58 |
# File 'lib/raptor-io/protocol/http/request/manipulators.rb', line 52 def ( manipulators, client ) errors = ( manipulators, client ) if errors.any? fail Request::Manipulator::Error::InvalidOptions, errors.to_s end nil end |