Class: TLAW::Namespace
Overview
Namespace is basically a container for Endpoints. It allows to
nest Ruby calls (like api.namespace1.namespace2.real_call(params)
),
optionally providing some parameters while nesting, like
worldbank.countries('uk').population(2016)
.
By default, namespaces nesting also means URL nesting (e.g.
base_url/namespace1/namespace2/endpoint
), but that could be altered
on namespace definition, see DSL module for details.
Typically, as with Endpoint, you never create namespace instances
or subclasses by yourself: you use DSL for their definition and
then call .<namespace_name>
method on parent namespace (or API instance):
class SampleAPI < TLAW::API
# namespace definition:
namespace :my_ns do
endpoint :weather
end
end
# usage:
api = SampleAPI.new
api.namespaces[:my_ns] # => class SampleAPI::MyNS, subclass of namespace
api.my_ns # => short-living instance of SampleAPI::MyNS
api.my_ns.weather # => real call to API
Direct Known Subclasses
Class Method Summary collapse
-
.describe(definition = nil) ⇒ Util::Description
Detailed namespace documentation.
-
.endpoints ⇒ Hash{Symbol => Endpoint}
Lists all current namespace's endpoints as a hash.
- .inspect ⇒ Object
-
.namespaces ⇒ Hash{Symbol => Namespace}
Lists all current namespace's nested namespaces as a hash.
Instance Method Summary collapse
Methods inherited from APIPath
Constructor Details
This class inherits a constructor from TLAW::APIPath
Class Method Details
.describe(definition = nil) ⇒ Util::Description
Detailed namespace documentation.
See APIPath.describe for explanations.
93 94 95 |
# File 'lib/tlaw/namespace.rb', line 93 def describe(definition = nil) super + describe_children end |
.endpoints ⇒ Hash{Symbol => Endpoint}
Lists all current namespace's endpoints as a hash.
52 53 54 |
# File 'lib/tlaw/namespace.rb', line 52 def endpoints children.select { |_k, v| v < Endpoint } end |
.inspect ⇒ Object
63 64 65 66 67 |
# File 'lib/tlaw/namespace.rb', line 63 def inspect "#<#{name || '(unnamed namespace class)'}: " \ "call-sequence: #{symbol}(#{param_set.to_code});" + inspect_docs end |
Instance Method Details
#describe ⇒ Object
141 142 143 144 |
# File 'lib/tlaw/namespace.rb', line 141 def describe self.class .describe("#{symbol}(#{param_set.to_hash_code(@parent_params)})") end |
#inspect ⇒ Object
136 137 138 139 |
# File 'lib/tlaw/namespace.rb', line 136 def inspect "#<#{symbol}(#{param_set.to_hash_code(@parent_params)})" + self.class.inspect_docs end |