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-04-05 16:02:16 +00:00
|
|
|
# module Relations #:nodoc:
|
|
|
|
# module AutoSave
|
|
|
|
# module ClassMethods #:nodoc:
|
|
|
|
# def autosave(metadata)
|
|
|
|
# if metadata.autosave?
|
|
|
|
# set_callback :save, :after do |document|
|
|
|
|
# relation = document.send(metadata.name)
|
|
|
|
#
|
|
|
|
# return true if document.try(:"autosave_for_#{metadata.name}?") == false # FIXME (Didier L.) add more control on the document side
|
|
|
|
#
|
|
|
|
# if relation
|
|
|
|
# (relation.do_or_do_not(:in_memory) || Array.wrap(relation)).each do |doc|
|
|
|
|
# doc.save
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
2012-04-05 16:01:16 +00:00
|
|
|
|
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
|
|
|
|
|
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
|
2012-04-05 16:01:16 +00:00
|
|
|
|
|
|
|
|