Class: Restspec::Endpoints::NamespaceDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/restspec/endpoints/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute common_endpoints_config_block to.



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_pathObject

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

#namespaceObject

Returns the value of attribute namespace.



28
29
30
# File 'lib/restspec/endpoints/dsl.rb', line 28

def namespace
  @namespace
end

#resource_endpoint_base_pathObject

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