Module: Flon::DSL
- Defined in:
- lib/flon/dsl.rb
Overview
This module holds Flon’s DSL. You should extend it in your class.
Routing collapse
-
#delete(path) ⇒ void
Creates a DELETE route from path, bound to the next defined method.
-
#get(path) ⇒ void
Creates a GET route from path, bound to the next defined method.
-
#namespace(path) ⇒ void
(also: #version)
Creates a namespace of the given path.
-
#patch(path) ⇒ void
Creates a PATCH route from path, bound to the next defined method.
-
#post(path) ⇒ void
Creates a POST route from path, bound to the next defined method.
-
#put(path) ⇒ void
Creates a PUT route from path, bound to the next defined method.
Instance Method Summary collapse
- #method_added(name) ⇒ Object private
- #namespaces ⇒ Object private
- #router ⇒ Object private
Instance Method Details
#delete(path) ⇒ void
This method returns an undefined value.
Creates a DELETE route from path, bound to the next defined method.
40 41 42 43 44 |
# File 'lib/flon/dsl.rb', line 40 %i[get post put delete patch].each do |http_method| define_method(http_method) do |path| @current_route = [http_method, namespaces.join + path] end end |
#get(path) ⇒ void
This method returns an undefined value.
Creates a GET route from path, bound to the next defined method.
40 41 42 43 44 |
# File 'lib/flon/dsl.rb', line 40 %i[get post put delete patch].each do |http_method| define_method(http_method) do |path| @current_route = [http_method, namespaces.join + path] end end |
#method_added(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
81 82 83 84 85 86 87 88 |
# File 'lib/flon/dsl.rb', line 81 def method_added(name) return unless @current_route http_method, path = @current_route router.add_route(http_method, path, instance_method(name)) @current_route = nil end |
#namespace(path) ⇒ void Also known as: version
This method returns an undefined value.
Creates a namespace of the given path. If a block is given, the namespace is local to the block. If not, it is applied to the rest of the API. You may not call this method without a block twice.
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/flon/dsl.rb', line 52 def namespace(path) if block_given? namespaces.push(path) yield namespaces.pop else unless namespaces.empty? raise Flon::Error, 'cannot declare a nested global namespace or declare a global namespace twice' end namespaces.push(path) end end |
#namespaces ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 |
# File 'lib/flon/dsl.rb', line 76 def namespaces @namespaces ||= [] end |
#patch(path) ⇒ void
This method returns an undefined value.
Creates a PATCH route from path, bound to the next defined method.
40 41 42 43 44 |
# File 'lib/flon/dsl.rb', line 40 %i[get post put delete patch].each do |http_method| define_method(http_method) do |path| @current_route = [http_method, namespaces.join + path] end end |
#post(path) ⇒ void
This method returns an undefined value.
Creates a POST route from path, bound to the next defined method.
40 41 42 43 44 |
# File 'lib/flon/dsl.rb', line 40 %i[get post put delete patch].each do |http_method| define_method(http_method) do |path| @current_route = [http_method, namespaces.join + path] end end |
#put(path) ⇒ void
This method returns an undefined value.
Creates a PUT route from path, bound to the next defined method.
40 41 42 43 44 |
# File 'lib/flon/dsl.rb', line 40 %i[get post put delete patch].each do |http_method| define_method(http_method) do |path| @current_route = [http_method, namespaces.join + path] end end |