Sha256: ebdfe3361020964aafdcaaba19f84bbceb819bfd96aeeb596a168f92d240044a

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 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 < Responder

        # 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
        # `Responder` parent 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.0 app/controllers/okei/api/v1/units_controller.rb
okei-1.0.0.pre.rc app/controllers/okei/api/v1/units_controller.rb