Skip to content

Instantly share code, notes, and snippets.

@kml
kml / rails_asset_precomiled_patch.rb
Created December 13, 2016 22:39
Don't check if asset is precompiled on development.
# config/initializers/assets.rb
if Rails.env.development?
Rails.application.config.assets.precompile = []
# Don't check if asset is precompiled on development,
# because building "precompiled_assets" list is taking quite long time.
#
# Default: https://github.com/rails/sprockets-rails/blob/89ba006950caba495954fbb1626919bfe4ee7838/lib/sprockets/railtie.rb#L31
# "Called from asset helpers to alert you if you reference an asset URL that
@kml
kml / rest-client-log-response-patch.rb
Created December 13, 2016 22:41
Log responses from RestClient
module RestClientLogResponsePatch
def process_result(res, &block)
response = super
log_response_with_body(response) unless res.is_a?(Net::HTTPRedirection)
response
rescue RestClient::Exception => exception
log_response_with_body(exception.response)
raise exception
end
require "active_support/inflector"
# http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-titleize
module LocaleDependentTitleize
def titleize(word)
return humanize(underscore(word)) if I18n.locale == :pl
super
end
end
# encoding: utf-8
require "bson/object_id"
BSON::ObjectId.class_eval do
alias to_json to_s
def as_json(*args)
to_s
end
require "mongo/collection/view"
# Add default "comment" for every request to MongoDB.
# https://github.com/mongodb/mongo-ruby-driver/blob/master/lib/mongo/collection/view.rb#L132
Mongo::Collection::View.class_eval do
alias :mongo_collection_view_initialize :initialize
def initialize(collection, filter = {}, options = {})
filter["$comment"] ||= default_comment
mongo_collection_view_initialize(collection, filter, options)
# encoding: utf-8
=begin
Mongoid::Errors::ReadonlyDocument:
message:
Attempted to persist the readonly document 'Offer'.
summary:
Documents loaded from the database using #only cannot be persisted.
resolution:
Don't attempt to persist documents that are flagged as readonly.
# encoding: utf-8
require "active_record/log_subscriber"
require "logger"
module ActiveRecord
class LogSubscriber
NULL_LOGGER = ::Logger.new(nil)
def logger
# encoding: utf-8
module ImplicitConnectionForbidder
def self.forbid_implicit_connections
yield
end
end
# http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html#method-i-with_connection
# http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html#method-i-release_connection
# encoding: utf-8
# https://github.com/mongodb/mongoid/blob/4789bfffd3cbfa065eb7be7f34fbac122278a0ae/lib/mongoid/criteria.rb#L324
require "mongoid/criteria"
module Mongoid
class Criteria
OnlyWhenDefaultScopeError = Class.new(StandardError)
# encoding: utf-8
# ISSUE: https://github.com/jruby/jruby/issues/405
# In JRuby, FileUtils.remove_entry_secure(dir) crashes when a dir is under
# a world-writable directory because it tries to open directory.
# Opening directory is not allowed in Java.
# -- https://github.com/jruby/jruby/blob/1.7.0/lib/ruby/1.9/tmpdir.rb#L25-L28
#[1] pry(main)> Dir.tmpdir