Class: Restspec::Endpoints::Namespace

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = '') ⇒ Namespace

Returns a new instance of Namespace.



14
15
16
17
18
# File 'lib/restspec/endpoints/namespace.rb', line 14

def initialize(name = '')
  self.name = name
  self.endpoints = []
  self.children_namespaces = []
end

Instance Attribute Details

#base_path=(value) ⇒ Object

Sets the attribute base_path

Parameters:

  • value

    the value to set the attribute base_path to.



4
5
6
# File 'lib/restspec/endpoints/namespace.rb', line 4

def base_path=(value)
  @base_path = value
end

#children_namespacesObject

Returns the value of attribute children_namespaces.



4
5
6
# File 'lib/restspec/endpoints/namespace.rb', line 4

def children_namespaces
  @children_namespaces
end

#endpointsObject

Returns the value of attribute endpoints.



6
7
8
# File 'lib/restspec/endpoints/namespace.rb', line 6

def endpoints
  @endpoints
end

#nameObject



53
54
55
56
57
58
59
# File 'lib/restspec/endpoints/namespace.rb', line 53

def name
  if top_level_namespace?
    @name
  else
    [parent_namespace.name, @name].reject(&:blank?).join('/')
  end
end

#parent_namespaceObject

Returns the value of attribute parent_namespace.



4
5
6
# File 'lib/restspec/endpoints/namespace.rb', line 4

def parent_namespace
  @parent_namespace
end

#schema_extensionsObject

Returns the value of attribute schema_extensions.



4
5
6
# File 'lib/restspec/endpoints/namespace.rb', line 4

def schema_extensions
  @schema_extensions
end

#schema_nameObject



49
50
51
# File 'lib/restspec/endpoints/namespace.rb', line 49

def schema_name
  @schema_name || parent_namespace.try(:schema_name)
end

Class Method Details

.create(name = '') ⇒ Object



8
9
10
11
12
# File 'lib/restspec/endpoints/namespace.rb', line 8

def self.create(name = '')
  namespace = new(name)
  Stores::NamespaceStore.store(namespace)
  namespace
end

Instance Method Details

#add_anonymous_children_namespaceObject



20
21
22
23
24
25
# File 'lib/restspec/endpoints/namespace.rb', line 20

def add_anonymous_children_namespace
  anonymous_namespace = Namespace.create
  anonymous_namespace.parent_namespace = self
  children_namespaces << anonymous_namespace
  anonymous_namespace
end

#add_endpoint(endpoint) ⇒ Object



27
28
29
30
31
# File 'lib/restspec/endpoints/namespace.rb', line 27

def add_endpoint(endpoint)
  endpoint.namespace = self
  endpoints << endpoint
  endpoint
end

#anonymous?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/restspec/endpoints/namespace.rb', line 61

def anonymous?
  @name.blank?
end

#full_base_pathObject



41
42
43
44
45
46
47
# File 'lib/restspec/endpoints/namespace.rb', line 41

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



33
34
35
# File 'lib/restspec/endpoints/namespace.rb', line 33

def get_endpoint(endpoint_name)
  search_internal_endpoint(endpoint_name) || search_child_endpoint(endpoint_name)
end

#top_level_namespace?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/restspec/endpoints/namespace.rb', line 37

def top_level_namespace?
  parent_namespace.nil?
end