Sha256: 4be7644a49f921d62b4ec77b570f9707aba2f4f2af45f25293efacfa4efcaacb

Contents?: true

Size: 847 Bytes

Versions: 2

Compression:

Stored size: 847 Bytes

Contents

module Querifier
  module Queries
    module Base
      def initialize(params)
        @params = params
        check_params!
      end

      def collection
        @collection ||= self.class.default_collection
      end

      def params
        @params.fetch(Config.filter_param, {})
      end

      def self.included(klass)
        klass.extend(ClassMethods)
      end

      module ClassMethods
        def default_collection
          @@default_collection ||= Object.const_get(self.name.split('::').last.split('Query').first).all
        end
      end

      private

      def check_params!
        return if @params.respond_to?(:keys) && @params.respond_to?(:has_key?)
        raise ArgumentError, "The params should extend of a hash, instead, they are a #{@params.class}" # rubocop:disable Metrics/LineLength
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
querifier-0.2.3 lib/querifier/queries/base.rb
querifier-0.2.2 lib/querifier/queries/base.rb