Class: MonoVM::Whois::Transport::Middleware::Base

Inherits:
Transport::Base
  • Object
show all
Defined in:
lib/monovm/whois/transport/middleware/base.rb

Overview

Wraps another transport and forwards to it. Because it implements the same Base interface, layers compose in any order and nothing downstream can tell it is talking to a decorator.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Base

Returns a new instance of Base.



30
31
32
33
# File 'lib/monovm/whois/transport/middleware/base.rb', line 30

def initialize(app)
  @app = app
  super()
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



19
20
21
# File 'lib/monovm/whois/transport/middleware/base.rb', line 19

def app
  @app
end

Class Method Details

.builder(**options) ⇒ Object

A lambda suitable for Factory's middleware: list.

Factory.new(middleware: [Middleware::Cache.builder(ttl: 300)])


25
26
27
# File 'lib/monovm/whois/transport/middleware/base.rb', line 25

def builder(**options)
  ->(app) { new(app, **options) }
end

Instance Method Details

#fetch(query:, endpoint:) ⇒ Object



35
36
37
# File 'lib/monovm/whois/transport/middleware/base.rb', line 35

def fetch(query:, endpoint:)
  app.fetch(query: query, endpoint: endpoint)
end

#inspectObject



48
49
50
# File 'lib/monovm/whois/transport/middleware/base.rb', line 48

def inspect
  "#<#{self.class.name} -> #{app.inspect}>"
end

#supports?(endpoint) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/monovm/whois/transport/middleware/base.rb', line 39

def supports?(endpoint)
  app.supports?(endpoint)
end

#unwrapObject

Reach the real transport through any stack of decorators.



44
45
46
# File 'lib/monovm/whois/transport/middleware/base.rb', line 44

def unwrap
  app.is_a?(Base) ? app.unwrap : app
end