Module: DataMapper::Aggregates::Query

Defined in:
lib/dm-aggregates/query.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/dm-aggregates/query.rb', line 4

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

Instance Method Details

#assert_valid_fields_with_operator(fields, unique) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dm-aggregates/query.rb', line 12

def assert_valid_fields_with_operator(fields, unique)
  operators, fields = fields.partition { |f| f.kind_of?(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