This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# module FooBar | |
# extend DelegatedModuleFunction | |
# | |
# define_delegated_module_functions do | |
# | |
# def foo_bar | |
# 'Foo' + bar | |
# end | |
# | |
# private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecordRelationExists | |
# DANGER this switches ActiveRecord::Relation#exists from delegation to arel to our implementation that returns a String with a twist. | |
# This achieves the most common usage of #exists before 4.2. Proper fix will be: https://github.com/rails/rails/issues/16959 | |
def exists | |
SqlStringWithNot.new("EXISTS (#{self.to_sql})") | |
end | |
class SqlStringWithNot < String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MongoidEmbeddedObjectModification | |
# Custom field behaves more like an immutable value. | |
# Your changes to the object obtained with getter method will not take an effect unless you assign it back. | |
# https://github.com/mongoid/mongoid/issues/3341 | |
def modify(mongoid_doc, field_name) | |
obj = mongoid_doc.public_send(field_name) | |
yield obj | |
mongoid_doc.public_send("#{field_name}=", obj) | |
end |
NewerOlder