Class: DbAgile::Restful::Middleware
- Inherits:
-
Object
- Object
- DbAgile::Restful::Middleware
- Includes:
- Utils
- Defined in:
- lib/dbagile/restful/middleware.rb,
lib/dbagile/restful/middleware/get.rb,
lib/dbagile/restful/middleware/post.rb,
lib/dbagile/restful/middleware/utils.rb,
lib/dbagile/restful/middleware/delete.rb,
lib/dbagile/restful/middleware/one_database.rb
Defined Under Namespace
Modules: Delete, Get, Post, Utils Classes: OneDatabase
Constant Summary
Constants included from IO
IO::EXTENSION_TO_FORMAT, IO::FORMAT_TO_CONTENT_TYPE, IO::FORMAT_TO_MODULE, IO::KNOWN_FORMATS, IO::KNOWN_FROM_FORMATS, IO::KNOWN_TO_FORMATS, IO::ROUND_TRIP_OPTIONS
Instance Attribute Summary collapse
-
#delegates ⇒ Object
readonly
OneDatabase delegates.
-
#environment ⇒ Object
readonly
Environment.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Delegated according to the path.
-
#initialize(environment = DbAgile::default_environment, &block) ⇒ Middleware
constructor
Creates a Restful handler.
Methods included from Utils
#_200_, #_404_, #_500_, #_copyright_, #params_to_tuple, #to_xxx_enumerable
Methods included from IO
#known_extension?, #known_format?, #roundtrip_options
Constructor Details
#initialize(environment = DbAgile::default_environment, &block) ⇒ Middleware
Creates a Restful handler
21 22 23 24 25 26 |
# File 'lib/dbagile/restful/middleware.rb', line 21 def initialize(environment = DbAgile::default_environment, &block) raise "Environment may not be nil" if environment.nil? block.call(environment) if block @environment = environment _install end |
Instance Attribute Details
#delegates ⇒ Object (readonly)
OneDatabase delegates
18 19 20 |
# File 'lib/dbagile/restful/middleware.rb', line 18 def delegates @delegates end |
#environment ⇒ Object (readonly)
Environment
15 16 17 |
# File 'lib/dbagile/restful/middleware.rb', line 15 def environment @environment end |
Instance Method Details
#call(env) ⇒ Object
Delegated according to the path
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dbagile/restful/middleware.rb', line 37 def call(env) env['PATH_INFO'] =~ /^\/(\w+)(.*)$/ if $1 if delegates.key?($1.to_sym) env['PATH_INFO'] = $2 delegates[$1.to_sym].call(env) else _404_(env) end else _copyright_(env) end end |