2011-03-08 15:05:07 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2010-06-03 20:20:53 +00:00
|
|
|
require 'mongoid'
|
|
|
|
|
2012-01-10 01:24:34 +00:00
|
|
|
module Mongoid#:nodoc:
|
2012-02-16 23:51:33 +00:00
|
|
|
|
2012-01-10 01:24:34 +00:00
|
|
|
module Document #:nodoc:
|
2011-12-22 01:59:30 +00:00
|
|
|
def as_json(options = {})
|
2011-12-21 14:24:39 +00:00
|
|
|
attrs = super(options)
|
|
|
|
attrs["id"] = attrs["_id"]
|
|
|
|
attrs
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-10 01:24:34 +00:00
|
|
|
module Fields #:nodoc:
|
|
|
|
module Internal #:nodoc:
|
|
|
|
class RawArray < Mongoid::Fields::Internal::Array
|
|
|
|
def resizable?; false; end
|
|
|
|
end
|
|
|
|
end
|
2011-03-08 15:05:07 +00:00
|
|
|
|
2012-01-10 01:24:34 +00:00
|
|
|
class RawArray < ::Array; end
|
|
|
|
end
|
2011-04-28 15:04:18 +00:00
|
|
|
|
2012-02-16 23:51:33 +00:00
|
|
|
class Criteria
|
|
|
|
def to_liquid
|
|
|
|
Locomotive::Liquid::Drops::ProxyCollection.new(self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-23 22:03:21 +00:00
|
|
|
module Criterion
|
|
|
|
class Selector < Hash
|
|
|
|
# for some reason, the store method behaves differently than the []= one, causing regression bugs (query not localized)
|
|
|
|
alias :store :[]=
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-28 15:04:18 +00:00
|
|
|
# without callback feature
|
2012-01-10 01:24:34 +00:00
|
|
|
module Callbacks #:nodoc:
|
|
|
|
module ClassMethods #:nodoc:
|
2011-04-28 15:04:18 +00:00
|
|
|
def without_callback(*args, &block)
|
|
|
|
skip_callback(*args)
|
|
|
|
yield
|
|
|
|
set_callback(*args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-02-16 21:07:00 +00:00
|
|
|
|
|
|
|
# make the validators work with localized field
|
|
|
|
module Validations #:nodoc:
|
|
|
|
def read_attribute_for_validation_with_localization(attr)
|
|
|
|
if fields[attr.to_s] && fields[attr.to_s].localized?
|
|
|
|
send(attr.to_sym)
|
|
|
|
else
|
|
|
|
read_attribute_for_validation_without_localization(attr)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
alias_method_chain :read_attribute_for_validation, :localization
|
|
|
|
|
|
|
|
class PresenceValidator < ActiveModel::EachValidator
|
|
|
|
def validate_each(document, attribute, value)
|
|
|
|
document.errors.add(attribute, :blank, options) if value.blank?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-02-16 23:51:33 +00:00
|
|
|
|
2012-02-16 21:07:00 +00:00
|
|
|
end
|