Module: Mongory

Defined in:
lib/mongory.rb,
lib/mongory/rails.rb,
lib/mongory/utils.rb,
lib/mongory/mongoid.rb,
lib/mongory/version.rb,
lib/mongory/matchers.rb,
lib/mongory/query_builder.rb,
lib/mongory/query_matcher.rb,
lib/mongory/utils/context.rb,
lib/mongory/query_operator.rb,
lib/mongory/utils/debugger.rb,
lib/mongory/utils/rails_patch.rb,
lib/mongory/matchers/eq_matcher.rb,
lib/mongory/matchers/gt_matcher.rb,
lib/mongory/matchers/in_matcher.rb,
lib/mongory/matchers/lt_matcher.rb,
lib/mongory/matchers/ne_matcher.rb,
lib/mongory/matchers/or_matcher.rb,
lib/mongory/converters/converted.rb,
lib/mongory/matchers/and_matcher.rb,
lib/mongory/matchers/gte_matcher.rb,
lib/mongory/matchers/lte_matcher.rb,
lib/mongory/matchers/nin_matcher.rb,
lib/mongory/matchers/not_matcher.rb,
lib/mongory/matchers/size_matcher.rb,
lib/mongory/matchers/every_matcher.rb,
lib/mongory/matchers/field_matcher.rb,
lib/mongory/matchers/regex_matcher.rb,
lib/mongory/matchers/exists_matcher.rb,
lib/mongory/utils/singleton_builder.rb,
lib/mongory/converters/key_converter.rb,
lib/mongory/matchers/literal_matcher.rb,
lib/mongory/matchers/present_matcher.rb,
lib/mongory/converters/data_converter.rb,
lib/mongory/matchers/abstract_matcher.rb,
lib/mongory/converters/value_converter.rb,
lib/mongory/matchers/elem_match_matcher.rb,
lib/mongory/converters/abstract_converter.rb,
lib/mongory/matchers/array_record_matcher.rb,
lib/mongory/converters/condition_converter.rb,
lib/mongory/matchers/abstract_multi_matcher.rb,
lib/mongory/matchers/hash_condition_matcher.rb,
lib/generators/mongory/install/install_generator.rb,
lib/generators/mongory/matcher/matcher_generator.rb

Overview

Main namespace for Mongory DSL and configuration.

Provides access to core converters, query construction, and optional integrations with frameworks like Rails or Mongoid.

Examples:

Basic usage

Mongory.build_query(records).where(age: { :$gt => 18 })

Enabling DSL snippets

Mongory.enable_symbol_snippets!
Mongory.register(Array)

Defined Under Namespace

Modules: ClassExtention, Converters, Generators, Matchers, MongoidPatch, Utils Classes: Error, QueryBuilder, QueryMatcher, QueryOperator, Railtie, TypeError

Constant Summary collapse

VERSION =
'0.6.1'

Class Method Summary collapse

Class Method Details

.build_query(records) ⇒ QueryBuilder

Builds a new query over the given record set.

Parameters:

  • records (Enumerable)

    any enumerable object (Array, AR::Relation, etc.)

Returns:



82
83
84
# File 'lib/mongory.rb', line 82

def self.build_query(records)
  QueryBuilder.new(records)
end

.condition_converterConverters::ConditionConverter

Returns the condition converter instance.



67
68
69
# File 'lib/mongory.rb', line 67

def self.condition_converter
  @condition_converter ||= Converters::ConditionConverter.instance
end

.configure {|self| ... } ⇒ void

This method returns an undefined value.

Yields Mongory for configuration and freezes key components.

Examples:

Configure converters

Mongory.configure do |mc|
  mc.data_converter.configure do |dc|
    dc.register(MyType) { transform(self) }
  end

  mc.condition_converter.key_converter.configure do |kc|
    kc.register(MyKeyType) { normalize_key(self) }
  end

  mc.condition_converter.value_converter.configure do |vc|
    vc.register(MyValueType) { cast_value(self) }
  end
end

Yield Parameters:



50
51
52
53
54
55
# File 'lib/mongory.rb', line 50

def self.configure
  yield self
  data_converter.freeze
  condition_converter.freeze
  Matchers.freeze
end

.data_converterConverters::DataConverter

Returns the data converter instance.



60
61
62
# File 'lib/mongory.rb', line 60

def self.data_converter
  @data_converter ||= Converters::DataConverter.instance
end

.debuggerUtils::Debugger

Returns the debugger instance.

Returns:



74
75
76
# File 'lib/mongory.rb', line 74

def self.debugger
  @debugger ||= Utils::Debugger.instance
end

.enable_symbol_snippets!void

This method returns an undefined value.

Enables symbol snippets like :age.gte or :name.regex by dynamically defining methods on Symbol for query operators.

Skips operators that already exist to avoid patching Mongoid or other gems.



101
102
103
# File 'lib/mongory.rb', line 101

def self.enable_symbol_snippets!
  Matchers.enable_symbol_snippets!
end

.register(klass) ⇒ void

This method returns an undefined value.

Registers a class to support .mongory query DSL. This injects a #mongory method into the given class.

Parameters:

  • klass (Class)

    the class to register (e.g., Array, ActiveRecord::Relation)



91
92
93
# File 'lib/mongory.rb', line 91

def self.register(klass)
  klass.include(ClassExtention)
end