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
# for Rails 3.2.12 | |
# loads fixtures a lot faster | |
require 'active_record/fixtures' | |
class ActiveRecord::Fixtures | |
# based on activerecord-3.2.12/lib/active_record/fixtures.rb l.462 | |
# modified lines are marked CHANGED | |
def self.create_fixtures(fixtures_directory, table_names, class_names = {}) | |
table_names = [table_names].flatten.map { |n| n.to_s } |
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
class MaybeClass < DelegateClass(FalseClass) | |
LIKELIHOOD = 0.4 | |
def initialize | |
super(rand < LIKELIHOOD) | |
end | |
def ==(obj) | |
obj.class == self.class |
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
# coding: utf-8 | |
require 'sequel/adapters/sqlite' | |
# monkey patch to optionally open database in read-only mode | |
class ::Sequel::SQLite::Database | |
# [Copied] from sequel-4.5.0/lib/sequel/adapters/sqlite.rb | |
def connect(server) | |
opts = server_opts(server) |
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 TwoPlusTwoIsFive | |
def self.included(base) | |
base.class_exec do | |
alias_method :plus_without_two_plus_two_is_five, :+ | |
private :plus_without_two_plus_two_is_five | |
alias_method :+, :plus_with_two_plus_two_is_five | |
public :+ | |
end | |
end |
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
require 'sequel/model' | |
module Sequel | |
class << self | |
# abstract model needs to avoid inherited callback | |
# (see https://groups.google.com/forum/#!msg/sequel-talk/OG5ti9JAJIE/p1iqO57cwqwJ) | |
# MyAbstractModel = Sequel.new_abstract_model do | |
# # ... your common stuff ... |
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 |
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 |
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
# monkey patch for https://github.com/willbryant/columns_on_demand/issues/2 | |
require 'active_record' | |
require 'columns_on_demand' | |
module ColumnsOnDemand | |
module BaseMethods | |
# COPIED |
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
# NOTE assumes the relation is very very simple | |
def bulk_update(relation, values, where_columns, set_columns) | |
return if values.empty? | |
connection = relation.connection | |
base_class = relation.base_class | |
if relation.arel.where_sql.present? | |
relation_ids = relation.ids | |
end |
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 UseSingleForwardableWithActiveSupport | |
extend ActiveSupport::Concern | |
included do | |
original_delegate_method = method(:delegate).unbind if self.respond_to?(:delegate) | |
extend SingleForwardable | |
if original_delegate_method.present? | |
# restore the delegate of ActiveSupport that has been overshadowed by SingleForwardable | |
define_singleton_method :delegate, original_delegate_method |
OlderNewer