Sha256: 398faf8400f259ba11d7ad3e86eeef204372350f3078bb2a7aaf770f98589336

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8

module Hexx

  # @api hide
  # The module contains classes that defines helper methods for the service.
  #
  # Basically those methods are private inside the service. In the helper
  # they are public, allowing them to be testable as a part of the gem's API.
  module Helpers

    # @api hide
    # The module declares helper methods for managing service object's params.
    module Parameters
      extend ActiveSupport::Concern

      # @api hide
      # Class helper methods
      module ClassMethods

        def allow_params(*keys)
          @params = keys.flatten.map(&:to_s)
          fail ArgumentError if @params == []
          params.each { |name| Creators::Parameter.add self, name }
        end

        private

        def params
          @params ||= []
        end
      end

      attr_reader :params

      def initialize(params = {})
        @params = params.stringify_keys.slice(*class_params)
      end

      private

      def class_params
        @class_params ||= self.class.send :params
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hexx-7.1.0 lib/hexx/helpers/parameters.rb
hexx-7.0.1 lib/hexx/helpers/parameters.rb
hexx-7.0.0 lib/hexx/helpers/parameters.rb