class TLAW::DSL::NamespaceWrapper
@private
Constants
- WRAPPERS
Public Instance Methods
endpoint(name, path = nil, **opts, &block)
click to toggle source
# File lib/tlaw/dsl.rb, line 464 def endpoint(name, path = nil, **opts, &block) update_existing(Endpoint, name, path, **opts, &block) || add_child(Endpoint, name, path: path || "/#{name}", **opts, &block) end
namespace(name, path = nil, &block)
click to toggle source
# File lib/tlaw/dsl.rb, line 469 def namespace(name, path = nil, &block) update_existing(Namespace, name, path, &block) || add_child(Namespace, name, path: path || "/#{name}", &block) end
Private Instance Methods
add_child(child_class, name, **opts, &block)
click to toggle source
# File lib/tlaw/dsl.rb, line 492 def add_child(child_class, name, **opts, &block) @object.add_child( child_class.inherit(@object, symbol: name, **opts) .tap { |c| c.setup_parents(@object) } .tap(&:params_from_path!) .tap { |c| WRAPPERS[child_class].new(c).define(&block) if block } ) end
update_existing(child_class, name, path, **opts, &block)
click to toggle source
# File lib/tlaw/dsl.rb, line 481 def update_existing(child_class, name, path, **opts, &block) existing = @object.children[name] or return nil existing < child_class or fail ArgumentError, "#{name} is already defined as #{child_class == Endpoint ? 'namespace' : 'endpoint'}, you can't redefine it as #{child_class}" !path && opts.empty? or fail ArgumentError, "#{child_class} is already defined, you can't change its path or options" WRAPPERS[child_class].new(existing).define(&block) if block end