Class: Restspec::Endpoints::Namespace
- Inherits:
-
Object
- Object
- Restspec::Endpoints::Namespace
show all
- Includes:
- HasSchemas
- Defined in:
- lib/restspec/endpoints/namespace.rb
Constant Summary
Constants included
from HasSchemas
HasSchemas::DEFAULT_ROLES, HasSchemas::ROLES
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from HasSchemas
#add_schema, #all_schemas, #remove_schemas, #schema_for, #schema_roles
Constructor Details
#initialize(name = '') ⇒ Namespace
Returns a new instance of Namespace.
15
16
17
18
19
|
# File 'lib/restspec/endpoints/namespace.rb', line 15
def initialize(name = '')
self.name = name
self.endpoints = []
self.children_namespaces = []
end
|
Instance Attribute Details
#base_path=(value) ⇒ Object
Sets the attribute base_path
6
7
8
|
# File 'lib/restspec/endpoints/namespace.rb', line 6
def base_path=(value)
@base_path = value
end
|
#children_namespaces ⇒ Object
Returns the value of attribute children_namespaces.
6
7
8
|
# File 'lib/restspec/endpoints/namespace.rb', line 6
def children_namespaces
@children_namespaces
end
|
#endpoints ⇒ Object
Returns the value of attribute endpoints.
7
8
9
|
# File 'lib/restspec/endpoints/namespace.rb', line 7
def endpoints
@endpoints
end
|
#name ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/restspec/endpoints/namespace.rb', line 54
def name
if top_level_namespace?
@name
else
[parent_namespace.name, @name].reject(&:blank?).join('/')
end
end
|
#parent_namespace ⇒ Object
Returns the value of attribute parent_namespace.
6
7
8
|
# File 'lib/restspec/endpoints/namespace.rb', line 6
def parent_namespace
@parent_namespace
end
|
Class Method Details
.create(name) ⇒ Object
9
10
11
12
13
|
# File 'lib/restspec/endpoints/namespace.rb', line 9
def self.create(name)
namespace = new(name)
Stores::NamespaceStore.store(namespace)
namespace
end
|
Instance Method Details
#add_anonymous_children_namespace ⇒ Object
21
22
23
24
25
26
|
# File 'lib/restspec/endpoints/namespace.rb', line 21
def add_anonymous_children_namespace
anonymous_namespace = Namespace.new('')
anonymous_namespace.parent_namespace = self
children_namespaces << anonymous_namespace
anonymous_namespace
end
|
#add_endpoint(endpoint) ⇒ Object
28
29
30
31
32
|
# File 'lib/restspec/endpoints/namespace.rb', line 28
def add_endpoint(endpoint)
endpoint.namespace = self
endpoints << endpoint
endpoint
end
|
#all_endpoints ⇒ Object
38
39
40
|
# File 'lib/restspec/endpoints/namespace.rb', line 38
def all_endpoints
endpoints + children_namespaces.map { |ns| ns.all_endpoints }.flatten
end
|
#anonymous? ⇒ Boolean
62
63
64
|
# File 'lib/restspec/endpoints/namespace.rb', line 62
def anonymous?
@name.blank?
end
|
#full_base_path ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/restspec/endpoints/namespace.rb', line 46
def full_base_path
if top_level_namespace?
base_path
else
parent_namespace.full_base_path + base_path
end
end
|
#get_endpoint(endpoint_name) ⇒ Object
34
35
36
|
# File 'lib/restspec/endpoints/namespace.rb', line 34
def get_endpoint(endpoint_name)
search_internal_endpoint(endpoint_name) || search_child_endpoint(endpoint_name)
end
|
#top_level_namespace? ⇒ Boolean
42
43
44
|
# File 'lib/restspec/endpoints/namespace.rb', line 42
def top_level_namespace?
parent_namespace.nil?
end
|