Module Innate::SingletonMethods
In: lib/innate.rb
lib/innate/node.rb
lib/innate/state.rb
lib/innate/route.rb
lib/innate/dynamap.rb

script_name, path_info = env[‘SCRIPT_NAME’], env[‘PATH_INFO’] answer = app.call(env) env.merge!(‘SCRIPT_NAME’ => script_name, ‘PATH_INFO’ => path_info) answer

Methods

Constants

PROXY_OPTIONS = { :port => 'adapter.port', :host => 'adapter.host', :adapter => 'adapter.handler' }

Public Instance methods

Answer with object at location.

@example

  class Hello
    include Innate::Node
    map '/'
  end

  Innate.at('/') # => Hello

Treat Innate like a rack application, pass the rack env and optionally the mode the application runs in.

@param [Hash] env rack env @param [Symbol] mode indicates the mode of the application @default mode options.mode @return [Array] with [body, header, status] @author manveru

@example Innate can be started by:

  Innate.start :file => __FILE__
  Innate.start :root => File.dirname(__FILE__)

Either setting will surpress the warning that might show up on startup and tells you it couldn‘t find an explicit root.

In case these options are not passed we will try to figure out a file named `start.rb` in the process’ working directory and assume it‘s a valid point.

Maps the given object or block to location, object must respond to call in order to be of any use.

@example with passed object

  Innate.map('/', lambda{|env| [200, {}, "Hello, World"] })
  Innate.at('/').call({}) # => [200, {}, "Hello, World"]

@example with passed block

  Innate.map('/'){|env| [200, {}, ['Hello, World!']] }
  Innate.at('/').call({})

Convenience method to include the Node module into node and map to a location.

@param [to_s] location where the node is mapped to @param [Node, nil] node the class that will be a node, will try to

                           look it up if not given

@return [Class, Module] the node argument or detected class will be

                           returned

@api external @see SingletonMethods::node_from_backtrace @author manveru

Cheap hack that works reasonably well to avoid passing self all the time to Innate::node We simply search the file that Innate::node was called in for the first class definition above the line that Innate::node was called and look up the constant. If there are any problems with this (filenames containing ’:’ or metaprogramming) just pass the node parameter explicitly to Innate::node

@param [Array<String>, #[]] backtrace

@return [Class, Module]

@api internal @see SingletonMethods::node @author manveru

The method that starts the whole business.

Call Innate.start after you defined your application.

Usually, this is a blocking call and will not return until the adapter has finished, which usually happens when you kill the application or hit ^C.

We do return if options.started is true, which indicates that all you wanted to do is setup the environment and update options.

@example usage

  # passing options
  Innate.start :adapter => :mongrel, :mode => :live

  # defining custom middleware
  Innate.start do |m|
    m.innate
  end

@return [nil] if options.started is true @yield [MiddlewareCompiler] @param [Proc] block will be passed to {middleware!}

@option param :host [String] (‘0.0.0.0’)

  IP address or hostname that we respond to - 0.0.0.0 for all

@option param :port [Fixnum] (7000)

  Port for the server

@option param :started [boolean] (false)

  Indicate that calls Innate::start will be ignored

@option param :adapter [Symbol] (:webrick)

  Web server to run on

@option param :setup [Array] ([Innate::Cache, Innate::Node])

  Will send ::setup to each element during Innate::start

@option param :header [Hash] ({‘Content-Type’ => ‘text/html’})

  Headers that will be merged into the response before Node::call

@option param :trap [String] (‘SIGINT’)

  Trap this signal to issue shutdown, nil/false to disable trap

@option param :mode [Symbol] (:dev)

  Indicates which default middleware to use, (:dev|:live)

Use this method to achieve thread-safety for sensitive operations.

This should be of most use when manipulating files to prevent other threads from doing the same, no other code will be scheduled during execution of this method.

@param [Proc] block the things you want to execute

Returns one of the paths the given object is mapped to.

@example

  class Hello
    include Innate::Node
    map '/'
  end

  Innate.to(Hello) # => '/'

[Validate]