Class: Restfulness::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/restfulness/application.rb

Overview

The Restulness::Application is the starting point. It’ll deal with defining the initial configuration, and handle incoming requests from rack.

Build your own Restfulness applications by inheriting from this class:

class MyApp < Restfulness::Application

  routes do
    scope 'api' do # scope not supported yet!
      add 'journey', JourneyResource
      add 'journeys', JourneyCollectionResource
    end
  end

end

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.middlewaresObject

A simple array of rack middlewares that will be applied before handling the request in Restfulness.

Probably most useful for adding the ActiveDispatch::Reloader as used by Rails to reload on each request. e.g.

middlewares << ActiveDispatch::Reloader


64
65
66
# File 'lib/restfulness/application.rb', line 64

def middlewares
  @middlewares
end

.routerObject

Returns the value of attribute router.



49
50
51
# File 'lib/restfulness/application.rb', line 49

def router
  @router
end

Class Method Details

.loggerObject

Quick access to the Restfulness logger.



69
70
71
# File 'lib/restfulness/application.rb', line 69

def logger
  Restfulness.logger
end

.logger=(logger) ⇒ Object

Override the default Restfulness logger.



74
75
76
# File 'lib/restfulness/application.rb', line 74

def logger=(logger)
  Restfulness.logger = logger
end

.routes(&block) ⇒ Object



51
52
53
54
# File 'lib/restfulness/application.rb', line 51

def routes(&block)
  # Store the block so we can parse it at run time (autoload win!)
  @router = Router.new(&block)
end

Instance Method Details

#call(env) ⇒ Object

Rack Handling. Forward rack call to dispatcher



29
30
31
32
# File 'lib/restfulness/application.rb', line 29

def call(env)
  @app ||= build_rack_app
  @app.call(env)
end

#routerObject



23
24
25
# File 'lib/restfulness/application.rb', line 23

def router
  self.class.router
end