Class: Mnemosyne::Middleware::Rack::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/mnemosyne/middleware/rack.rb

Instance Method Summary collapse

Constructor Details

#initialize(body, &block) ⇒ Proxy

Returns a new instance of Proxy.



7
8
9
10
11
# File 'lib/mnemosyne/middleware/rack.rb', line 7

def initialize(body, &block)
  @body = body
  @block = block
  @closed = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/mnemosyne/middleware/rack.rb', line 19

def method_missing(*args)
  super if args.first && args.first.to_s == 'to_ary'

  if block_given?
    @body.__send__(*args, &Proc.new)
  else
    @body.__send__(*args)
  end
end

Instance Method Details

#close ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/mnemosyne/middleware/rack.rb', line 29

def close
  return if @closed
  @closed = true

  begin
    @body.close if @body.respond_to? :close
  ensure
    @block.call
  end
end

#closed? ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/mnemosyne/middleware/rack.rb', line 40

def closed?
  @closed
end

#each(*args) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/mnemosyne/middleware/rack.rb', line 44

def each(*args)
  if block_given?
    @body.each(*args, &Proc.new)
  else
    @body.each(*args)
  end
end

#respond_to_missing?(*args) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/mnemosyne/middleware/rack.rb', line 13

def respond_to_missing?(*args)
  return false if args.first && args.first.to_s == 'to_ary'

  @body.respond_to?(*args)
end