class Restspec::Endpoints::Namespace

Attributes

base_path[RW]
children_namespaces[RW]
endpoints[RW]
name[W]
parent_namespace[RW]

Public Class Methods

create(name) click to toggle source
# File lib/restspec/endpoints/namespace.rb, line 9
def self.create(name)
  namespace = new(name)
  Stores::NamespaceStore.store(namespace)
  namespace
end
new(name = '') click to toggle source
# File lib/restspec/endpoints/namespace.rb, line 15
def initialize(name = '')
  self.name = name
  self.endpoints = []
  self.children_namespaces = []
end

Public Instance Methods

add_anonymous_children_namespace() click to toggle source
# 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) click to toggle source
# File lib/restspec/endpoints/namespace.rb, line 28
def add_endpoint(endpoint)
  endpoint.namespace = self
  endpoints << endpoint
  endpoint
end
all_endpoints() click to toggle source
# File lib/restspec/endpoints/namespace.rb, line 38
def all_endpoints
  endpoints + children_namespaces.map { |ns| ns.all_endpoints }.flatten
end
anonymous?() click to toggle source
# File lib/restspec/endpoints/namespace.rb, line 62
def anonymous?
  @name.blank?
end
full_base_path() click to toggle source
# 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) click to toggle source
# File lib/restspec/endpoints/namespace.rb, line 34
def get_endpoint(endpoint_name)
  search_internal_endpoint(endpoint_name) || search_child_endpoint(endpoint_name)
end
name() click to toggle source
# 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
top_level_namespace?() click to toggle source
# File lib/restspec/endpoints/namespace.rb, line 42
def top_level_namespace?
  parent_namespace.nil?
end

Private Instance Methods

search_child_endpoint(endpoint_name) click to toggle source
# File lib/restspec/endpoints/namespace.rb, line 76
def search_child_endpoint(endpoint_name)
  children_namespaces.each do |children_namespace|
    child_endpoint = children_namespace.get_endpoint(endpoint_name)
    return child_endpoint if child_endpoint.present?
  end

  return nil
end
search_internal_endpoint(endpoint_name) click to toggle source
# File lib/restspec/endpoints/namespace.rb, line 70
def search_internal_endpoint(endpoint_name)
  endpoints.find do |endpoint|
    endpoint.name == endpoint_name
  end
end