Module: Octarine::App::ClassMethods

Defined in:
lib/octarine/app.rb

Instance Method Summary collapse

Instance Method Details

#add_route(route) ⇒ Object

:nodoc:



52
53
54
# File 'lib/octarine/app.rb', line 52

def add_route(route) # :nodoc:
  (@handlers ||= []) << [__method__, route, nil]
end

#environmentObject

:call-seq: environment -> string

Returns the current enviroment. Defaults to “development”.



69
70
71
# File 'lib/octarine/app.rb', line 69

def environment
  ENV["RACK_ENV"] || "development"
end

#methodObject

:method: default :call-seq: default {|request| block }

Adds block as a handler for when no path is matched.



46
47
48
49
50
# File 'lib/octarine/app.rb', line 46

[:add, :get, :post, :delete, :put, :default].each do |method|
  define_method(method) do |*args, &block|
    (@handlers ||= []) << [method, *args, block]
  end
end

#new(*args) ⇒ Object

:nodoc:



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/octarine/app.rb', line 73

def new(*args) # :nodoc:
  instance = super
  instance.router = HttpRouter.new
  @handlers.each do |method, *args|
    block = args.pop
    instance.router.send(method, *args) do |env|
      instance.instance_exec(request_class.new(env), &block)
    end
  end
  instance
end

#request_class(klass = nil) ⇒ Object

:call-seq: request_class(klass)

Set the class of the request object handed to the path handler blocks. Defaults to Octarine::Request.



61
62
63
# File 'lib/octarine/app.rb', line 61

def request_class(klass=nil)
  klass ? @request_class = klass : @request_class || Octarine::Request
end