Sha256: 5671d3c67d904fc16e2785fb4f7258d273ba8523c2aa062921f5cb11a361b049

Contents?: true

Size: 907 Bytes

Versions: 2

Compression:

Stored size: 907 Bytes

Contents

module DataMapper
  module Aggregates
    module Query
      def self.included(base)
        base.class_eval <<-RUBY, __FILE__, __LINE__ + 1
          # FIXME: figure out a cleaner approach than AMC
          alias_method :assert_valid_fields_without_operator, :assert_valid_fields
          alias_method :assert_valid_fields, :assert_valid_fields_with_operator
        RUBY
      end

      def assert_valid_fields_with_operator(fields, unique)
        operators, fields = fields.partition { |f| f.is_a?(DataMapper::Query::Operator) }

        operators.each do |operator|
          target = operator.target

          unless target == :all || @properties.include?(target)
            raise ArgumentError, "+options[:fields]+ entry #{target.inspect} does not map to a property in #{model}"
          end
        end

        assert_valid_fields_without_operator(fields, unique)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sbf-dm-aggregates-1.3.0 lib/dm-aggregates/query.rb
sbf-dm-aggregates-1.3.0.beta lib/dm-aggregates/query.rb