Class: Restspec::Endpoints::NamespaceDSL
- Inherits:
-
Object
- Object
- Restspec::Endpoints::NamespaceDSL
- Defined in:
- lib/restspec/endpoints/dsl.rb
Instance Attribute Summary collapse
-
#common_endpoints_config_block ⇒ Object
writeonly
Sets the attribute common_endpoints_config_block.
-
#endpoint_base_path ⇒ Object
Returns the value of attribute endpoint_base_path.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#resource_endpoint_base_path ⇒ Object
Returns the value of attribute resource_endpoint_base_path.
Instance Method Summary collapse
- #all(&endpoints_config) ⇒ Object
- #collection(base_path: nil, &block) ⇒ Object
- #endpoint(name, &block) ⇒ Object
-
#initialize(namespace) ⇒ NamespaceDSL
constructor
A new instance of NamespaceDSL.
- #member(base_path: nil, identifier_name: 'id', &block) ⇒ Object
- #schema(name, schema_extensions = {}) ⇒ Object
- #url_param(param, &value_or_example_block) ⇒ Object
Constructor Details
#initialize(namespace) ⇒ NamespaceDSL
Returns a new instance of NamespaceDSL.
30 31 32 33 |
# File 'lib/restspec/endpoints/dsl.rb', line 30 def initialize(namespace) self.namespace = namespace self.resource_endpoint_base_path = '' end |
Instance Attribute Details
#common_endpoints_config_block=(value) ⇒ Object
Sets the attribute common_endpoints_config_block
28 29 30 |
# File 'lib/restspec/endpoints/dsl.rb', line 28 def common_endpoints_config_block=(value) @common_endpoints_config_block = value end |
#endpoint_base_path ⇒ Object
Returns the value of attribute endpoint_base_path.
28 29 30 |
# File 'lib/restspec/endpoints/dsl.rb', line 28 def endpoint_base_path @endpoint_base_path end |
#namespace ⇒ Object
Returns the value of attribute namespace.
28 29 30 |
# File 'lib/restspec/endpoints/dsl.rb', line 28 def namespace @namespace end |
#resource_endpoint_base_path ⇒ Object
Returns the value of attribute resource_endpoint_base_path.
28 29 30 |
# File 'lib/restspec/endpoints/dsl.rb', line 28 def resource_endpoint_base_path @resource_endpoint_base_path end |
Instance Method Details
#all(&endpoints_config) ⇒ Object
72 73 74 |
# File 'lib/restspec/endpoints/dsl.rb', line 72 def all(&endpoints_config) self.common_endpoints_config_block = endpoints_config end |
#collection(base_path: nil, &block) ⇒ Object
61 62 63 64 65 |
# File 'lib/restspec/endpoints/dsl.rb', line 61 def collection(base_path: nil, &block) collection_namespace = namespace.add_anonymous_children_namespace collection_namespace.base_path = base_path NamespaceDSL.new(collection_namespace).instance_eval(&block) end |
#endpoint(name, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/restspec/endpoints/dsl.rb', line 35 def endpoint(name, &block) endpoint = Endpoint.new(name) endpoint_dsl = EndpointDSL.new(endpoint) namespace.add_endpoint(endpoint) endpoint_dsl.instance_eval(&block) endpoint_dsl.instance_eval(&common_endpoints_config_block) Restspec::EndpointStore.store(endpoint) end |
#member(base_path: nil, identifier_name: 'id', &block) ⇒ Object
55 56 57 58 59 |
# File 'lib/restspec/endpoints/dsl.rb', line 55 def member(base_path: nil, identifier_name: 'id', &block) member_namespace = namespace.add_anonymous_children_namespace member_namespace.base_path = base_path || "/:#{identifier_name}" NamespaceDSL.new(member_namespace).instance_eval(&block) end |
#schema(name, schema_extensions = {}) ⇒ Object
67 68 69 70 |
# File 'lib/restspec/endpoints/dsl.rb', line 67 def schema(name, schema_extensions = {}) namespace.schema_name = name namespace.schema_extensions = schema_extensions end |
#url_param(param, &value_or_example_block) ⇒ Object
76 77 78 79 80 |
# File 'lib/restspec/endpoints/dsl.rb', line 76 def url_param(param, &value_or_example_block) all do url_param(param, &value_or_example_block) end end |