Sha256: dd9cfbb04a2087c1744e05cb5b612bc9d814cd83be6ca2790d71b524ef0cec8d

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

# encoding: utf-8

module Okei

  # Controllers for public JSON API routes.
  module Api

    # API v.1 controllers.
    module V1

      # Controller for getting units
      class UnitsController < ResponderController

        # Returns either all units of measure or units of given measure.
        def index
          run_case GetUnits, with: :measure
        end

        # Finds a unit of measure by uuid.
        def show
          run_case GetUnit, with: :uuid
        end

        # Finds a unit of measure by text
        def search
          run_case FindUnit, with: :text
        end

        private

        # Initializes a corresponding use case (service) with allowed params,
        # subscribes for its results and then runs a use case.
        #
        # After running, the use case will call a method defined in the
        # `ResponderController` base class.
        #
        def run_case(klass, with:)
          use_case = klass.new params.permit(*with)
          use_case.subscribe self, prefix: :on
          use_case.run
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
okei-1.0.2 app/controllers/okei/api/v1/units_controller.rb
okei-1.0.1 app/controllers/okei/api/v1/units_controller.rb