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
akabiru/faker-bot
https://github.com/akabiru/faker-bot
lib/faker/bot/renderer.rb
Ruby
mit
201
main
4,164
# frozen_string_literal: true require 'pastel' require 'tty/pager' require 'tty/screen' require 'tty/tree' module Faker module Bot # A class responsible for printing output to an [IO] interface # # @api private # class Renderer DEPRECATION_WARNING = ' ( WILL BE DEPRECATED )' EMPTY = ...
github
akabiru/faker-bot
https://github.com/akabiru/faker-bot
lib/faker/bot/command.rb
Ruby
mit
201
main
962
# frozen_string_literal: true require 'forwardable' require_relative 'renderer' module Faker module Bot # @abstract interface for [Command] objects # # @api private # class Command extend Forwardable def_delegators :command, :run # [Command] options # # @return [...
github
akabiru/faker-bot
https://github.com/akabiru/faker-bot
lib/faker/bot/commands/search.rb
Ruby
mit
201
main
1,264
# frozen_string_literal: true require_relative '../command' require_relative '../reflectors/search' module Faker module Bot module Commands # Runs a search against [Faker<Base>] methods and returns matching results # # @api private # class Search < Command # Execute the `se...
github
akabiru/faker-bot
https://github.com/akabiru/faker-bot
lib/faker/bot/commands/list.rb
Ruby
mit
201
main
1,287
# frozen_string_literal: true require_relative '../command' require_relative '../reflectors/list' module Faker module Bot module Commands # Lists all [Faker<Base>] constants # # @api private # class List < Command # Execute the `list` command # # @return [IO...
github
akabiru/faker-bot
https://github.com/akabiru/faker-bot
lib/faker/bot/reflectors/search.rb
Ruby
mit
201
main
1,806
# frozen_string_literal: true require_relative '../reflector' module Faker module Bot module Reflectors # Reflection object that searches all `Faker::Base` subclass methods # * Currently operates at O(n); improvements welcome. :) # # @api private # class Search < Reflector ...
github
akabiru/faker-bot
https://github.com/akabiru/faker-bot
lib/faker/bot/reflectors/list.rb
Ruby
mit
201
main
2,314
# frozen_string_literal: true require_relative '../reflector' module Faker module Bot module Reflectors # Reflection object that lists all `Faker::Base` subclasses # # @api private # class List < Reflector # Output filter # # @return [String, nil] # ...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
Gemfile
Ruby
mit
201
master
476
# frozen_string_literal: true source 'https://rubygems.org' gem 'appraisal' gem 'aruba' gem 'bundler' gem 'byebug' gem 'hirb' gem 'pry' gem 'rails' gem 'rake' gem 'rspec' gem 'simplecov' gem 'rubocop', require: false gem 'rubocop-packaging', require: false gem 'rubocop-performance', require: false gem 'rubocop-rails...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
Rakefile
Ruby
mit
201
master
1,312
# frozen_string_literal: true require 'bundler/gem_tasks' # RSpec require 'rspec/core/rake_task' RSpec::Core::RakeTask.new do |spec| spec.rspec_opts = '-f progress' if ENV['CI'] end task default: ['testapp:create', :spec] # Create a test Rails app in tmp/railsapp for testing the rake # tasks and overall Rails inte...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
chrono_model.gemspec
Ruby
mit
201
master
1,138
# frozen_string_literal: true require File.expand_path('lib/chrono_model/version', __dir__) Gem::Specification.new do |gem| gem.authors = ['Marcello Barnaba', 'Peter Joseph Brindisi'] gem.email = ['vjt@openssl.it', 'p.brindisi@ifad.org'] gem.description = 'Give your models as-of date temporal ex...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
Appraisals
Ruby
mit
201
master
467
# frozen_string_literal: true appraise 'rails-7.0' do gem 'rails', '~> 7.0.0' gem 'concurrent-ruby', '1.3.4' # Ref: rails/rails#54260 end appraise 'rails-7.1' do gem 'rails', '~> 7.1.0' end appraise 'rails-7.2' do gem 'rails', '~> 7.2.0' end appraise 'rails-8.0' do gem 'rails', '~> 8.0.0' end appraise '...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/spec_helper.rb
Ruby
mit
201
master
5,573
# frozen_string_literal: true require 'simplecov' SimpleCov.start do add_filter '/benchmarks' add_filter '/spec' end require 'byebug' require 'chrono_model' require_relative 'support/connection' require_relative 'support/matchers/column' require_relative 'support/matchers/function' require_relative 'support/mat...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/history_models_spec.rb
Ruby
mit
201
master
1,586
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' RSpec.describe ChronoModel do describe '.history_models' do subject(:history_models) { described_class.history_models } it 'tracks recorded history models' do expected = {} # support/time_machine/struc...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/conversions_spec.rb
Ruby
mit
201
master
321
# frozen_string_literal: true require 'spec_helper' RSpec.describe ChronoModel::Conversions do describe '.time_to_utc_string' do subject { described_class.time_to_utc_string(time) } let(:time) { Time.utc(1981, 4, 11, 2, 42, 10, 123_456) } it { is_expected.to eq '1981-04-11 02:42:10.123456' } end end
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/model_identification_spec.rb
Ruby
mit
201
master
1,035
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' class Plain < ActiveRecord::Base; end RSpec.describe ChronoModel::TimeMachine do include ChronoTest::TimeMachine::Helpers adapter.create_table 'plains' do |t| t.string :foo end describe '.chrono?' do subjec...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/manipulations_spec.rb
Ruby
mit
201
master
3,333
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' RSpec.describe ChronoModel::TimeMachine do include ChronoTest::TimeMachine::Helpers describe '#save' do let(:historical_object) { $t.bar.history.first } let(:another_historical_object) { $t.bar.history.second } ...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/delegate_missing_to_spec.rb
Ruby
mit
201
master
781
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' class Attachment < ActiveRecord::Base belongs_to :blob delegate_missing_to :blob end class Blob < ActiveRecord::Base has_many :attachments end RSpec.describe ChronoModel::TimeMachine, '#delegate_missing_to' do inclu...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/history_spec.rb
Ruby
mit
201
master
4,321
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' RSpec.describe ChronoModel::TimeMachine do include ChronoTest::TimeMachine::Helpers describe '.history' do let(:foo_history) do ['foo', 'foo bar', 'new foo', 'foo 0', 'foo 1'] end let(:bar_history) do ...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/keep_cool_spec.rb
Ruby
mit
201
master
1,310
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' RSpec.describe ChronoModel::TimeMachine do include ChronoTest::TimeMachine::Helpers describe 'does not interfere with AR standard behaviour' do let(:all_foos) { [$t.foo] + $t.foos } let(:all_bars) { [$t.bar] + $t...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/timestamps_spec.rb
Ruby
mit
201
master
1,077
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' RSpec.describe ChronoModel::TimeMachine do include ChronoTest::TimeMachine::Helpers history_methods = %w[valid_from valid_to recorded_at] current_methods = %w[as_of_time] context 'with historical records' do let...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/historical_association_spec.rb
Ruby
mit
201
master
1,043
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' class Country < ActiveRecord::Base include ChronoModel::TimeMachine has_many :cities end class City < ActiveRecord::Base include ChronoModel::TimeMachine belongs_to :country end RSpec.describe ChronoModel::TimeMac...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/as_of_eager_loading_spec.rb
Ruby
mit
201
master
1,391
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' RSpec.describe ChronoModel::TimeMachine, :db do include ChronoTest::TimeMachine::Helpers describe 'as_of with eager_load associations' do context 'when loading historical associations' do # At $t.subbar.ts[0], ...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/timeline_spec.rb
Ruby
mit
201
master
1,922
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' RSpec.describe ChronoModel::TimeMachine do include ChronoTest::TimeMachine::Helpers describe '#timeline' do split = ->(ts) { ts.map! { |t| [t.to_i, t.usec] } } timestamps_from = lambda { |*records| records...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/sti_spec.rb
Ruby
mit
201
master
3,421
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' class Animal < ActiveRecord::Base include ChronoModel::TimeMachine end class Dog < Animal; end class Goat < Animal; end class Element < ActiveRecord::Base include ChronoModel::TimeMachine end class Publication < Eleme...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/changes_spec.rb
Ruby
mit
201
master
1,939
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' RSpec.describe ChronoModel::TimeMachine do include ChronoTest::TimeMachine::Helpers describe '#last_changes' do context 'with plain records' do context 'with history' do subject { $t.bar.last_changes } ...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/as_of_spec.rb
Ruby
mit
201
master
10,346
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' RSpec.describe ChronoModel::TimeMachine do include ChronoTest::TimeMachine::Helpers describe '.as_of' do it { expect(Foo.as_of(1.month.ago)).to eq [] } it { expect(Foo.as_of($t.foos[0].ts[0])).to eq [$t.foo, $t....
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/sequence_spec.rb
Ruby
mit
201
master
2,234
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' RSpec.describe ChronoModel::TimeMachine do include ChronoTest::TimeMachine::Helpers describe '#pred' do context 'with the first history entry' do subject { $t.foo.history.first.pred } it { is_expected.to...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/time_query_spec.rb
Ruby
mit
201
master
8,049
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' class Event < ActiveRecord::Base extend ChronoModel::TimeMachine::TimeQuery end RSpec.describe ChronoModel::TimeMachine::TimeQuery do include ChronoTest::TimeMachine::Helpers adapter.create_table 'events' do |t| t...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/eager_load_includes_joins_spec.rb
Ruby
mit
201
master
3,774
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' RSpec.describe ChronoModel::TimeMachine, :db do include ChronoTest::TimeMachine::Helpers describe 'includes + joins with as_of' do describe 'propagates as_of_time to eagerly loaded associations used in subsequent tra...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/counter_cache_race_spec.rb
Ruby
mit
201
master
1,217
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' class Section < ActiveRecord::Base include ChronoModel::TimeMachine has_many :articles end class Article < ActiveRecord::Base include ChronoModel::TimeMachine belongs_to :section, counter_cache: true end RSpec.des...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/transactions_spec.rb
Ruby
mit
201
master
1,640
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' RSpec.describe ChronoModel::TimeMachine do include ChronoTest::TimeMachine::Helpers # Transactions context 'with multiple updates to an existing record' do let!(:r1) do Foo.create!(name: 'xact test').tap do |...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/batches_spec.rb
Ruby
mit
201
master
910
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' RSpec.describe ChronoModel::TimeMachine do include ChronoTest::TimeMachine::Helpers describe '.find_each' do it { expect(Foo.history.find_each(batch_size: 2).count).to eq Foo.history.count } end describe '.in_ba...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/time_machine/default_scope_spec.rb
Ruby
mit
201
master
1,392
# frozen_string_literal: true require 'spec_helper' require 'support/time_machine/structure' class Defoo < ActiveRecord::Base include ChronoModel::TimeMachine default_scope proc { where(active: true) } end RSpec.describe ChronoModel::TimeMachine do include ChronoTest::TimeMachine::Helpers # Set up database...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/adapter/base_spec.rb
Ruby
mit
201
master
3,626
# frozen_string_literal: true require 'spec_helper' require 'support/adapter/structure' RSpec.describe ChronoModel::Adapter do include ChronoTest::Adapter::Structure subject { adapter } it { is_expected.to be_a(described_class) } describe '.adapter_name' do subject { adapter.adapter_name } it { is...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/adapter/indexes_spec.rb
Ruby
mit
201
master
1,664
# frozen_string_literal: true require 'spec_helper' require 'support/adapter/structure' RSpec.describe ChronoModel::Adapter do include ChronoTest::Adapter::Structure before do adapter.create_table :meetings do |t| t.string :name t.tsrange :interval end end after do adapter.drop_table...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/adapter/ddl_spec.rb
Ruby
mit
201
master
6,115
# frozen_string_literal: true require 'spec_helper' require 'support/adapter/structure' RSpec.describe ChronoModel::Adapter do include ChronoTest::Adapter::Structure let(:current) { "#{ChronoModel::Adapter::TEMPORAL_SCHEMA}.#{table}" } let(:history) { "#{ChronoModel::Adapter::HISTORY_SCHEMA}.#{table}" } def...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/chrono_model/adapter/migrations_spec.rb
Ruby
mit
201
master
15,932
# frozen_string_literal: true require 'spec_helper' require 'support/adapter/structure' # For the structure of these tables, please see spec/support/adabters/structure.rb. RSpec.shared_examples_for 'temporal table' do it { expect(adapter.is_chrono?(subject)).to be(true) } it { is_expected.not_to have_public_bac...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/support/aruba.rb
Ruby
mit
201
master
1,584
# frozen_string_literal: true require 'aruba/rspec' require 'arel' require 'rake' require 'rails' module ChronoTest module Aruba def schema_load_task(as_regexp: false) str = 'db:schema:load' as_regexp ? Regexp.new(str) : str end def copy_db_config(file = 'database_without_username_and_passw...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/support/connection.rb
Ruby
mit
201
master
1,758
# frozen_string_literal: true require 'pathname' require 'active_record' module ChronoTest AR = ActiveRecord::Base AR.automatically_invert_plural_associations = true if AR.respond_to?(:automatically_invert_plural_associations) log = ENV['VERBOSE'].present? ? $stderr : 'spec/debug.log'.tap { |f| File.open(f, 'ab...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/support/time_machine/structure.rb
Ruby
mit
201
master
5,631
# frozen_string_literal: true require 'support/time_machine/helpers' # This module contains the test DDL and models used by most of the # +TimeMachine+ specs. # # The models exercise different ActiveRecord features. # # They look candidate of unwinding by their respective specs, however this # test suite aims testing...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/support/time_machine/helpers.rb
Ruby
mit
201
master
1,675
# frozen_string_literal: true module ChronoTest module TimeMachine # This module contains helpers used throughout the # +ChronoModel::TimeMachine+ specs. # module Helpers def self.included(base) base.extend(self) end def adapter ChronoTest.connection end ...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/support/adapter/shared_contexts.rb
Ruby
mit
201
master
342
# frozen_string_literal: true RSpec.shared_context 'with temporal tables' do before { adapter.create_table(table, temporal: true, &columns) } after { adapter.drop_table table } end RSpec.shared_context 'with plain tables' do before { adapter.create_table(table, temporal: false, &columns) } after { adapter.d...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/support/adapter/structure.rb
Ruby
mit
201
master
1,286
# frozen_string_literal: true require_relative 'shared_contexts' # This module contains the definition of a test structure that is used by the # adapter methods tests, that look up in the database directly whether the # expected objects have been created. # # The structure definition below serves as a blueprint of wh...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/support/matchers/table.rb
Ruby
mit
201
master
9,157
# frozen_string_literal: true require_relative 'base' module ChronoTest module Matchers module Table class Base < ChronoTest::Matchers::Base protected # Database statements # def relation_exists?(options) schema = options[:in] kind = options[:kind] ==...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/support/matchers/schema.rb
Ruby
mit
201
master
893
# frozen_string_literal: true require_relative 'base' module ChronoTest module Matchers module Schema class BeInSchema < ChronoTest::Matchers::Base def initialize(expected) @expected = expected @expected = '"$user", public' if @expected == :default end def desc...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/support/matchers/column.rb
Ruby
mit
201
master
2,436
# frozen_string_literal: true require_relative 'base' module ChronoTest module Matchers module Column class HaveColumns < ChronoTest::Matchers::Base def initialize(columns, schema = 'public') @columns = columns @schema = schema end def description 'h...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/support/matchers/function.rb
Ruby
mit
201
master
2,046
# frozen_string_literal: true require_relative 'base' module ChronoTest module Matchers module Function class HaveFunctions < ChronoTest::Matchers::Base def initialize(functions, schema = 'public') @functions = functions @schema = schema end def description ...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/support/matchers/source.rb
Ruby
mit
201
master
1,008
# frozen_string_literal: true require_relative 'base' module ChronoTest module Matchers module Source class HaveFunctionSource < ChronoTest::Matchers::Base def initialize(function, source_regexp) @function = function @regexp = source_regexp end def descriptio...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/support/matchers/index.rb
Ruby
mit
201
master
1,902
# frozen_string_literal: true require_relative 'base' module ChronoTest module Matchers module Index class HaveIndex < ChronoTest::Matchers::Base attr_reader :name, :columns, :schema def initialize(name, columns, schema = 'public') @name = name @columns = columns.so...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/support/matchers/base.rb
Ruby
mit
201
master
1,400
# frozen_string_literal: true module ChronoTest module Matchers class Base include ActiveRecord::Sanitization::ClassMethods def failure_message_for_should_not failure_message_for_should.gsub('to ', 'to not ') end protected def connection ChronoTest.connection ...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/aruba/subclasses_spec.rb
Ruby
mit
201
master
649
# frozen_string_literal: true require 'spec_helper' RSpec.describe 'subclasses spec', type: :aruba do subject(:last_command) { action && last_command_started } let(:action) { run_command('bundle exec rails runner "Foo.subclasses"') } before do set_environment_variable 'CM_TEST_EAGER_LOAD', true set_en...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/aruba/migrations_spec.rb
Ruby
mit
201
master
1,291
# frozen_string_literal: true require 'spec_helper' RSpec.describe 'database migrations', type: :aruba do before { copy_db_config } context 'when a migration is generated' do before { run_command_and_stop('bundle exec rails g migration CreateModels name:string') } describe 'bundle exec rails db:migrate'...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/aruba/dbconsole_spec.rb
Ruby
mit
201
master
391
# frozen_string_literal: true require 'spec_helper' RSpec.describe 'rails dbconsole', type: :aruba do subject { action && last_command_started } let(:action) { run_command("bash -c \"echo 'select 1 as foo_column; \\q' | bundle exec rails db\"") } before { copy_db_config } it { is_expected.to be_successfull...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
spec/aruba/rake_task_spec.rb
Ruby
mit
201
master
3,443
# frozen_string_literal: true require 'spec_helper' require 'rake' RSpec.describe 'rake tasks', type: :aruba do describe 'bundle exec rake -T' do subject { last_command_started } before do copy_db_config run_command_and_stop('bundle exec rake -T') end it { is_expected.to have_output(sc...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
benchmarks/profile.rb
Ruby
mit
201
master
249
#!/usr/bin/env ruby -s # frozen_string_literal: true require_relative 'benchmark_sample' require 'ruby-prof' result = RubyProf::Profile.profile do run_benchmark_sample end printer = RubyProf::FlatPrinter.new(result) printer.print($stdout, {})
github
ifad/chronomodel
https://github.com/ifad/chronomodel
benchmarks/benchmark_sample.rb
Ruby
mit
201
master
1,355
# frozen_string_literal: true $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" require 'chrono_model' require 'rails' ActiveRecord::Base.establish_connection(adapter: 'chronomodel', database: 'chronomodel_bench') ActiveRecord::Base.logger = Logger.new(nil) ActiveRecord::Migration.verbose = false ActiveRecord::S...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
benchmarks/profile_memory.rb
Ruby
mit
201
master
215
#!/usr/bin/env ruby -s # frozen_string_literal: true require_relative 'benchmark_sample' require 'memory_profiler' MemoryProfiler.report(allow_files: 'chronomodel/lib') do run_benchmark_sample end.pretty_print
github
ifad/chronomodel
https://github.com/ifad/chronomodel
benchmarks/benchmark.rb
Ruby
mit
201
master
1,467
#!/usr/bin/env ruby -s # frozen_string_literal: true unless ENV['COVERAGE'].nil? require 'simplecov' SimpleCov.start SimpleCov.command_name 'Bench' end require_relative 'benchmark_sample' require 'benchmark' ITERATIONS = 5_000 Foo.create! name: 'My Foo' Bar.create! name: 'My Bar' first_foo = Foo.first Ben...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model.rb
Ruby
mit
201
master
2,739
# frozen_string_literal: true require 'active_record' require_relative 'chrono_model/chrono' require_relative 'chrono_model/conversions' require_relative 'chrono_model/patches' require_relative 'chrono_model/adapter' require_relative 'chrono_model/time_machine' require_relative 'chrono_model/time_gate' require_relati...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/utilities.rb
Ruby
mit
201
master
831
# frozen_string_literal: true module ChronoModel module Utilities # Amends the given history item setting a different period. # Useful when migrating from legacy systems. # # To use it, extend AR::Base with ChronoModel::Utilities # # ActiveRecord::Base.instance_eval do # extend Chro...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/chrono.rb
Ruby
mit
201
master
523
# frozen_string_literal: true module ChronoModel # A module to add to ActiveRecord::Base to check if they are backed by # temporal tables. module Chrono # Checks whether this Active Record model is backed by a temporal table # # @return [Boolean] false if the connection does not respond to is_chrono?...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/patches.rb
Ruby
mit
201
master
308
# frozen_string_literal: true require_relative 'patches/as_of_time_holder' require_relative 'patches/as_of_time_relation' require_relative 'patches/join_node' require_relative 'patches/relation' require_relative 'patches/preloader' require_relative 'patches/association' require_relative 'patches/batches'
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/time_machine.rb
Ruby
mit
201
master
7,034
# frozen_string_literal: true require_relative 'time_machine/time_query' require_relative 'time_machine/timeline' require_relative 'time_machine/history_model' module ChronoModel module TimeMachine include ChronoModel::Patches::AsOfTimeHolder extend ActiveSupport::Concern included do if table_ex...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/conversions.rb
Ruby
mit
201
master
201
# frozen_string_literal: true module ChronoModel module Conversions module_function def time_to_utc_string(time) time.to_fs(:db) << '.' << format('%06d', time.usec) end end end
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/time_gate.rb
Ruby
mit
201
master
538
# frozen_string_literal: true module ChronoModel # Provides the TimeMachine API to non-temporal models that associate # temporal ones. # module TimeGate extend ActiveSupport::Concern include ChronoModel::Patches::AsOfTimeHolder module ClassMethods include ChronoModel::TimeMachine::Timeline ...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/railtie.rb
Ruby
mit
201
master
1,050
# frozen_string_literal: true require_relative '../active_record/tasks/chronomodel_database_tasks' module ChronoModel class Railtie < ::Rails::Railtie TASKS_CLASS = ActiveRecord::Tasks::ChronomodelDatabaseTasks # Register our database tasks under our adapter name ActiveRecord::Tasks::DatabaseTasks.regi...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/adapter.rb
Ruby
mit
201
master
6,270
# frozen_string_literal: true require 'active_record/connection_adapters/postgresql_adapter' require_relative 'adapter/migrations' require_relative 'adapter/migrations_modules/stable' require_relative 'adapter/ddl' require_relative 'adapter/indexes' require_relative 'adapter/upgrade' module ChronoModel # This cla...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/patches/association.rb
Ruby
mit
201
master
1,605
# frozen_string_literal: true module ChronoModel module Patches # Patches ActiveRecord::Associations::Association to add support for # temporal associations. # # Each record fetched from the +as_of+ scope on the owner class will have # an additional "as_of_time" field yielding the UTC time of the...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/patches/as_of_time_holder.rb
Ruby
mit
201
master
469
# frozen_string_literal: true module ChronoModel module Patches # Added to classes that need to carry the As-Of date around # module AsOfTimeHolder # Sets the virtual 'as_of_time' attribute to the given time, converting to UTC. # def as_of_time!(time) @_as_of_time = time.utc ...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/patches/as_of_time_relation.rb
Ruby
mit
201
master
271
# frozen_string_literal: true module ChronoModel module Patches # This class is a dummy relation whose scope is only to pass around the # as_of_time parameters across ActiveRecord call chains. class AsOfTimeRelation < ActiveRecord::Relation; end end end
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/patches/batches.rb
Ruby
mit
201
master
1,464
# frozen_string_literal: true module ChronoModel module Patches # Overrides the default batch methods for historical models # # In the default implementation, `cursor` defaults to `primary_key`, which is 'id'. # However, historical models need to use 'hid' instead of 'id'. # # This patch addr...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/patches/preloader.rb
Ruby
mit
201
master
1,856
# frozen_string_literal: true module ChronoModel module Patches # Patches ActiveRecord::Associations::Preloader to add support for # temporal associations. This is tying itself to Rails internals # and it is ugly :-(. # module Preloader attr_reader :chronomodel_options # Overwrite th...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/patches/join_node.rb
Ruby
mit
201
master
647
# frozen_string_literal: true module ChronoModel module Patches # Replaces the left side of an Arel join (table or table alias) with a SQL # literal pointing to the history virtual table at the given as_of_time, # preserving any existing table alias. class JoinNode < Arel::Nodes::SqlLiteral att...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/patches/db_console.rb
Ruby
mit
201
master
736
# frozen_string_literal: true module ChronoModel module Patches module DBConsole module Config def config super.dup.tap { |config| config['adapter'] = 'postgresql/chronomodel' } end end module DbConfig def db_config return @patched_db_config if @patc...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/patches/relation.rb
Ruby
mit
201
master
4,221
# frozen_string_literal: true module ChronoModel module Patches module Relation include ChronoModel::Patches::AsOfTimeHolder def preload_associations(records) # :nodoc: preload = preload_values preload += includes_values unless eager_loading? scope = StrictLoadingScope if str...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/time_machine/time_query.rb
Ruby
mit
201
master
2,820
# frozen_string_literal: true module ChronoModel module TimeMachine # # TODO Documentation # module TimeQuery def time_query(match, time, options) range = columns_hash.fetch(options[:on].to_s) where(time_query_sql(match, time, range, options)) end private de...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/time_machine/timeline.rb
Ruby
mit
201
master
3,627
# frozen_string_literal: true module ChronoModel module TimeMachine module Timeline # Returns an Array of unique UTC timestamps for which at least an # history record exists. Takes temporal associations into account. # def timeline(record = nil, options = {}) rid = if re...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/time_machine/history_model.rb
Ruby
mit
201
master
8,495
# frozen_string_literal: true module ChronoModel module TimeMachine module HistoryModel extend ActiveSupport::Concern included do self.table_name = "#{Adapter::HISTORY_SCHEMA}.#{superclass.table_name}" scope :chronological, -> { order(Arel.sql('lower(validity) ASC')) } end ...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/adapter/ddl.rb
Ruby
mit
201
master
9,110
# frozen_string_literal: true require 'active_support/core_ext/string/strip' require 'multi_json' module ChronoModel class Adapter < ActiveRecord::ConnectionAdapters::PostgreSQLAdapter module DDL private # Create the public view and its INSTEAD OF triggers # def chrono_public_view_ddl(t...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/adapter/migrations.rb
Ruby
mit
201
master
8,290
# frozen_string_literal: true module ChronoModel class Adapter < ActiveRecord::ConnectionAdapters::PostgreSQLAdapter module Migrations # Creates the given table, possibly creating the temporal schema # objects if the `:temporal` option is given and set to true. # def create_table(table_na...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/adapter/upgrade.rb
Ruby
mit
201
master
4,832
# frozen_string_literal: true module ChronoModel class Adapter < ActiveRecord::ConnectionAdapters::PostgreSQLAdapter module Upgrade def chrono_upgrade! chrono_ensure_schemas chrono_upgrade_structure! end private # Locate tables needing a structure upgrade # ...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/adapter/indexes.rb
Ruby
mit
201
master
6,773
# frozen_string_literal: true module ChronoModel class Adapter < ActiveRecord::ConnectionAdapters::PostgreSQLAdapter module Indexes # Create temporal indexes for timestamp search. # # This index is used by +TimeMachine.at+, `.current` and `.past` to # build the temporal WHERE clauses that...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/chrono_model/adapter/migrations_modules/stable.rb
Ruby
mit
201
master
1,275
# frozen_string_literal: true module ChronoModel class Adapter module MigrationsModules module Stable # If adding an index to a temporal table, add it to the one in the # temporal schema and to the history one. If the `:unique` option is # present, it is removed from the index creat...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/active_record/connection_adapters/chronomodel_adapter.rb
Ruby
mit
201
master
1,470
# frozen_string_literal: true require_relative '../../chrono_model' module ActiveRecord # TODO: Remove when dropping Rails < 7.2 compatibility module ConnectionHandling def chronomodel_adapter_class ChronoModel::Adapter end # Install the new adapter in ActiveRecord. This approach is required be...
github
ifad/chronomodel
https://github.com/ifad/chronomodel
lib/active_record/tasks/chronomodel_database_tasks.rb
Ruby
mit
201
master
3,273
# frozen_string_literal: true module ActiveRecord module Tasks class ChronomodelDatabaseTasks < PostgreSQLDatabaseTasks CHRONOMODEL_SCHEMAS = [ ChronoModel::Adapter::TEMPORAL_SCHEMA, ChronoModel::Adapter::HISTORY_SCHEMA ].freeze def structure_dump(*arguments) if schema_...
github
calebhearth/title
https://github.com/calebhearth/title
Gemfile
Ruby
mit
201
main
301
source 'https://rubygems.org' rails_version = ENV.fetch("RAILS_VERSION", "7.1") if rails_version == "main" rails_constraint = { github: "rails/rails" } else rails_constraint = "~> #{rails_version}.0" end gem "rails", rails_constraint # Specify your gem's dependencies in title.gemspec gemspec
github
calebhearth/title
https://github.com/calebhearth/title
title.gemspec
Ruby
mit
201
main
1,004
# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'title/version' Gem::Specification.new do |spec| spec.name = 'title' spec.version = Title::VERSION spec.authors = ['Caleb Hearth'] spec.email = ['caleb@calebh...
github
calebhearth/title
https://github.com/calebhearth/title
lib/title.rb
Ruby
mit
201
main
280
app = File.expand_path('../../app', __FILE__) $LOAD_PATH.unshift(app) unless $LOAD_PATH.include?(app) require 'title/version' require 'active_support' require 'rails/engine' require 'title/engine' require 'helpers/title/title_helper' module Title # Your code goes here... end
github
calebhearth/title
https://github.com/calebhearth/title
app/helpers/title/title_helper.rb
Ruby
mit
201
main
1,612
module Title module TitleHelper def title(additional_context = {}) context = controller.view_assigns.merge(additional_context).symbolize_keys PageTitle.new(controller_path, action_name, context).to_s end class PageTitle def initialize(controller_path, action_name, context) @cont...
github
calebhearth/title
https://github.com/calebhearth/title
spec/helpers/title_helper_spec.rb
Ruby
mit
201
main
2,523
require 'title' describe Title::TitleHelper do it 'is the app name when no translation is present' do stub_rails expect(helper.title).to eq('Dummy') end it 'uses the application title by default' do stub_rails load_translations(application: 'Not Dummy') expect(helper.title).to eq('Not Dumm...
github
clio/jit_preloader
https://github.com/clio/jit_preloader
jit_preloader.gemspec
Ruby
mit
201
master
1,523
# frozen_string_literal: true lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'jit_preloader/version' Gem::Specification.new do |spec| spec.name = 'jit_preloader' spec.version = JitPreloader::VERSION spec.authors = ["Kyle d'Oliveira"] ...
github
clio/jit_preloader
https://github.com/clio/jit_preloader
spec/spec_helper.rb
Ruby
mit
201
master
1,537
require 'bundler/setup' Bundler.setup require 'jit_preloader' require 'support/database' require 'support/models' require 'byebug' require 'database_cleaner' DatabaseCleaner.strategy = :transaction RSpec.configure do |config| config.before(:suite) do Database.connect! Database.build! end config.before ...
github
clio/jit_preloader
https://github.com/clio/jit_preloader
spec/support/models.rb
Ruby
mit
201
master
2,484
class ContactBook < ActiveRecord::Base has_many :contacts has_many :contacts_with_scope, ->(_contact_book) { desc }, class_name: "Contact", foreign_key: :contact_book_id has_many :employees, through: :contacts has_many :companies has_many :company_employees, through: :companies, source: :employees has_man...
github
clio/jit_preloader
https://github.com/clio/jit_preloader
spec/support/database.rb
Ruby
mit
201
master
1,246
class Database def self.tables [ "CREATE TABLE contact_books (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(255))", "CREATE TABLE contacts (id INTEGER NOT NULL PRIMARY KEY, type VARCHAR(255), contact_book_id INTEGER, contact_id INTEGER, name VARCHAR(255), contact_owner_id INTEGER, contact_owner_type V...
github
clio/jit_preloader
https://github.com/clio/jit_preloader
spec/lib/jit_preloader/preloader_spec.rb
Ruby
mit
201
master
23,050
require "spec_helper" require "db-query-matchers" RSpec.describe JitPreloader::Preloader do let!(:contact1) do addresses = [ Address.new(street: "123 Fake st", country: canada), Address.new(street: "21 Jump st", country: usa), Address.new(street: "90210 Beverly Hills", country: usa) ] p...
github
clio/jit_preloader
https://github.com/clio/jit_preloader
spec/lib/jit_preloader/active_record/base_spec.rb
Ruby
mit
201
master
4,282
require 'spec_helper' require "db-query-matchers" RSpec.describe "ActiveRecord::Base Extensions" do let(:canada) { Country.create(name: "Canada") } let(:usa) { Country.create(name: "U.S.A") } describe "#preload_scoped_relation" do def call(contact) contact.preload_scoped_relation( name: "Amer...
github
clio/jit_preloader
https://github.com/clio/jit_preloader
lib/jit_preloader.rb
Ruby
mit
201
master
1,428
require 'active_support/concern' require 'active_support/core_ext/module/delegation' require 'active_support/notifications' require 'active_record' require "jit_preloader/version" require 'jit_preloader/active_record/base' require 'jit_preloader/active_record/relation' require 'jit_preloader/active_record/associations...
github
clio/jit_preloader
https://github.com/clio/jit_preloader
lib/jit_preloader/preloader.rb
Ruby
mit
201
master
2,514
module JitPreloader class Preloader < ActiveRecord::Associations::Preloader attr_accessor :records if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("7.0.0") def self.attach(records) new(records: records.dup, associations: nil).tap do |loader| records.each do |re...
github
clio/jit_preloader
https://github.com/clio/jit_preloader
lib/jit_preloader/active_record/base.rb
Ruby
mit
201
master
6,312
module JitPreloadExtension attr_accessor :jit_preloader attr_accessor :jit_n_plus_one_tracking attr_accessor :jit_preload_aggregates attr_accessor :jit_preload_scoped_relations def reload(*args) clear_jit_preloader! super end def clear_jit_preloader! self.jit_preload_aggregates = {} self...
github
clio/jit_preloader
https://github.com/clio/jit_preloader
lib/jit_preloader/active_record/relation.rb
Ruby
mit
201
master
1,066
module JitPreloader module ActiveRecordRelation def jit_preload(*args) spawn.jit_preload!(*args) end def jit_preload!(*args) @jit_preload = true self end def jit_preload? @jit_preload end def calculate(*args) if respond_to?(:proxy_association) && proxy_ass...
github
clio/jit_preloader
https://github.com/clio/jit_preloader
lib/jit_preloader/active_record/associations/collection_association.rb
Ruby
mit
201
master
1,235
module JitPreloader module ActiveRecordAssociationsCollectionAssociation def load_target was_loaded = loaded? if !loaded? && owner.persisted? && owner.jit_preloader && (reflection.scope.nil? || reflection.scope.arity == 0) owner.jit_preloader.jit_preload(reflection.name) end jit...