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
# ActiveRecord's find_each and find_in_batches ported to Sequel. | |
# Sequel's paged_each is not practical when converting large data due to its use of transaction and offset. | |
# | |
# Usage: | |
# | |
# SequelEachInBatches.find_each(dataset, keys) { |record| ... } | |
# | |
# It can also monkey patch Sequel::Dataset: | |
# | |
# Sequel::Dataset.send(:include, SequelEachInBatches) |
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 SequelBulkUpdate | |
class << self | |
# NOTE assumes the relation is simple | |
# | |
# @param relation [Sequel::Dataset] scope of update | |
# @param values [Array<Hash{Symbol=>_},#to_h>] values of each row required for updating | |
# @param where_columns [Array<Symbol>] columns used to identify the target row | |
# @param set_columns [Array<Symbol>] columns to update |
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 EnumeratorWithPositionAndSize | |
# @yields [original_params, position_and_size] | |
# @yieldparam position_and_size [(Integer, Integer)] 2-element array of position (first being 1) and size; size may be nil (see Enumerator#size) | |
# @example | |
# %w[a b c d e].each.with_position_and_size { |char, (position, size)| puts "#{char} (#{position}/#{size})" } | |
def with_position_and_size | |
return to_enum(__method__) unless block_given? | |
my_size = self.size | |
self.with_index(1) do |original_params, position| |
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 IOStreamingResponseBody | |
def self.render(options = {}, &block) | |
instance = new(options) | |
instance.define_singleton_method :render do |dummy_io| | |
block.call(dummy_io) | |
end | |
instance | |
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 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
require 'active_support' | |
require 'active_support/concern' | |
require 'active_support/core_ext' | |
require 'active_support/json' | |
# String#to_json to escape any string outside BMP | |
module StringToJsonWithEscape4byteUtf8 | |
extend ActiveSupport::Concern | |
included do |
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 Sequel | |
module Plugins | |
module AssociationExists | |
module DatasetMethods | |
def association_exists(association, &block) | |
_association_exists(association, &block) | |
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 Enumerable | |
def self.product(first, *rest) | |
return enum_for(__method__, first, *rest) unless block_given? | |
if rest.empty? | |
first.each do |v0| | |
yield [v0] | |
end | |
else | |
enum_for_rest = product(*rest) |
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 Rubinius | |
config = {} | |
config[:config_file] = "/Users/ippei/src/rubinius-3.33/config.rb" | |
config[:command_line] = ["--prefix=/Users/ippei/.rvm/rubies/rbx-3.33", "--with-opt-dir=/usr/local/opt/openssl:/usr/local/opt/readline:/usr/local/opt/libyaml:/usr/local/opt/gdbm", "--llvm-path=/usr/local/Cellar/llvm/3.6.2"] | |
config[:build_make] = "make" | |
config[:build_rake] = "rake" | |
config[:build_perl] = "perl" | |
config[:llvm_path] = "/usr/local/Cellar/llvm/3.6.2" | |
config[:llvm_system_name] = nil | |
config[:llvm_configure] = "/usr/local/opt/llvm/bin/llvm-config" |