Module: Renee::Core::RackInteraction

Included in:
Renee::Core
Defined in:
lib/renee_core/rack_interaction.rb

Overview

A module that defines useful Rack interaction methods.

Instance Method Summary collapse

Instance Method Details

#build { ... } ⇒ Object

Creates an ad-hoc Rack application within the context of a Rack::Builder.

Examples:

get { halt build { use Rack::ContentLength; run proc { |env| Rack::Response.new("Hello!").finish } } }

Yields:

  • The block to be used to instantiate the Rack::Builder.



11
12
13
# File 'lib/renee_core/rack_interaction.rb', line 11

def build(&blk)
  run Rack::Builder.new(&blk).to_app
end

#build!(&blk) ⇒ Object

Creates an ad-hoc Rack application within the context of a Rack::Builder that immediately halts when done.

Examples:

get { halt build { use Rack::ContentLength; run proc { |env| Rack::Response.new("Hello!").finish } } }


21
22
23
# File 'lib/renee_core/rack_interaction.rb', line 21

def build!(&blk)
  halt build(&blk)
end

#run(app = nil) {|env| ... } ⇒ Object

Runs a rack application. You must either use app or blk.

Examples:

get { halt run proc { |env| Renee::Core::Response.new("Hello!").finish } }

Parameters:

  • app (#call) (defaults to: nil)

    The application to call.

Yields:

  • (env)

    The block to yield to



33
34
35
36
# File 'lib/renee_core/rack_interaction.rb', line 33

def run(app = nil, &blk)
  raise "You cannot supply both a block and an app" unless app.nil? ^ blk.nil?
  (app || blk).call(env)
end

#run!(app = nil, &blk) ⇒ Object

Runs a rack application and halts immediately.

Examples:

get { run proc { |env| Renee::Core::Response.new("Hello!").finish } }

Parameters:

  • app (#call) (defaults to: nil)

    The application to call.

See Also:



45
46
47
# File 'lib/renee_core/rack_interaction.rb', line 45

def run!(app = nil, &blk)
  halt run(app, &blk)
end