Module: Mongoid::Extensions::Symbol::Inflections

Included in:
Symbol
Defined in:
lib/mongoid/extensions/symbol/inflections.rb

Overview

This module contains convenience methods for symbol inflection and conversion.

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#invertString

Get the inverted sorting option.

Examples:

Get the inverted option.

:asc.invert

Returns:

  • (String)

    The string inverted.



23
24
25
# File 'lib/mongoid/extensions/symbol/inflections.rb', line 23

def invert
  REVERSALS[self]
end

#operCriterion::Complex

Define all the necessary methods on symbol to support Mongoid’s complex criterion.

Examples:

A greater than criterion.

:field.gt => 5

Returns:

Since:

  • 1.0.0



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mongoid/extensions/symbol/inflections.rb', line 36

[
  "all",
  "asc",
  "ascending",
  "desc",
  "descending",
  "exists",
  "gt",
  "gte",
  "in",
  "lt",
  "lte",
  "mod",
  "ne",
  "near",
  "nin",
  "size",
  "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