Class: RaptorIO::Protocol::HTTP::Request::Manipulator Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/raptor-io/protocol/http/request/manipulator.rb

Overview

This class is abstract.

Base manipulator class, all manipulator components should inherit from it.

Author:

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, request, options = {}) ⇒ Manipulator

Returns a new instance of Manipulator.

Parameters:



42
43
44
45
46
# File 'lib/raptor-io/protocol/http/request/manipulator.rb', line 42

def initialize( client, request, options = {} )
  @client  = client
  @request = request
  @options = options
end

Instance Attribute Details

#clientHTTP::Client (readonly)

Returns Current HTTP client instance.

Returns:



30
31
32
# File 'lib/raptor-io/protocol/http/request/manipulator.rb', line 30

def client
  @client
end

#optionsHash (readonly)

Returns Manipulator options.

Returns:

  • (Hash)

    Manipulator options.



36
37
38
# File 'lib/raptor-io/protocol/http/request/manipulator.rb', line 36

def options
  @options
end

#requestHTTP::Request (readonly)

Returns Request to manipulate.

Returns:



33
34
35
# File 'lib/raptor-io/protocol/http/request/manipulator.rb', line 33

def request
  @request
end

Class Method Details

.inherited(manipulator_klass) ⇒ Object

Registers manipulators which inherit from this class.

See Also:

  • Request::Manipulators#register


106
107
108
109
110
111
# File 'lib/raptor-io/protocol/http/request/manipulator.rb', line 106

def inherited( manipulator_klass )
  Request::Manipulators.register(
      Request::Manipulators.path_to_name( caller.first.split( ':' ).first ),
      manipulator_klass
  )
end

.shortnameString

Returns Shortname of ‘self`.

Returns:

  • (String)

    Shortname of ‘self`.



99
100
101
# File 'lib/raptor-io/protocol/http/request/manipulator.rb', line 99

def shortname
  @shortname ||= Request::Manipulators.class_to_name( self )
end

.validate_options(&block) ⇒ Hash{Symbol=>Array<String>}

Returns Option names keys for and error messages for values.

Returns:

  • (Hash{Symbol=>Array<String>})

    Option names keys for and error messages for values.



81
82
83
84
# File 'lib/raptor-io/protocol/http/request/manipulator.rb', line 81

def validate_options( &block )
  fail ArgumentError, 'Missing block.' if !block_given?
  @validator = block
end

.validate_options!(options, client) ⇒ Hash{Symbol=>Array<String>}

This method is abstract.

Returns Option names keys for and error messages for values.

Parameters:

  • options (Hash)

    Manipulator options.

  • client (HTTP::Client)

    Applicable client.

Returns:

  • (Hash{Symbol=>Array<String>})

    Option names keys for and error messages for values.



94
95
96
# File 'lib/raptor-io/protocol/http/request/manipulator.rb', line 94

def validate_options!( options, client )
  @validator ? @validator.call( options, client ) : {}
end

Instance Method Details

#datastoreHash

Returns Persistent storage – per Client instance.

Returns:

  • (Hash)

    Persistent storage – per Client instance.



62
63
64
# File 'lib/raptor-io/protocol/http/request/manipulator.rb', line 62

def datastore
  client.datastore[shortname]
end

#delegate(manipulator, opts = options) ⇒ Object

Delegates the work to another manipulator.

Parameters:

  • manipulator (Symbol)

    Manipulator to run.

  • opts (Hash) (defaults to: options)

    Manipulator options.



57
58
59
# File 'lib/raptor-io/protocol/http/request/manipulator.rb', line 57

def delegate( manipulator, opts = options )
  Request::Manipulators.process( manipulator, client, request, opts )
end

#runObject

This method is abstract.

Delivers the manipulator’s payload.



50
51
# File 'lib/raptor-io/protocol/http/request/manipulator.rb', line 50

def run
end

#shortnameString

Returns Shortname of ‘self`.

Returns:

  • (String)

    Shortname of ‘self`.



67
68
69
# File 'lib/raptor-io/protocol/http/request/manipulator.rb', line 67

def shortname
  self.class.shortname
end

#validate_optionsHash{Symbol=>Array<String>}

Returns Option names keys for and error messages for values.

Returns:

  • (Hash{Symbol=>Array<String>})

    Option names keys for and error messages for values.



73
74
75
# File 'lib/raptor-io/protocol/http/request/manipulator.rb', line 73

def validate_options
  self.class.validate_options!( options, client )
end