Class: Restspec::Endpoints::DSL
- Inherits:
-
Object
- Object
- Restspec::Endpoints::DSL
- Defined in:
- lib/restspec/endpoints/dsl.rb
Overview
The Endpoints DSL is what should be used inside the endpoints.rb
file.
This class is related to the top-level namespace of the DSL.
Instance Method Summary collapse
-
#namespace(name, base_path: nil, &block) ⇒ Object
Generates a new namespace that is just an entity that groups a couple of endpoints for whatever reason.
-
#resource(name, base_path: nil, &block) ⇒ Object
This is actually a kind of namespace factory, that creates a namespace that have the next conventions: - The name is a pluralization of another name.
Instance Method Details
#namespace(name, base_path: nil, &block) ⇒ Object
Generates a new namespace that is just an entity that groups a couple of endpoints for whatever reason.
24 25 26 27 28 29 |
# File 'lib/restspec/endpoints/dsl.rb', line 24 def namespace(name, base_path: nil, &block) namespace = Namespace.create(name.to_s) namespace.base_path = base_path namespace_dsl = NamespaceDSL.new(namespace) namespace_dsl.instance_eval(&block) end |
#resource(name, base_path: nil, &block) ⇒ Object
This is actually a kind of namespace factory, that creates a namespace that have the next conventions:
- The name is a pluralization of another name. (products, books, etc)
- The base_path is, when not defined, the name of the namespace prepended with a "/"
- Attaches a schema with the name of the namespace singularized to the namespace. (product, book, etc)
In this way, it can express REST resources that groups a couple of endpoints related to them.
49 50 51 52 53 54 55 56 |
# File 'lib/restspec/endpoints/dsl.rb', line 49 def resource(name, base_path: nil, &block) resource_name = name.to_s.singularize.to_sym namespace name, base_path: (base_path || "/#{name}") do schema resource_name instance_eval(&block) end end |