Module: Trailblazer::Endpoint::Controller::DSL::Endpoint

Defined in:
lib/trailblazer/endpoint/controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(extended) ⇒ Object



91
92
93
# File 'lib/trailblazer/endpoint/controller.rb', line 91

def self.extended(extended)
  extended.directive(:endpoints, ->(*) { {} })
end

Instance Method Details

#build_endpoint(name, domain_activity: name, **options) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/trailblazer/endpoint/controller.rb', line 115

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 = nil, **options, &block) ⇒ Object

Builds and registers an endpoint in a controller class.



96
97
98
99
100
101
102
# File 'lib/trailblazer/endpoint/controller.rb', line 96

def endpoint(name=nil, **options, &block)
  options = options.merge(protocol_block: block) if block_given?

  return generic_endpoint_config(**options) if name.nil?

  build_endpoint(name, **options)
end

#generic_endpoint_config(**options) ⇒ Object

Configures generic :adapter, :protocol, etc.



105
106
107
108
109
110
111
112
113
# File 'lib/trailblazer/endpoint/controller.rb', line 105

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