Class: Restspec::Endpoints::Namespace
- Inherits:
-
Object
- Object
- Restspec::Endpoints::Namespace
- Defined in:
- lib/restspec/endpoints/namespace.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
writeonly
Sets the attribute base_path.
-
#children_namespaces ⇒ Object
Returns the value of attribute children_namespaces.
-
#endpoints ⇒ Object
readonly
Returns the value of attribute endpoints.
- #name ⇒ Object readonly
-
#parent_namespace ⇒ Object
Returns the value of attribute parent_namespace.
-
#schema_extensions ⇒ Object
Returns the value of attribute schema_extensions.
- #schema_name ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #add_anonymous_children_namespace ⇒ Object
- #add_endpoint(endpoint) ⇒ Object
- #all_endpoints ⇒ Object
- #anonymous? ⇒ Boolean
- #full_base_path ⇒ Object
- #get_endpoint(endpoint_name) ⇒ Object
-
#initialize(name = '') ⇒ Namespace
constructor
A new instance of Namespace.
- #top_level_namespace? ⇒ Boolean
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
4 5 6 |
# File 'lib/restspec/endpoints/namespace.rb', line 4 def base_path=(value) @base_path = value end |
#children_namespaces ⇒ Object
Returns the value of attribute children_namespaces.
4 5 6 |
# File 'lib/restspec/endpoints/namespace.rb', line 4 def children_namespaces @children_namespaces end |
#endpoints ⇒ Object
Returns the value of attribute endpoints.
6 7 8 |
# File 'lib/restspec/endpoints/namespace.rb', line 6 def endpoints @endpoints end |
#name ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/restspec/endpoints/namespace.rb', line 57 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.
4 5 6 |
# File 'lib/restspec/endpoints/namespace.rb', line 4 def parent_namespace @parent_namespace end |
#schema_extensions ⇒ Object
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_name ⇒ Object
53 54 55 |
# File 'lib/restspec/endpoints/namespace.rb', line 53 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_namespace ⇒ Object
20 21 22 23 24 25 |
# File 'lib/restspec/endpoints/namespace.rb', line 20 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
27 28 29 30 31 |
# File 'lib/restspec/endpoints/namespace.rb', line 27 def add_endpoint(endpoint) endpoint.namespace = self endpoints << endpoint endpoint end |
#all_endpoints ⇒ Object
37 38 39 |
# File 'lib/restspec/endpoints/namespace.rb', line 37 def all_endpoints endpoints + children_namespaces.map { |ns| ns.all_endpoints }.flatten end |
#anonymous? ⇒ Boolean
65 66 67 |
# File 'lib/restspec/endpoints/namespace.rb', line 65 def anonymous? @name.blank? end |
#full_base_path ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/restspec/endpoints/namespace.rb', line 45 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
41 42 43 |
# File 'lib/restspec/endpoints/namespace.rb', line 41 def top_level_namespace? parent_namespace.nil? end |