Sha256: 804d8a6aa6044bc02ec041df7b1b7bb2beb98d6147f64e8bb8a619047b171984

Contents?: true

Size: 881 Bytes

Versions: 3

Compression:

Stored size: 881 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Extensions #:nodoc:
    module Symbol #:nodoc:
      module Inflections #:nodoc:

        REVERSALS = {
          :asc => :desc,
          :ascending => :descending,
          :desc => :asc,
          :descending => :ascending
        }

        def invert
          REVERSALS[self]
        end

        def singular?
          to_s.singular?
        end

        def plural?
          to_s.plural?
        end

        [ "gt", "lt", "gte", "lte", "ne", "near", "in", "nin", "mod", "all",
          "size", "exists", "within", ["matches","elemMatch"] ].each do |oper|
          m, oper = oper
          oper = m unless oper
          class_eval <<-OPERATORS
            def #{m}
              Criterion::Complex.new(:key => self, :operator => "#{oper}")
            end
          OPERATORS
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
mongoid-2.0.0.beta.7 lib/mongoid/extensions/symbol/inflections.rb
chhean-mongoid-2.0.1.beta1 lib/mongoid/extensions/symbol/inflections.rb
mongoid-2.0.0.beta.5 lib/mongoid/extensions/symbol/inflections.rb