Sha256: 24155b7d73ee2235ff52278defda1658c0560c08149bd07f3f1441bad6d141fa

Contents?: true

Size: 1.46 KB

Versions: 8

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Azeroth
  # @api private
  # @author Darthjee
  #
  # Builder resposible for adding routes methods to the controller
  class RoutesBuilder
    # @param model [Model] resource interface
    # @param builder [Sinclair] methods builder
    # @param options [Option]
    def initialize(model, builder, options)
      @model = model
      @builder = builder
      @options = options
    end

    # Append the routes methods to be built
    #
    # @return [Array<Sinclair::MethodDefinition>]
    def append
      options.actions.each do |route|
        add_method(route, &route_code(route))
      end
    end

    private

    attr_reader :model, :builder, :options
    # @method model
    # @api private
    # @private
    #
    # Resource interface
    #
    # @return [Model]

    # @method builder
    # @api private
    # @private
    #
    # Methods builder
    #
    # @return [Sinclair]

    # @method options
    # @api private
    # @private
    #
    # Buiding options
    #
    # @return [Options]

    delegate :add_method, to: :builder
    # @method add_method
    # @api private
    # @private
    #
    # Appends a method
    #
    # @return [Array<Sinclair::MethodDefinition>]

    def route_code(route)
      model_interface = model
      handler_class = Azeroth::RequestHandler.const_get(
        route.to_s.capitalize
      )

      proc do
        handler_class.new(
          self, model_interface
        ).process
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
azeroth-0.6.5 lib/azeroth/routes_builder.rb
azeroth-0.6.4 lib/azeroth/routes_builder.rb
azeroth-0.6.3 lib/azeroth/routes_builder.rb
azeroth-0.6.2 lib/azeroth/routes_builder.rb
azeroth-0.6.1 lib/azeroth/routes_builder.rb
azeroth-0.6.0 lib/azeroth/routes_builder.rb
azeroth-0.5.0 lib/azeroth/routes_builder.rb
azeroth-0.4.0 lib/azeroth/routes_builder.rb