Sha256: 529edd2efe9c8045d1c455ed9d765a89999df27db908da5f992e63f2b73d7a72

Contents?: true

Size: 939 Bytes

Versions: 2

Compression:

Stored size: 939 Bytes

Contents

module Trailblazer
  class Finder
    module Features
      module Predicate
        PREDICATES = %w[eq not_eq blank not_blank lt lte gt gte].freeze

        def self.included(base)
          base.extend ClassMethods
          base.instance_eval do
            include Predicates
          end
        end

        module ClassMethods
          def predicate_filter(attribute, predicate)
            filter_by "#{attribute}_#{predicate}" do |entity_type, value|
              splitter = Utils::Splitter.new "#{attribute}_#{predicate}", value
              splitter.split_key predicate.to_sym
              send splitter.op, splitter.field, splitter.value, entity_type
            end
          end

          def predicates_for(*attributes)
            attributes.each do |attribute|
              PREDICATES.each { |predicate| predicate_filter(attribute, predicate) }
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trailblazer-finder-0.1.4 lib/trailblazer/finder/features/predicate.rb
trailblazer-finder-0.1.3 lib/trailblazer/finder/features/predicate.rb