module Trailblazer::Endpoint::Controller::DSL::Endpoint

Public Class Methods

extended(extended) click to toggle source
# File lib/trailblazer/endpoint/controller.rb, line 91
def self.extended(extended)
  extended.directive(:endpoints, ->(*) { {} })
end

Public Instance Methods

build_endpoint(name, domain_activity: name, **options) click to toggle source
# File lib/trailblazer/endpoint/controller.rb, line 114
def build_endpoint(name, domain_activity: name, **options)
  build_options = options_for(:generic_options, {}).merge(domain_activity: domain_activity, **options) # DISCUSS: why don't we add this as another directive option/step?

  endpoint = Trailblazer::Endpoint.build(build_options)

  directive :endpoints, ->(*) { {name.to_s => endpoint} }
end
endpoint(name, **options, &block) click to toggle source

Builds and registers an endpoint in a controller class.

# File lib/trailblazer/endpoint/controller.rb, line 96
def endpoint(name, **options, &block)
  options = options.merge(protocol_block: block) if block_given?

  return generic_endpoint_config(**name, **options) if name.is_a?(Hash)
  build_endpoint(name, **options)
end
generic_endpoint_config(**options) click to toggle source

Configures generic {:adapter}, {:protocol}, etc.

# File lib/trailblazer/endpoint/controller.rb, line 104
def generic_endpoint_config(**options)
  self.singleton_class.define_method :generic_options do |ctx,**|
    {
      **options
    }
  end

  directive :generic_options, method(:generic_options) # FIXME: do we need this?
end