Class: PrestoHTTP::ClassAPI
- Inherits:
-
Object
- Object
- PrestoHTTP::ClassAPI
- Includes:
- API, Config
- Defined in:
- lib/presto/http.rb,
lib/presto/http/class-api/api.rb
Constant Summary
Constant Summary
Constants included from PrestoCore::Utils
PrestoCore::Utils::PATH_MODIFIERS, PrestoCore::Utils::STATUS__NOT_FOUND, PrestoCore::Utils::STATUS__OK, PrestoCore::Utils::STATUS__PERMANENT_REDIRECT, PrestoCore::Utils::STATUS__REDIRECT, PrestoCore::Utils::STATUS__RESTRICTED, PrestoCore::Utils::STATUS__SERVER_ERROR
Instance Attribute Summary (collapse)
-
- (Object) alias(action = nil, *aliases)
allow any action to serve multiple paths.
-
- (Object) canonical
readonly
Returns the value of attribute canonical.
-
- (Object) path
readonly
Returns the value of attribute path.
Attributes included from Config
#cache_pool, #content_type, #middleware, #path_rules, #rewrite_rules
Instance Method Summary (collapse)
- - (Object) [](action_or_url)
- - (Object) action_map
- - (Boolean) configurable?
-
- (Object) env
in order built-in browser to work, class api should be compliant with instance api.
-
- (ClassAPI) initialize(controller)
constructor
initializing the HTTP API to be used at class level.
-
- (Object) map(*paths)
setting controller's root path.
- - (Object) root
Methods included from Config
#after, #auth, #basic_auth, #before, #cache, #digest_auth, #encoding, #error, #html_auth, #rewrite, #use
Methods included from PrestoCore::Utils
build_path, #extract_controllers, is_controller?, normalize_path, rootify_url
Methods included from API
#authorization_form, #build_path, #get, #mime_type, #normalize_path, #post, #route, #xhr_get, #xhr_post
Constructor Details
- (ClassAPI) initialize(controller)
initializing the HTTP API to be used at class level.
12 13 14 15 16 |
# File 'lib/presto/http/class-api/api.rb', line 12 def initialize controller super @controller = controller @canonical, @alias = {}, {} end |
Instance Attribute Details
- (Object) alias(action = nil, *aliases)
allow any action to serve multiple paths.
53 54 55 56 |
# File 'lib/presto/http/class-api/api.rb', line 53 def alias action = nil, *aliases @alias[action] = aliases if action && aliases.size > 0 && configurable? @alias end |
- (Object) canonical (readonly)
Returns the value of attribute canonical
7 8 9 |
# File 'lib/presto/http/class-api/api.rb', line 7 def canonical @canonical end |
- (Object) path (readonly)
Returns the value of attribute path
7 8 9 |
# File 'lib/presto/http/class-api/api.rb', line 7 def path @path end |
Instance Method Details
- (Object) [](action_or_url)
62 63 64 |
# File 'lib/presto/http/class-api/api.rb', line 62 def [] action_or_url @controller.ctrl[action_or_url] end |
- (Object) action_map
58 59 60 |
# File 'lib/presto/http/class-api/api.rb', line 58 def action_map @controller.ctrl.action_map end |
- (Boolean) configurable?
66 67 68 |
# File 'lib/presto/http/class-api/api.rb', line 66 def configurable? @controller.ctrl.configurable? end |
- (Object) env
in order built-in browser to work, class api should be compliant with instance api.
72 73 74 |
# File 'lib/presto/http/class-api/api.rb', line 72 def env {} end |
- (Object) map(*paths)
controller root can be set only once.
controller root always should start with a single slash.
setting controller's root path. only mapped controllers will respond to HTTP requests.
if multiple paths provided, first path is treated as root, and other ones are treated as canonical routes. canonical routes allow controller to serve multiple paths.
28 29 30 31 32 |
# File 'lib/presto/http/class-api/api.rb', line 28 def map *paths return unless configurable? @path = rootify_url(paths.shift.to_s).freeze @canonical = paths.map { |p| rootify_url(p.to_s) }.freeze end |
- (Object) root
34 35 36 |
# File 'lib/presto/http/class-api/api.rb', line 34 def root '' << @controller.ctrl.slice.root << path end |