Class: Puuko::Application
- Inherits:
-
Object
- Object
- Puuko::Application
- Defined in:
- lib/puuko/application.rb
Class Method Summary collapse
Instance Method Summary collapse
- #configuration ⇒ Object
- #delete(path, to: Puuko::Endpoints::NotFound, params: {}) ⇒ Object
- #get(path, to: Puuko::Endpoints::NotFound, params: {}) ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #logger ⇒ Object
- #patch(path, to: Puuko::Endpoints::NotFound, params: {}) ⇒ Object
- #post(path, to: Puuko::Endpoints::NotFound, params: {}) ⇒ Object
- #put(path, to: Puuko::Endpoints::NotFound, params: {}) ⇒ Object
- #rack_app ⇒ Object
- #router=(router) ⇒ Object
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
26 27 28 |
# File 'lib/puuko/application.rb', line 26 def initialize @routes = [] end |
Class Method Details
.configuration ⇒ Object
21 22 23 |
# File 'lib/puuko/application.rb', line 21 def configuration @configuration end |
.configure(klass = nil) {|@configuration| ... } ⇒ Object
11 12 13 14 15 |
# File 'lib/puuko/application.rb', line 11 def configure(klass = nil) @configuration = klass.new if klass yield @configuration if block_given? @configuration end |
.logger ⇒ Object
17 18 19 |
# File 'lib/puuko/application.rb', line 17 def logger @configuration.logger end |
Instance Method Details
#configuration ⇒ Object
50 51 52 |
# File 'lib/puuko/application.rb', line 50 def configuration self.class.configuration end |
#delete(path, to: Puuko::Endpoints::NotFound, params: {}) ⇒ Object
46 47 48 |
# File 'lib/puuko/application.rb', line 46 def delete(path, to: Puuko::Endpoints::NotFound, params: {}) @routes << Puuko::Route.new(:delete, path, to, params) end |
#get(path, to: Puuko::Endpoints::NotFound, params: {}) ⇒ Object
30 31 32 |
# File 'lib/puuko/application.rb', line 30 def get(path, to: Puuko::Endpoints::NotFound, params: {}) @routes << Puuko::Route.new(:get, path, to, params) end |
#logger ⇒ Object
54 55 56 |
# File 'lib/puuko/application.rb', line 54 def logger self.class.logger end |
#patch(path, to: Puuko::Endpoints::NotFound, params: {}) ⇒ Object
42 43 44 |
# File 'lib/puuko/application.rb', line 42 def patch(path, to: Puuko::Endpoints::NotFound, params: {}) @routes << Puuko::Route.new(:patch, path, to, params) end |
#post(path, to: Puuko::Endpoints::NotFound, params: {}) ⇒ Object
34 35 36 |
# File 'lib/puuko/application.rb', line 34 def post(path, to: Puuko::Endpoints::NotFound, params: {}) @routes << Puuko::Route.new(:post, path, to, params) end |
#put(path, to: Puuko::Endpoints::NotFound, params: {}) ⇒ Object
38 39 40 |
# File 'lib/puuko/application.rb', line 38 def put(path, to: Puuko::Endpoints::NotFound, params: {}) @routes << Puuko::Route.new(:put, path, to, params) end |
#rack_app ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/puuko/application.rb', line 62 def rack_app klass = Class.new(Puuko::Base) do set :protection, except: :json_csrf configure :production, :development do enable :logging end end configuration.before_filters.each do |before_filter| klass.before(&before_filter) end @routes.each do |route| logger.debug "Register #{route.verb} #{route.path} to #{route.endpoint.name}" klass.public_send(route.verb, route.path) do handler = route.endpoint.new(request, route.params.merge(params)) handler.execute [ handler.response.status, handler.response.headers, handler.response.body.to_json ] end end configuration.after_filters.each do |after_filter| klass.after(&after_filter) end klass end |
#router=(router) ⇒ Object
58 59 60 |
# File 'lib/puuko/application.rb', line 58 def router=(router) router.apply(self) end |