source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
spec/lib/sprig/seed/entry_spec.rb
Ruby
mit
208
master
920
require 'spec_helper' RSpec.describe Sprig::Seed::Entry do describe ".success_log_text" do context "on a new record" do it "indicates the record was 'saved'" do subject = described_class.new(Post, { title: "Hello World!", content: "Stuff", sprig_id: 1 }, {}) subject.save_record exp...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
spec/lib/sprig/seed/record_spec.rb
Ruby
mit
208
master
717
require 'spec_helper' RSpec.describe Sprig::Seed::Record do describe ".existing?" do let!(:existing) do Post.create( :title => "Existing title", :content => "Existing content", :published => false ) end it "returns true if the record has already been saved to...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
spec/lib/sprig/parser/base_spec.rb
Ruby
mit
208
master
253
require 'spec_helper' RSpec.describe Sprig::Parser::Base do describe "#parse" do it "enforces implementation in a subclass" do expect { described_class.new('data').parse }.to raise_error(NotImplementedError) end end end
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
spec/lib/generators/sprig/install_generator_spec.rb
Ruby
mit
208
master
1,374
require 'spec_helper' require 'generators/sprig/install_generator' RSpec.describe Sprig::Generators::InstallGenerator, type: :generator do destination File.expand_path("../../tmp", __FILE__) before do stub_rails_root prepare_destination run_generator end it "creates empty db/seeds directory" do ...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig.rb
Ruby
mit
208
master
1,681
module Sprig autoload :Configuration, 'sprig/configuration' autoload :Planter, 'sprig/planter' autoload :TsortableHash, 'sprig/tsortable_hash' autoload :Dependency, 'sprig/dependency' autoload :DependencyCollection, 'sprig/dependency_collection' autoload :DependencySorte...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/generators/sprig/install_generator.rb
Ruby
mit
208
master
787
require 'rails/generators/base' module Sprig module Generators class InstallGenerator < Rails::Generators::Base argument :arg_envs, :type => :array, :optional => true desc "Install Sprig seed directories" def create_enviroment_directories empty_directory 'db/seeds' create_shar...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/planter.rb
Ruby
mit
208
master
633
module Sprig class Planter def initialize(seeds) @seeds = seeds.to_a end def sprig dependency_sorted_seeds.each do |seed| plant(seed) end notifier.finished end private attr_reader :seeds def dependency_sorted_seeds DependencySorter.new(seeds).sort...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/source.rb
Ruby
mit
208
master
3,149
module Sprig class Source def initialize(table_name, args = {}) @table_name = table_name @args = args end def records data[:records] || [] end def options data[:options] || {} end private attr_reader :table_name, :args def data @data ||= be...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/sprig_record_store.rb
Ruby
mit
208
master
664
require 'singleton' module Sprig class SprigRecordStore include Singleton class RecordNotFoundError < StandardError;end def save(record, sprig_id) records_of_klass(record.class)[sprig_id.to_s] = record end def get(klass, sprig_id) records_of_klass(klass)[sprig_id.to_s] || record_no...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/directive.rb
Ruby
mit
208
master
845
module Sprig class Directive attr_reader :attributes def initialize(args) @attributes = begin case when args.is_a?(Hash) args when args.is_a?(Class) && args < Sprig.adapter_model_class { :class => args } else raise ArgumentError, argument_er...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/dependency.rb
Ruby
mit
208
master
842
module Sprig class Dependency attr_reader :id def self.for(klass, sprig_id) klass = to_klass(klass) sprig_id = sprig_id.to_s collection.get(klass, sprig_id) || new(klass, sprig_id) end def initialize(klass, sprig_id) @klass = klass @sprig_id = sprig_id @id = Secu...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/helpers.rb
Ruby
mit
208
master
840
module Sprig module Helpers def seed_directory Sprig.configuration.directory end def sprig(directive_definitions) Sprig.shared_seeding = false plant_records(directive_definitions) end def sprig_shared(directive_definitions) Sprig.shared_seeding = true plant_records(...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/logging.rb
Ruby
mit
208
master
648
module Sprig module Logging LOG_LEVELS = { debug: :blue, info: :green, warn: :orange, error: :red } LOG_COLORS = { blue: 34, green: 32, orange: 33, red: 31 } LOG_LEVELS.each do |level, color| define_method("log_#{level}") do |message|...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/dependency_sorter.rb
Ruby
mit
208
master
1,818
module Sprig class DependencySorter class CircularDependencyError < StandardError; end attr_reader :items def initialize(items) @items = items.to_a end def sorted_items sorted_tags.map do |tag| id_dictionary[tag] end end private def id_dictionary @i...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/configuration.rb
Ruby
mit
208
master
648
module Sprig class Configuration attr_writer :directory, :shared_directory, :logger def directory Rails.root.join(@directory || default_directory, seeds_directory) end def logger @logger ||= Logger.new($stdout) end private def default_directory 'db/seeds' end ...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/seed.rb
Ruby
mit
208
master
334
module Sprig module Seed autoload :Attribute, 'sprig/seed/attribute' autoload :AttributeCollection, 'sprig/seed/attribute_collection' autoload :Entry, 'sprig/seed/entry' autoload :Factory, 'sprig/seed/factory' autoload :Record, 'sprig/seed/reco...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/parser.rb
Ruby
mit
208
master
341
module Sprig module Parser autoload :Base, 'sprig/parser/base' autoload :Csv, 'sprig/parser/csv' autoload :Json, 'sprig/parser/json' autoload :Yml, 'sprig/parser/yml' autoload :GoogleSpreadsheetJson, 'sprig/parser/google_spreads...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/process_notifier.rb
Ruby
mit
208
master
1,163
require 'active_support/inflector' module Sprig class ProcessNotifier include Logging def initialize @success_count = 0 @error_count = 0 @errors = [] end def in_progress(seed) log_debug seed.in_progress_text end def success(seed) log_info seed.success_log_text...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/directive_list.rb
Ruby
mit
208
master
563
module Sprig class DirectiveList def initialize(definitions) @definitions = Array(definitions) end def add_seeds_to_hopper(hopper) seed_factories.each do |factory| factory.add_seeds_to_hopper(hopper) end end private attr_reader :definitions def directives ...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/dependency_collection.rb
Ruby
mit
208
master
357
module Sprig class DependencyCollection def initialize @records = {} end def get(klass, id) records_for_klass(klass)[id] end def set(klass, id, value) records_for_klass(klass)[id] = value end private attr_reader :records def records_for_klass(klass) rec...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/parser/google_spreadsheet_json.rb
Ruby
mit
208
master
643
module Sprig module Parser class GoogleSpreadsheetJson < Base def parse { :records => records } end private def records @records ||= raw_records.map { |record| build_record(record) } end def build_record(record) hash = {} record.keys.each do...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/parser/base.rb
Ruby
mit
208
master
251
module Sprig module Parser class Base attr_reader :data_io def initialize(data_io) @data_io = data_io end def parse raise NotImplementedError, 'Parsers must implement #parse' end end end end
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/parser/csv.rb
Ruby
mit
208
master
355
require 'csv' module Sprig module Parser class Csv < Base def parse { :records => records } end private def records [].tap do |records| CSV.foreach(data_io, headers: :first_row, skip_blanks: true) do |row| records << row.to_hash end ...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/seed/record.rb
Ruby
mit
208
master
865
module Sprig module Seed class Record attr_reader :orm_record delegate :errors, :to => :orm_record def self.new_or_existing(klass, attributes, find_params) orm_record = klass.where(find_params).first new(klass, attributes, orm_record) end def initialize(klass, attr...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/seed/attribute_collection.rb
Ruby
mit
208
master
728
module Sprig module Seed class AttributeCollection include Enumerable delegate :each, :to => :attributes def initialize(attrs_hash) @attrs_hash = attrs_hash.to_hash end def find_by_name(name) attributes.detect {|attribute| attribute.name == name.to_s } || attribute...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/seed/entry.rb
Ruby
mit
208
master
2,200
module Sprig module Seed class Entry def initialize(klass, attrs, options) self.klass = klass attrs = attrs.to_hash.with_indifferent_access self.sprig_id = attrs.delete(:sprig_id) || SecureRandom.uuid @attributes = AttributeCollection.new(attrs) @options = options ...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/seed/factory.rb
Ruby
mit
208
master
1,450
module Sprig module Seed class Factory def self.new_from_directive(directive) raise ArgumentError, 'Must provide a Directive' unless directive.is_a? Directive new( directive.klass, directive.datasource, directive.options ) end def initializ...
github
vigetlabs/sprig
https://github.com/vigetlabs/sprig
lib/sprig/seed/attribute.rb
Ruby
mit
208
master
2,583
module Sprig module Seed class Attribute attr_reader :name, :raw_value, :value def initialize(name, raw_value) @name = name.to_s @raw_value = raw_value end def dependencies @dependencies ||= find_dependencies_within(raw_value).uniq end def value ...
github
mojombo/bert
https://github.com/mojombo/bert
Rakefile
Ruby
mit
208
master
2,382
require 'rubygems' require 'rake' begin require 'jeweler' Jeweler::Tasks.new do |gem| gem.name = "bert" gem.summary = %Q{BERT Serializiation for Ruby} gem.description = %Q{BERT Serializiation for Ruby} gem.email = "tom@mojombo.com" gem.homepage = "http://github.com/mojombo/bert" gem.authors...
github
mojombo/bert
https://github.com/mojombo/bert
bert.gemspec
Ruby
mit
208
master
2,016
# Generated by jeweler # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = %q{bert} s.version = "1.1.6" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_ruby...
github
mojombo/bert
https://github.com/mojombo/bert
lib/bert.rb
Ruby
mit
208
master
439
require 'stringio' $:.unshift File.join(File.dirname(__FILE__), *%w[.. ext]) require 'bert/bert' require 'bert/types' begin # try to load the C extension require 'bert/c/decode' rescue LoadError # fall back on the pure ruby version require 'bert/decode' end require 'bert/encode' require 'bert/encoder' requ...
github
mojombo/bert
https://github.com/mojombo/bert
lib/bert/encoder.rb
Ruby
mit
208
master
1,292
module BERT class Encoder # Encode a Ruby object into a BERT. # +ruby+ is the Ruby object # # Returns a BERT def self.encode(ruby) complex_ruby = convert(ruby) Encode.encode(complex_ruby) end # Convert complex Ruby form in simple Ruby form. # +item+ is the Ruby object ...
github
mojombo/bert
https://github.com/mojombo/bert
lib/bert/bert.rb
Ruby
mit
208
master
316
module BERT def self.encode(ruby) Encoder.encode(ruby) end def self.decode(bert) Decoder.decode(bert) end def self.ebin(str) bytes = [] str.each_byte { |b| bytes << b.to_s } "<<" + bytes.join(',') + ">>" end class Tuple < Array def inspect "t#{super}" end end end
github
mojombo/bert
https://github.com/mojombo/bert
lib/bert/decoder.rb
Ruby
mit
208
master
205
module BERT class Decoder # Decode a BERT into a Ruby object. # +bert+ is the BERT String # # Returns a Ruby object def self.decode(bert) Decode.decode(bert) end end end
github
mojombo/bert
https://github.com/mojombo/bert
lib/bert/types.rb
Ruby
mit
208
master
348
module BERT module Types SMALL_INT = 97 INT = 98 SMALL_BIGNUM = 110 LARGE_BIGNUM = 111 FLOAT = 99 ATOM = 100 SMALL_TUPLE = 104 LARGE_TUPLE = 105 NIL = 106 STRING = 107 LIST = 108 BIN = 109 FUN = 117 NEW_FUN = 112 MAGIC = 131 MAX_INT = (1 << 27) -1 MI...
github
mojombo/bert
https://github.com/mojombo/bert
lib/bert/decode.rb
Ruby
mit
208
master
5,885
module BERT class Decode attr_accessor :in include Types def self.impl 'Ruby' end def self.decode(string) io = StringIO.new(string) io.set_encoding('binary') if io.respond_to?(:set_encoding) new(io).read_any end def initialize(ins) @in = ins @peeked =...
github
mojombo/bert
https://github.com/mojombo/bert
lib/bert/encode.rb
Ruby
mit
208
master
2,776
module BERT class Encode include Types attr_accessor :out def initialize(out) self.out = out end def self.encode(data) io = StringIO.new io.set_encoding('binary') if io.respond_to?(:set_encoding) self.new(io).write_any(data) io.string end def write_any obj...
github
mojombo/bert
https://github.com/mojombo/bert
test/encoder_test.rb
Ruby
mit
208
master
3,216
# encoding: utf-8 require 'test_helper' class EncoderTest < Test::Unit::TestCase context "BERT Encoder complex type converter" do should "convert nil" do assert_equal [:bert, :nil], BERT::Encoder.convert(nil) end should "convert nested nil" do before = [nil, [nil]] after = [[:bert, :n...
github
mojombo/bert
https://github.com/mojombo/bert
test/decoder_test.rb
Ruby
mit
208
master
3,472
require 'test_helper' class DecoderTest < Test::Unit::TestCase BERT_NIL = [131,104,2,100,0,4,98,101,114,116,100,0,3,110,105,108].pack('c*') BERT_TRUE = [131,104,2,100,0,4,98,101,114,116,100,0,4,116,114,117,101].pack('c*') BERT_FALSE = [131,104,2,100,0,4,98,101,114,116,100,0,5,102,97,108,115,101].pack('c*') co...
github
mojombo/bert
https://github.com/mojombo/bert
test/bert_test.rb
Ruby
mit
208
master
2,495
require 'test_helper' class BertTest < Test::Unit::TestCase context "BERT" do setup do time = Time.at(1254976067) @ruby = t[:user, {:name => 'TPW'}, [/cat/i, 9.9], time, nil, true, false, :true, :false] @bert = "\203h\td\000\004userh\003d\000\004bertd\000\004dictl\000\000\000\001h\002d\000\004n...
github
mojombo/bert
https://github.com/mojombo/bert
test/test_helper.rb
Ruby
mit
208
master
271
require 'rubygems' require 'test/unit' require 'shoulda' $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'ext', 'bert', 'c')) load 'bert.rb' puts "Using #{BERT::Decode.impl} implementation."
github
mojombo/bert
https://github.com/mojombo/bert
bench/decode_bench.rb
Ruby
mit
208
master
3,374
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'rubygems' require 'json' require 'yajl' require 'benchmark' ITER = 1_000 def setup tiny = t[:ok, :awesome] small = t[:ok, :answers, [42] * 42] large = ["abc" * 1000] * 100 complex = [42, {:foo => 'bac' * 100}, t[(1..100).to_a]] * 10 ...
github
mojombo/bert
https://github.com/mojombo/bert
bench/bench.rb
Ruby
mit
208
master
1,628
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'rubygems' require 'bert' require 'json' require 'yajl' require 'benchmark' ITER = 1_000 tiny = t[:ok, :awesome] small = t[:ok, :answers, [42] * 42] large = ["abc" * 1000] * 100 complex = [42, {:foo => 'bac' * 100}, t[(1..100).to_a]] * 10 Be...
github
mojombo/bert
https://github.com/mojombo/bert
bench/encode_bench.rb
Ruby
mit
208
master
1,446
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'rubygems' require 'bert' require 'json' require 'yajl' require 'benchmark' ITER = 1_000 tiny = t[:ok, :awesome] small = t[:ok, :answers, [42] * 42] large = ["abc" * 1000] * 100 complex = [42, {:foo => 'bac' * 100}, t[(1..100).to_a]] * 10 Be...
github
mojombo/bert
https://github.com/mojombo/bert
ext/bert/c/extconf.rb
Ruby
mit
208
master
260
# Loads mkmf which is used to make makefiles for Ruby extensions require 'mkmf' # warnings save lives $CFLAGS << " -Wall " # Give it a name extension_name = 'decode' # The destination dir_config(extension_name) # Do the work create_makefile(extension_name)
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
activerecord-turntable.gemspec
Ruby
mit
208
master
2,634
$LOAD_PATH.push File.expand_path("../lib", __FILE__) require "active_record/turntable/version" Gem::Specification.new do |spec| spec.name = "activerecord-turntable" spec.version = ActiveRecord::Turntable::VERSION spec.authors = %w[gussan sue445] spec.homepage = "https://github.com/drecom/activerecord-tur...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
Rakefile
Ruby
mit
208
master
6,319
require "bundler/gem_tasks" require "rubygems" require "rspec/core" require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) do |spec| spec.pattern = FileList["spec/**/*_spec.rb"] end require "active_record" require "active_record/turntable/active_record_ext/database_tasks" namespace :turntable do namespa...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
Guardfile
Ruby
mit
208
master
426
# A sample Guardfile # More info at https://github.com/guard/guard#readme guard "rspec", cmd: "bundle exec rspec", all_after_pass: true, all_on_start: true do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch("spec/spec_helper.rb") { "spec" } end ...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/generators/templates/turntable.rb
Ruby
mit
208
master
1,462
cluster :user_cluster do algorithm :range_bsearch sequencer :user_seq, :mysql, connection: :user_seq shard 0...20_000, to: :user_shard_1 shard 20_000...40_000, to: :user_shard_2 shard 40_000...60_000, to: :user_shard_1 shard 60_000...80_000, to: :user_shard_2 shard 80_000...10_000_0...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/generators/active_record/turntable/install_generator.rb
Ruby
mit
208
master
378
module ActiveRecord::Turntable module Generators class InstallGenerator < Rails::Generators::Base source_root File.expand_path("../../../templates", __FILE__) desc "Creates turntable configuration file (config/turntable.yml)" class_option :orm def copy_locale copy_file "turntable...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable.rb
Ruby
mit
208
master
1,346
# #= ActiveRecord::Turntable # # ActiveRecord Sharding Plugin # require "active_record/turntable/version" require "active_record" require "active_record/fixtures" require "active_support/concern" require "active_record/turntable/error" require "active_record/turntable/util" require "logger" require "singleton" module ...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/util.rb
Ruby
mit
208
master
1,234
module ActiveRecord::Turntable module Util def ar_version_equals_or_later?(version) ar_version >= Gem::Version.new(version) end def ar_version_earlier_than?(version) ar_version < Gem::Version.new(version) end def ar_version ActiveRecord.gem_version.release end def ar_v...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/error.rb
Ruby
mit
208
master
347
module ActiveRecord::Turntable class TurntableError < StandardError; end class SequenceNotFoundError < TurntableError; end class CannotSpecifyShardError < TurntableError; end class DefaultShardNotConnected < TurntableError; end class UnknownOperatorError < TurntableError; end class InvalidConfigurationError...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/cluster.rb
Ruby
mit
208
master
2,421
require "active_support/core_ext/hash/indifferent_access" require "concurrent/atomic/thread_local_var" module ActiveRecord::Turntable class Cluster DEFAULT_CONFIG = { "shards" => [], "algorithm" => "range", }.with_indifferent_access attr_accessor :algorithm, :shard_registry, :sequencer_regis...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/slave_registry.rb
Ruby
mit
208
master
426
module ActiveRecord::Turntable class SlaveRegistry extend ActiveSupport::PerThreadRegistry def initialize @registry = Hash.new { |h, k| h[k] = {} } end def slave_for(shard) @registry[shard][:current_slave] end def set_slave_for(shard, target_slave) @registry[shard][:curren...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/configuration_methods.rb
Ruby
mit
208
master
1,100
module ActiveRecord::Turntable module ConfigurationMethods DEFAULT_PATH = File.dirname(File.dirname(__FILE__)) def turntable_configuration_file @turntable_configuration_file ||= File.join(turntable_app_root_path, "config/turntable.yml") end alias_method :turntable_config_file, :turntable_config...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/shard.rb
Ruby
mit
208
master
1,701
module ActiveRecord::Turntable class Shard module Connections; end def self.connection_classes Connections.constants.map { |name| Connections.const_get(name) } end attr_accessor :cluster, :name, :slaves def initialize(cluster, name = defined?(Rails) ? Rails.env : "development", slaves = []...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/sql_tree_patch.rb
Ruby
mit
208
master
12,981
# rubocop:disable Style/CaseEquality require "sql_tree" require "active_support/core_ext/kernel/reporting" module SQLTree class << self attr_accessor :identifier_quote_field_char end self.identifier_quote_field_char = "`" end class SQLTree::Token extended_keywords = %w(BINARY LIMIT OFFSET INDEX KEY USE FO...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/deprecation.rb
Ruby
mit
208
master
214
module ActiveRecord::Turntable class Deprecation < ActiveSupport::Deprecation def initialize(deprecation_horizon = "4.1", gem_name = "activerecord-turntable") super end end end
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/connection_proxy.rb
Ruby
mit
208
master
7,634
require "active_record/turntable/connection_proxy/mixable" module ActiveRecord::Turntable class ConnectionProxy include Mixable # for expiring query cache CLEAR_CACHE_METHODS = [:update, :insert, :delete, :exec_insert, :exec_update, :exec_delete, :insert_many].freeze attr_reader :klass, :default_sh...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/railtie.rb
Ruby
mit
208
master
1,419
module ActiveRecord::Turntable class Railtie < Rails::Railtie rake_tasks do require "active_record/turntable/active_record_ext/database_tasks" load "active_record/turntable/railties/databases.rake" end # rails loading hook ActiveSupport.on_load(:before_initialize) do ActiveSupport.o...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/pool_proxy.rb
Ruby
mit
208
master
1,991
module ActiveRecord::Turntable class PoolProxy def initialize(proxy) @proxy = proxy end attr_reader :proxy alias_method :connection, :proxy def with_connection yield proxy end delegate :connected?, :checkout_timeout, :automatic_reconnect, :automatic_reconnect=, :checkout_tim...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/seq_shard.rb
Ruby
mit
208
master
679
module ActiveRecord::Turntable class SeqShard < Shard def initialize(name = defined?(Rails) ? Rails.env : "development") super(nil, name) end def support_slave? false end private def connection_class_instance if Connections.const_defined?(name.classify) klass...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/configuration.rb
Ruby
mit
208
master
1,155
module ActiveRecord::Turntable class Configuration extend ActiveSupport::Autoload autoload :DSL autoload :Loader attr_reader :cluster_registry, :sequencer_registry attr_accessor :raise_on_not_specified_shard_query, :raise_on_not_specified_shard_update alias_method :configure...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/migration.rb
Ruby
mit
208
master
5,278
module ActiveRecord::Turntable::Migration extend ActiveSupport::Concern included do extend ShardDefinition prepend OverrideMethods class_attribute :target_shards, :current_shard ::ActiveRecord::ConnectionAdapters::AbstractAdapter.include(SchemaStatementsExt) ::ActiveRecord::Migration::CommandRe...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/shard_registry.rb
Ruby
mit
208
master
855
module ActiveRecord::Turntable class ShardRegistry ShardMap = Struct.new(:range, :shard) do delegate :connection, :connection_pool, :name, to: :shard end attr_reader :cluster, :shard_maps def initialize(cluster) @cluster = cluster @shards_names_hash = {}.with_indifferent_access ...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/default_shard.rb
Ruby
mit
208
master
953
module ActiveRecord::Turntable class DefaultShard < Shard def initialize(klass) (klass and original_connection_pool(klass)) or raise DefaultShardNotConnected, "connection_pool is nil" @klass = klass @name = "master" end def connection_pool if ActiveRecord::Base == @klass ...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/sharding_condition.rb
Ruby
mit
208
master
686
module ActiveRecord::Turntable module ShardingCondition private def foreign_shard_key reflection.options[:foreign_shard_key] || foreign_target_model.turntable_shard_key end def foreign_target_model return model if respond_to?(:model) return @model if instance_variable_d...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/active_record_ext.rb
Ruby
mit
208
master
1,740
module ActiveRecord::Turntable module ActiveRecordExt extend ActiveSupport::Concern extend ActiveSupport::Autoload eager_autoload do autoload :AbstractAdapter autoload :CleverLoad autoload :ConnectionHandlerExtension autoload :LogSubscriber autoload :Persistence autolo...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/algorithm.rb
Ruby
mit
208
master
507
module ActiveRecord::Turntable module Algorithm extend ActiveSupport::Autoload eager_autoload do autoload :Base autoload :RangeAlgorithm autoload :RangeBsearchAlgorithm autoload :ModuloAlgorithm autoload :HashSlotAlgorithm end def class_for(name_or_class) case nam...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/compatibility.rb
Ruby
mit
208
master
1,237
module ActiveRecord::Turntable module Compatibility def self.extended(base) base.instance_variable_set(:@_compatible_versions, []) end def [](version = ActiveRecord.gem_version.release) unless version.is_a?(Gem::Version) version = Gem::Version.new(version) end find_compati...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/cluster_helper_methods.rb
Ruby
mit
208
master
3,019
module ActiveRecord::Turntable module ClusterHelperMethods extend ActiveSupport::Concern included do ActiveSupport.on_load(:turntable_configuration_loaded) do turntable_clusters.each do |name, _cluster| turntable_define_cluster_methods(name) end end end module C...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/sequencer_registry.rb
Ruby
mit
208
master
767
module ActiveRecord::Turntable class SequencerRegistry attr_reader :sequencers alias_method :all, :sequencers def initialize @sequencers = {}.with_indifferent_access @cluster_sequencers = {}.with_indifferent_access end def add(name, type, options, cluster) # TODO: Warn if defin...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/sequencer.rb
Ruby
mit
208
master
910
module ActiveRecord::Turntable class Sequencer extend ActiveSupport::Autoload eager_autoload do autoload :Api autoload :Mysql autoload :Barrage autoload :Katsubushi end def sequence_name(table_name, primary_key = 'id') [table_name, primary_key, "seq"].join("_") end ...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/base.rb
Ruby
mit
208
master
4,020
require "active_support/lazy_load_hooks" module ActiveRecord::Turntable module Base extend ActiveSupport::Concern included do class_attribute :turntable_clusters, :turntable_sequencers, :turntable_enabled, :turntable_sequencer_enabled, :turntable_configuration self.turntab...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/mixer.rb
Ruby
mit
208
master
10,118
# rubocop:disable Style/CaseEquality require "active_support/core_ext/object/try" require "active_record/turntable/sql_tree_patch" module ActiveRecord::Turntable class Mixer extend ActiveSupport::Autoload eager_autoload do autoload :Fader end delegate :logger, to: ActiveRecord::Base NOT_...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/sequencer/api.rb
Ruby
mit
208
master
935
# # Sequencer via HTTP API # module ActiveRecord::Turntable class Sequencer class Api < Sequencer API_ENDPOINT = "/sequences/".freeze NEXT_VALUE_ENDPOINT = "/new".freeze def initialize(options = {}) require "httpclient" @options = options @host = @options[:api_host] ...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/sequencer/barrage.rb
Ruby
mit
208
master
579
module ActiveRecord::Turntable class Sequencer class Barrage < Sequencer class_attribute :unique_barrage_instance self.unique_barrage_instance = {} def initialize(options = {}) require "barrage" @options = options["options"] end def next_sequence_value(sequence_name...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/sequencer/mysql.rb
Ruby
mit
208
master
1,040
# -*- coding: utf-8 -*- # # 採番 # module ActiveRecord::Turntable class Sequencer class Mysql < Sequencer def initialize(options = {}) @options = options @shard = SeqShard.new(@options[:connection].to_s) end def connection @shard.connection end def release! ...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/sequencer/katsubushi.rb
Ruby
mit
208
master
684
module ActiveRecord::Turntable class Sequencer class Katsubushi < Sequencer def initialize(options = {}) @options = options["options"] opts = @options.dup servers = opts.delete("servers").map do |server| "#{server["host"]}:#{server["port"]}" end require "d...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/mixer/fader.rb
Ruby
mit
208
master
912
# -*- coding: utf-8 -*- module ActiveRecord::Turntable class Mixer class Fader extend ActiveSupport::Autoload eager_autoload do # single shard autoload :SpecifiedShard # multiple shard merging autoload :SelectShardsMergeResult autoload :InsertShardsMergeResult ...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/mixer/fader/specified_shard.rb
Ruby
mit
208
master
332
module ActiveRecord::Turntable class Mixer class Fader class SpecifiedShard < Fader def execute shard, query = @shards_query_hash.first @proxy.with_shard(shard) do shard.connection.send(@called_method, query, *@args, &@block) end end end en...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/mixer/fader/calculate_shards_sum_result.rb
Ruby
mit
208
master
735
module ActiveRecord::Turntable class Mixer class Fader class CalculateShardsSumResult < Fader def execute results = @shards_query_hash.map do |shard, query| args = @args.dup args[1] = args[1].dup if args[1].present? shard.connection.send(@called_method, ...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/mixer/fader/select_shards_merge_result.rb
Ruby
mit
208
master
927
module ActiveRecord::Turntable class Mixer class Fader class SelectShardsMergeResult < Fader def execute results = @shards_query_hash.map do |shard, query| args = @args.dup args[1] = args[1].dup if args[1].present? shard.connection.send(@called_method, q...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/mixer/fader/insert_shards_merge_result.rb
Ruby
mit
208
master
775
module ActiveRecord::Turntable class Mixer class Fader class InsertShardsMergeResult < Fader def execute if @shards_query_hash.size == 1 @proxy.shards_transaction(@shards_query_hash.keys) do shard, query = @shards_query_hash.first shard.connection.se...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/mixer/fader/update_shards_merge_result.rb
Ruby
mit
208
master
487
module ActiveRecord::Turntable class Mixer class Fader class UpdateShardsMergeResult < Fader def execute @proxy.shards_transaction(@shards_query_hash.keys) do @shards_query_hash.map do |shard, query| args = @args.dup args[1] = args[1].dup if args[1]....
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/configuration/dsl.rb
Ruby
mit
208
master
2,149
require "active_record/turntable/configuration" module ActiveRecord::Turntable class Configuration class DSL attr_reader :configuration def initialize(configuration = Configuration.new) @configuration = configuration end def cluster(name, &block) cluster_dsl = ClusterDSL...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/configuration/loader/dsl.rb
Ruby
mit
208
master
525
module ActiveRecord::Turntable class Configuration class Loader::DSL attr_reader :path, :configuration, :dsl def initialize(path, configuration = Configuration.new) @path = path @configuration = configuration @dsl = DSL.new(@configuration) end def self.load(path, ...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/configuration/loader/yaml.rb
Ruby
mit
208
master
1,927
module ActiveRecord::Turntable class Configuration class Loader::YAML attr_reader :path, :configuration, :dsl def initialize(path, configuration = Configuration.new) @path = path @configuration = configuration @dsl = DSL.new(@configuration) end def self.load(path,...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/active_record_ext/locking_optimistic.rb
Ruby
mit
208
master
5,135
module ActiveRecord::Turntable module ActiveRecordExt module LockingOptimistic if Util.ar_version_equals_or_later?("5.1.6") ::ActiveRecord::Locking::Optimistic.class_eval <<-EOD private def _update_row(attribute_names, attempted_action = "update") return super unless...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/active_record_ext/clever_load.rb
Ruby
mit
208
master
1,952
module ActiveRecord::Turntable module ActiveRecordExt module CleverLoad extend ActiveSupport::Concern included do class << ActiveRecord::Base delegate :clever_load!, to: :all end end def clever_load!(association_name) # load records records = sel...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/active_record_ext/persistence.rb
Ruby
mit
208
master
7,831
module ActiveRecord::Turntable module ActiveRecordExt module Persistence extend ActiveSupport::Concern extend Compatibility ::ActiveRecord::Persistence.class_eval do # @note Override to add sharding scope on reloading def reload(options = nil) self.class.connection.cle...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/active_record_ext/query_cache.rb
Ruby
mit
208
master
2,548
module ActiveRecord::Turntable module ActiveRecordExt module QueryCache def self.prepended(klass) class << klass prepend ClassMethods.compatible_module end end module ClassMethods extend Compatibility module V6_0 end module V5_2 ...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/active_record_ext/connection_handler_extension.rb
Ruby
mit
208
master
468
module ActiveRecord::Turntable module ActiveRecordExt module ConnectionHandlerExtension def owner_to_turntable_pool @owner_to_turntable_pool ||= Concurrent::Map.new(initial_capacity: 2) end # @note Override not to establish_connection destroy existing connection pool proxy object ...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/active_record_ext/database_tasks.rb
Ruby
mit
208
master
3,141
require "active_record/tasks/database_tasks" module ActiveRecord module Tasks module DatabaseTasks def create_all_turntable_cluster each_local_turntable_cluster_configuration { |_name, configuration| puts "[turntable] *** executing to database: #{configuration['database']}" crea...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/active_record_ext/activerecord_import_ext.rb
Ruby
mit
208
master
1,726
module ActiveRecord::Turntable module ActiveRecordExt # activerecord-import extension module ActiverecordImportExt # @note override for sequencer injection # @see https://github.com/zdennis/activerecord-import/blob/85586d052822b8d498ced6c900251997edbeee04/lib/activerecord-import/import.rb#L848-L88...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/active_record_ext/association_preloader.rb
Ruby
mit
208
master
856
require "active_record/associations/preloader/association" module ActiveRecord::Turntable module ActiveRecordExt module AssociationPreloader include ShardingCondition if Util.ar52_or_later? def build_scope returning_scope = super if should_use_shard_key? return...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/active_record_ext/fixtures.rb
Ruby
mit
208
master
5,080
# # force TestFixtures to begin transaction with all shards. # require "active_record/fixtures" require "active_record/turntable/util" module ActiveRecord class FixtureSet extend ActiveRecord::Turntable::Util # rubocop:disable Style/MultilineMethodCallBraceLayout unless ar52_or_later? def self.cre...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/active_record_ext/log_subscriber.rb
Ruby
mit
208
master
1,618
require "active_record/log_subscriber" module ActiveRecord::Turntable module ActiveRecordExt module LogSubscriber # @note prepend to add shard name logging def sql(event) self.class.runtime += event.duration return unless logger.debug? payload = event.payload return ...
github
drecom/activerecord-turntable
https://github.com/drecom/activerecord-turntable
lib/active_record/turntable/active_record_ext/association.rb
Ruby
mit
208
master
887
require "active_record/associations" module ActiveRecord::Turntable module ActiveRecordExt module Association include ShardingCondition def self.prepended(mod) ActiveRecord::Associations::Builder::Association::VALID_OPTIONS << :foreign_shard_key end protected # @note Ov...