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 | redbooth/departure | https://github.com/redbooth/departure | lib/departure/logger.rb | Ruby | mit | 86 | master | 1,185 | module Departure
# Copies the ActiveRecord::Migration #say and #write plus a new
# #write_no_newline to log the migration's status. It's not possible to reuse
# the from ActiveRecord::Migration because the migration's instance can't be
# seen from the connection adapter.
class Logger
def initialize(saniti... |
github | redbooth/departure | https://github.com/redbooth/departure | lib/departure/connection_details.rb | Ruby | mit | 86 | master | 2,042 | module Departure
# Holds the parameters of the DB connection and formats them to string
class ConnectionDetails
DEFAULT_PORT = 3306
# Constructor
#
# @param [Hash] connection parametes as used in #establish_conneciton
def initialize(connection_data)
@connection_data = connection_data
e... |
github | redbooth/departure | https://github.com/redbooth/departure | lib/departure/option.rb | Ruby | mit | 86 | master | 1,501 | module Departure
class Option
attr_reader :name, :value
# Builds an instance by parsing its name and value out of the given string.
#
# @param string [String]
# @return [Option]
def self.from_string(string)
name, value = string.split(/\s|=/, 2)
new(name, value)
end
# Cons... |
github | redbooth/departure | https://github.com/redbooth/departure | lib/departure/dsn.rb | Ruby | mit | 86 | master | 684 | module Departure
# Represents the 'DSN' argument of Percona's pt-online-schema-change
# See https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html#dsn-options
class DSN
# Constructor
#
# @param database [String, Symbol]
# @param table_name [String, Symbol]
def initialize(... |
github | redbooth/departure | https://github.com/redbooth/departure | lib/departure/command.rb | Ruby | mit | 86 | master | 2,761 | module Departure
# Executes the given command returning it's status and errors
class Command
COMMAND_NOT_FOUND = 127
# Constructor
#
# @param command_line [String]
# @param error_log_path [String]
# @param logger [#write_no_newline]
def initialize(command_line, error_log_path, logger)
... |
github | redbooth/departure | https://github.com/redbooth/departure | lib/departure/logger_factory.rb | Ruby | mit | 86 | master | 410 | module Departure
module LoggerFactory
# Returns the appropriate logger instance for the given configuration. Use
# :verbose option to log to the stdout
#
# @param verbose [Boolean]
# @return [#say, #write]
def self.build(sanitizers: [], verbose: true)
if verbose
Departure::Logger... |
github | redbooth/departure | https://github.com/redbooth/departure | lib/departure/user_options.rb | Ruby | mit | 86 | master | 920 | module Departure
# Encapsulates the pt-online-schema-change options defined by the user
class UserOptions
delegate :each, :merge, to: :to_set
# Constructor
#
# @param arguments [String]
def initialize(arguments = ENV['PERCONA_ARGS'])
@arguments = arguments
end
private
attr_r... |
github | redbooth/departure | https://github.com/redbooth/departure | lib/departure/configuration.rb | Ruby | mit | 86 | master | 374 | module Departure
class Configuration
attr_accessor :tmp_path, :global_percona_args
def initialize
@tmp_path = '.'.freeze
@error_log_filename = 'departure_error.log'.freeze
@global_percona_args = nil
end
def error_log_path
File.join(tmp_path, error_log_filename)
end
p... |
github | redbooth/departure | https://github.com/redbooth/departure | lib/departure/log_sanitizers/password_sanitizer.rb | Ruby | mit | 86 | master | 530 | module Departure
module LogSanitizers
class PasswordSanitizer
PASSWORD_REPLACEMENT = '[filtered_password]'.freeze
delegate :password_argument, to: :connection_details
def initialize(connection_details)
@connection_details = connection_details
end
def execute(log_statement)... |
github | redbooth/departure | https://github.com/redbooth/departure | lib/active_record/connection_adapters/percona_adapter.rb | Ruby | mit | 86 | master | 4,337 | require 'active_record/connection_adapters/abstract_mysql_adapter'
require 'active_record/connection_adapters/statement_pool'
require 'active_record/connection_adapters/mysql2_adapter'
require 'departure'
require 'forwardable'
module ActiveRecord
module ConnectionHandling
# Establishes a connection to the databa... |
github | redbooth/departure | https://github.com/redbooth/departure | lib/lhm/column_with_type.rb | Ruby | mit | 86 | master | 667 | module Lhm
# Abstracts the details of a table column definition when specified with a type
# as a symbol. This is the regular ActiveRecord's #add_column syntax:
#
# add_column :tablenames, :field, :string
#
class ColumnWithType
# Constructor
#
# @param name [String, Symbol]
# @param defini... |
github | redbooth/departure | https://github.com/redbooth/departure | lib/lhm/adapter.rb | Ruby | mit | 86 | master | 3,433 | require 'lhm/column_with_sql'
require 'lhm/column_with_type'
module Lhm
# Translates Lhm DSL to ActiveRecord's one, so Lhm migrations will now go
# through Percona as well, without any modification on the migration's
# code
class Adapter
# Constructor
#
# @param migration [ActiveRecord::Migtration]... |
github | redbooth/departure | https://github.com/redbooth/departure | lib/lhm/column_with_sql.rb | Ruby | mit | 86 | master | 2,274 | require 'forwardable'
module Lhm
# Abstracts the details of a table column definition when specified with a MySQL
# column definition string
class ColumnWithSql
extend Forwardable
# Returns the column's class to be used
#
# @return [Constant]
def self.column_factory
::ActiveRecord::Con... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/integration_spec.rb | Ruby | mit | 86 | master | 6,793 | require 'spec_helper'
# TODO: Handle #change_table syntax
describe Departure, integration: true do
class Comment < ActiveRecord::Base; end
let(:migration_fixtures) do
ActiveRecord::Migrator.migrations(MIGRATION_FIXTURES)
end
let(:migration_path) { [MIGRATION_FIXTURES] }
let(:direction) { :up }
it 'h... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/percona_migrator_spec.rb | Ruby | mit | 86 | master | 256 | require 'spec_helper'
describe Departure do
describe '.configure' do
it 'yields the configuration object' do
expect do |b|
described_class.configure(&b)
end.to yield_with_args(kind_of(Departure::Configuration))
end
end
end |
github | redbooth/departure | https://github.com/redbooth/departure | spec/spec_helper.rb | Ruby | mit | 86 | master | 1,332 | require 'simplecov'
SimpleCov.start
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
Bundler.require(:default, :development)
require './configuration'
require './test_database'
require 'departure'
require 'lhm'
require 'support/matchers/have_column'
require 'support/matchers/have_index'
require 'support/... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/lhm_integration_spec.rb | Ruby | mit | 86 | master | 666 | require 'spec_helper'
describe Departure, integration: true do
class Comment < ActiveRecord::Base; end
let(:migration_fixtures) do
File.expand_path('../fixtures/lhm_migrate/', __FILE__)
end
let(:direction) { :up }
context 'creating/removing columns' do
let(:version) { 1 }
context 'creating col... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/lhm/column_with_sql_spec.rb | Ruby | mit | 86 | master | 7,403 | require 'spec_helper'
describe Lhm::ColumnWithSql do
let(:name) { :some_field_name }
let(:column) { described_class.new(name, definition) }
describe '#attributes' do
subject { column.attributes }
context 'when defining INT' do
let(:definition) { 'INT' }
its([0]) { is_expected.to eq(:intege... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/lhm/column_with_type_spec.rb | Ruby | mit | 86 | master | 294 | require 'spec_helper'
describe Lhm::ColumnWithType do
let(:name) { :some_field_name }
let(:definition) { :integer }
let(:column) { described_class.new(name, definition) }
describe '#attributes' do
subject { column.attributes }
it { is_expected.to eq([definition]) }
end
end |
github | redbooth/departure | https://github.com/redbooth/departure | spec/lhm/adapter/add_unique_index_spec.rb | Ruby | mit | 86 | master | 1,645 | require 'spec_helper'
describe Lhm::Adapter, '#add_unique_index' do
let(:migration) { double(:migration) }
let(:table_name) { :comments }
let(:adapter) { described_class.new(migration, table_name) }
context 'when passing a single column' do
before do
allow(migration).to(
receive(:add_index)... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/lhm/adapter/remove_column_spec.rb | Ruby | mit | 86 | master | 577 | require 'byebug'
require 'spec_helper'
describe Lhm::Adapter, '#remove_column' do
let(:migration) { double(:migration) }
let(:table_name) { :comments }
let(:adapter) { described_class.new(migration, table_name) }
before do
allow(migration).to(
receive(:remove_column).with(table_name, column_name)
... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/lhm/adapter/add_index_spec.rb | Ruby | mit | 86 | master | 1,315 | require 'byebug'
require 'spec_helper'
describe Lhm::Adapter, '#add_index' do
let(:migration) { double(:migration) }
let(:table_name) { :comments }
let(:adapter) { described_class.new(migration, table_name) }
before do
allow(migration).to(
receive(:add_index).with(table_name, columns, options)
... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/lhm/adapter/remove_index_spec.rb | Ruby | mit | 86 | master | 1,559 | require 'spec_helper'
describe Lhm::Adapter, '#remove_index' do
let(:migration) { double(:migration) }
let(:table_name) { :comments }
let(:adapter) { described_class.new(migration, table_name) }
context 'when passing a single column' do
before do
allow(migration).to(
receive(:remove_index).... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/lhm/adapter/rename_column_spec.rb | Ruby | mit | 86 | master | 661 | require 'spec_helper'
describe Lhm::Adapter, '#rename_column' do
let(:migration) { double(:migration) }
let(:table_name) { :comments }
let(:adapter) { described_class.new(migration, table_name) }
before do
allow(migration).to(
receive(:rename_column).with(table_name, column_name, new_column_name)
... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/lhm/adapter/shared_example_column_definition_method_spec.rb | Ruby | mit | 86 | master | 2,063 | # TODO: What about ENUM?
shared_examples 'column-definition method' do |method_name|
let(:migration) { double(:migration) }
let(:table_name) { :comments }
let(:adapter) { described_class.new(migration, table_name) }
before do
allow(column).to receive(:attributes).and_return(attributes)
end
context 'wh... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/departure/logger_factory_spec.rb | Ruby | mit | 86 | master | 571 | require 'spec_helper'
describe Departure::LoggerFactory do
describe '.build' do
context 'when :verbose is set as true' do
subject { described_class.build(verbose: true) }
it { is_expected.to be_a(Departure::Logger) }
end
context 'when :verbose is set as false' do
subject { described_cl... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/departure/runner_spec.rb | Ruby | mit | 86 | master | 1,488 | require 'spec_helper'
require 'tempfile'
describe Departure::Runner do
let(:command_line) { 'pt-online-schema-change command' }
let(:logger) { instance_double(Departure::Logger) }
let(:cli_generator) { instance_double(Departure::CliGenerator) }
let(:mysql_adapter) do
instance_double(ActiveRecord::Connectio... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/departure/alter_argument_spec.rb | Ruby | mit | 86 | master | 1,095 | require 'spec_helper'
describe Departure::AlterArgument do
let(:alter_argument) { described_class.new(statement) }
describe '#initialize' do
subject { described_class.new(statement) }
context 'when the statement is invalid' do
let(:statement) { 'CREATE TABLE `things`' }
it 'raises a InvalidA... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/departure/cli_generator_spec.rb | Ruby | mit | 86 | master | 4,921 | require 'spec_helper'
describe Departure::CliGenerator do
let(:cli_generator) { described_class.new(connection_details) }
let(:connection_details) do
instance_double(
Departure::ConnectionDetails,
database: 'dummy_test',
to_s: '-h localhost -u root'
)
end
let(:table_name) { 'tasks' }... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/departure/option_spec.rb | Ruby | mit | 86 | master | 3,406 | require 'spec_helper'
describe Departure::Option do
describe '.from_string' do
it 'gets the name and value' do
expect(described_class).to receive(:new).with('--arg', 'value')
described_class.from_string('--arg=value')
end
context 'when given a name in short form' do
it 'gets the short ... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/departure/command_spec.rb | Ruby | mit | 86 | master | 2,836 | require 'spec_helper'
describe Departure::Command do
describe '#run' do
let(:command) { 'pt-online-schema-change command' }
let(:error_log_path) { 'departure_error.log' }
let(:logger) do
instance_double(
Departure::Logger, write: true, say: true, write_no_newline: true
)
end
... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/departure/configuration_spec.rb | Ruby | mit | 86 | master | 455 | require 'spec_helper'
describe Departure::Configuration do
describe '#initialize' do
its(:tmp_path) { is_expected.to eq('.') }
its(:error_log_filename) { is_expected.to eq('departure_error.log') }
end
describe '#tmp_path' do
subject { described_class.new.tmp_path }
it { is_expected.to eq('.') }
... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/departure/connection_details_spec.rb | Ruby | mit | 86 | master | 2,319 | require 'spec_helper'
describe Departure::ConnectionDetails do
let(:connection_details) { described_class.new(connection_data) }
around do |example|
ClimateControl.modify(env_var) do
example.run
end
end
describe '#to_s' do
subject { connection_details.to_s }
let(:connection_data) do
... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/departure/logger_spec.rb | Ruby | mit | 86 | master | 2,258 | require 'spec_helper'
describe Departure::Logger do
let(:logger) { described_class.new(sanitizers) }
let(:sanitizers) { [] }
describe '#say' do
let(:message) { 'a random message' }
context 'when the subitem options is not specified' do
it 'prints the message to the stdout' do
expect(logge... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/departure/dsn_spec.rb | Ruby | mit | 86 | master | 272 | require 'spec_helper'
describe Departure::DSN do
let(:database) { 'development' }
let(:table_name) { 'comments' }
describe '#to_s' do
subject { described_class.new(database, table_name).to_s }
it { is_expected.to eq('D=development,t=comments') }
end
end |
github | redbooth/departure | https://github.com/redbooth/departure | spec/departure/null_logger_spec.rb | Ruby | mit | 86 | master | 347 | require 'spec_helper'
describe Departure::NullLogger do
let(:null_logger) { described_class.new }
let(:message) { 'a message' }
describe '#say' do
subject { null_logger.say(message) }
it { is_expected.to eq(nil) }
end
describe '#write' do
subject { null_logger.write(message) }
it { is_expec... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/departure/log_sanitizers/password_sanitizer_spec.rb | Ruby | mit | 86 | master | 845 | require 'spec_helper'
describe Departure::LogSanitizers::PasswordSanitizer do
subject(:password_sanitizer) { described_class.new(connection_details) }
let(:password_argument) { '-p secret_password' }
let(:connection_details) { double(:connection_details, password_argument: password_argument) }
describe '#exe... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/active_record/connection_adapters/percona_adapter_spec.rb | Ruby | mit | 86 | master | 6,350 | require 'spec_helper'
describe ActiveRecord::ConnectionAdapters::DepartureAdapter do
describe ActiveRecord::ConnectionAdapters::DepartureAdapter::Column do
let(:field) { double(:field) }
let(:default) { double(:default) }
let(:cast_type) { ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlStri... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/integration/tables_spec.rb | Ruby | mit | 86 | master | 1,760 | require 'spec_helper'
describe Departure, integration: true do
class Comment < ActiveRecord::Base; end
let(:migration_path) { [MIGRATION_FIXTURES] }
let(:direction) { :up }
context 'creating a table' do
let(:version) { 8 }
it 'creates the table' do
ActiveRecord::Migrator.run(direction, migrati... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/integration/data_migrations_spec.rb | Ruby | mit | 86 | master | 2,564 | require 'spec_helper'
describe Departure, integration: true do
class Comment < ActiveRecord::Base; end
let(:migration_fixtures) { [MIGRATION_FIXTURES] }
let(:direction) { :up }
before do
ActiveRecord::Base.connection.add_column(
:comments,
:read,
:boolean,
default: false,
nu... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/integration/indexes_spec.rb | Ruby | mit | 86 | master | 3,861 | require 'spec_helper'
describe Departure, integration: true do
class Comment < ActiveRecord::Base; end
let(:migration_fixtures) do
ActiveRecord::Migrator.migrations(MIGRATION_FIXTURES)
end
let(:migration_path) { [MIGRATION_FIXTURES] }
let(:direction) { :up }
context 'managing indexes' do
let(:ve... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/integration/columns_spec.rb | Ruby | mit | 86 | master | 4,250 | require 'spec_helper'
describe Departure, integration: true do
class Comment < ActiveRecord::Base; end
let(:migration_fixtures) do
ActiveRecord::Migrator.migrations(MIGRATION_FIXTURES)
end
let(:migration_path) { [MIGRATION_FIXTURES] }
let(:direction) { :up }
context 'managing columns' do
let(:ve... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/integration/references_spec.rb | Ruby | mit | 86 | master | 2,329 | require 'spec_helper'
describe Departure, integration: true do
class Comment < ActiveRecord::Base; end
let(:migration_path) { [MIGRATION_FIXTURES] }
let(:direction) { :up }
context 'creating references' do
context 'when no option is set' do
let(:version) { 16 }
it 'adds a reference column' d... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/support/table_methods.rb | Ruby | mit | 86 | master | 446 | module TableMethods
def columns(table_name)
ActiveRecord::Base.connection.columns(table_name)
end
def unique_indexes_from(table_name)
indexes = indexes_from(table_name)
indexes.select(&:unique).map(&:name)
end
def indexes_from(table_name)
ActiveRecord::Base.connection.indexes(table_name)
e... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/support/matchers/have_column.rb | Ruby | mit | 86 | master | 472 | # Defines a matcher to check whether a table contains a given column.
#
# @example Check the comments table contains the id column:
#
# expect(:comments).to have_column('id')
RSpec::Matchers.define :have_column do |expected|
match do |actual|
expect(column_names(actual)).to include(expected)
end
def column... |
github | redbooth/departure | https://github.com/redbooth/departure | spec/support/matchers/have_index.rb | Ruby | mit | 86 | master | 521 | # Defines a matcher to check whether a table contains a given index.
#
# @example Check the comments table contains the index index_comments_on_user_id
#
# expect(:comments).to have_index('index_comments_on_user_id')
RSpec::Matchers.define :have_index do |expected|
match do |actual|
expect(index_names(actual)).... |
github | gregretkowski/vmth | https://github.com/gregretkowski/vmth | vmth.gemspec | Ruby | apache-2.0 | 86 | master | 2,556 | # -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{vmth}
s.version = "0.0.1"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Greg Retkowski"]
s.date = %q{2011-04-26}
s.description = %q{require 'rubygems' require 'rake... |
github | gregretkowski/vmth | https://github.com/gregretkowski/vmth | Rakefile | Ruby | apache-2.0 | 86 | master | 698 | require 'rubygems'
require 'rake'
require 'echoe'
Echoe.new('vmth', '0.0.2') do |p|
p.description = File.open(File.dirname(__FILE__+"/DESCRIPTION")).read
p.summary = "A VM test harness for testing operational configurations"
p.url = "http://github.com/gregretkowski/vmth"
p.author =... |
github | gregretkowski/vmth | https://github.com/gregretkowski/vmth | lib/vmth.rb | Ruby | apache-2.0 | 86 | master | 18,541 | #!/usr/bin/ruby
#--
# Copyright 2011 Greg Retkowski
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law... |
github | gregretkowski/vmth | https://github.com/gregretkowski/vmth | lib/virb.rb | Ruby | apache-2.0 | 86 | master | 1,394 | #!/usr/bin/ruby
#--
# Copyright 2011 Greg Retkowski
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law... |
github | gregretkowski/vmth | https://github.com/gregretkowski/vmth | test/test_vmth.rb | Ruby | apache-2.0 | 86 | master | 427 | #!/bin/ruby
require File.dirname(__FILE__)+"/helpers.rb"
require 'vmth'
class VmthTest < Test::Unit::TestCase
def setup
true
end
def test_true
assert true
end
def test_new
assert_nothing_raised do
@vmth = Vmth.new()
end
end
def test_vmcl
@vmth = Vmth.new()
vmcl = @vmth... |
github | gregretkowski/vmth | https://github.com/gregretkowski/vmth | test/test_virb.rb | Ruby | apache-2.0 | 86 | master | 220 | #!/bin/ruby
require File.dirname(__FILE__)+"/helpers.rb"
require 'virb'
class VirbTest < Test::Unit::TestCase
def setup
true
end
def test_new
assert defined?(p_test)
assert defined?(f_apply)
end
end |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | compendium.gemspec | Ruby | mit | 86 | master | 1,139 | # -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'compendium/version'
Gem::Specification.new do |gem|
gem.name = "compendium"
gem.version = Compendium::VERSION
gem.authors = ["Daniel Vandersluis"]
gem.email... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/option_spec.rb | Ruby | mit | 86 | master | 367 | require 'compendium/option'
describe Compendium::Option do
it "should raise an ArgumentError if no name is given" do
expect { described_class.new }.to raise_error ArgumentError, "name must be provided"
end
it "should set up type predicates from the type option" do
o = described_class.new(name: :option, ... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/sum_query_spec.rb | Ruby | mit | 86 | master | 1,791 | require 'spec_helper'
require 'compendium/sum_query'
require 'compendium/report'
class SingleSummer
def sum(col)
1792
end
end
class MultipleSummer
def order(*)
@order = true
self
end
def reverse_order
@reverse = true
self
end
def sum(col)
results = { 1 => 340, 2 => 204, 3 => 98... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/param_types_spec.rb | Ruby | mit | 86 | master | 4,876 | require 'compendium/param_types'
describe Compendium::Param do
subject{ described_class.new(:test) }
it { is_expected.not_to be_scalar }
it { is_expected.not_to be_boolean }
it { is_expected.not_to be_date }
it { is_expected.not_to be_dropdown }
it { is_expected.not_to be_radio }
describe "#==" do
... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/dsl_spec.rb | Ruby | mit | 86 | master | 9,856 | require 'spec_helper'
require 'compendium'
require 'compendium/dsl'
describe Compendium::DSL do
subject do
Class.new do
extend Compendium::DSL
end
end
describe "#option" do
before { subject.option :starting_on, :date }
specify { expect(subject.options).to include :starting_on }
specif... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/report_spec.rb | Ruby | mit | 86 | master | 9,927 | require 'compendium/report'
describe Compendium::Report do
subject { described_class }
specify { expect(subject.queries).to be_empty }
specify { expect(subject.options).to be_empty }
it "should not do anything when run" do
report = subject.new
report.run
expect(report.results).to be_empty
end
... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/query_spec.rb | Ruby | mit | 86 | master | 6,043 | require 'spec_helper'
require 'compendium/query'
describe Compendium::Query do
describe "#initialize" do
let(:options) { double("Options") }
let(:proc) { double("Proc") }
context "when supplying a report" do
let(:r) { Compendium::Report.new }
subject { described_class.new(r, :test, options, ... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/spec_helper.rb | Ruby | mit | 86 | master | 203 | $:.unshift File.expand_path("../../app/classes", __FILE__)
RSpec.configure do |rspec|
rspec.mock_with :rspec do |mocks|
mocks.yield_receiver_to_any_instance_implementation_blocks = true
end
end |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/context_wrapper_spec.rb | Ruby | mit | 86 | master | 1,520 | require 'compendium/context_wrapper'
class Wrapper1
def test_val
123
end
end
class Wrapper2
def wrapped
true
end
end
class Wrapper3
def wrapper_num
3
end
end
class Wrapper4
def wrapper_num
4
end
end
describe Compendium::ContextWrapper do
describe ".wrap" do
let(:w1) { Wrapper1... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/collection_query_spec.rb | Ruby | mit | 86 | master | 2,216 | require 'spec_helper'
require 'compendium/collection_query'
describe Compendium::CollectionQuery do
let(:collection) { { one: 1, two: 2, three: 3 } }
subject { described_class.new(:collection_query, { collection: collection }, -> _, key, item { [item * 2] }) }
before { allow_any_instance_of(Compendium::Query).t... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/metric_spec.rb | Ruby | mit | 86 | master | 2,460 | require 'compendium/metric'
class MetricContext
def calculate(data)
data.first.first
end
end
describe Compendium::Metric do
let(:ctx) { MetricContext.new }
let(:data) { [[1, 2, 3], [4, 5, 6]] }
subject { described_class.new(:test_metric, :query, nil) }
describe "#run" do
it "should delegate the ... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/through_query_spec.rb | Ruby | mit | 86 | master | 3,457 | require 'compendium/through_query'
describe Compendium::ThroughQuery do
describe "#initialize" do
let(:options) { double("Options") }
let(:proc) { double("Proc") }
let(:through) { double("Query") }
context "when supplying a report" do
let(:r) { Compendium::Report.new }
subject { describe... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/count_query_spec.rb | Ruby | mit | 86 | master | 1,771 | require 'spec_helper'
require 'compendium'
require 'compendium/count_query'
class SingleCounter
def count
1792
end
end
class MultipleCounter
def order(*)
@order = true
self
end
def reverse_order
@reverse = true
self
end
def count
results = { 1 => 340, 2 => 204, 3 => 983 }
... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/result_set_spec.rb | Ruby | mit | 86 | master | 761 | require 'compendium/result_set'
describe Compendium::ResultSet do
describe "#initialize" do
subject{ described_class.new(results).records }
context "when given an array" do
let(:results) { [1, 2, 3] }
it { is_expected.to eq([1, 2, 3]) }
end
context "when given an array of hashes" do
... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/params_spec.rb | Ruby | mit | 86 | master | 1,797 | require 'compendium/params'
describe Compendium::Params do
let(:options) {
opts = Collection[Compendium::Option]
opts << Compendium::Option.new(name: :starting_on, type: :date, default: ->{ Date.today })
opts << Compendium::Option.new(name: :ending_on, type: :date)
opts << Compendium::Option.new(name... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/presenters/base_spec.rb | Ruby | mit | 86 | master | 554 | require 'spec_helper'
require 'compendium/presenters/base'
TestPresenter = Class.new(Compendium::Presenters::Base) do
presents :test_obj
end
describe Compendium::Presenters::Base do
let(:template) { double("Template", delegated?: true) }
subject { TestPresenter.new(template, :test) }
it "should allow the obj... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/presenters/chart_spec.rb | Ruby | mit | 86 | master | 2,757 | require 'spec_helper'
require 'compendium/presenters/chart'
describe Compendium::Presenters::Chart do
let(:template) { double('Template', protect_against_forgery?: false, request_forgery_protection_token: :authenticity_token, form_authenticity_token: "ABCDEFGHIJ").as_null_object }
let(:query) { double('Query', nam... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/presenters/csv_spec.rb | Ruby | mit | 86 | master | 1,147 | require 'compendium/presenters/csv'
describe Compendium::Presenters::CSV do
let(:results) { double('Results', records: [{ group: 'A', one: 1, two: 2 }, { group: 'B', one: 3, two: 4 }], keys: [:group, :one, :two]) }
let(:query) { double('Query', results: results, options: {}, table_settings: nil) }
let(:presenter... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/presenters/option_spec.rb | Ruby | mit | 86 | master | 1,350 | require 'spec_helper'
require 'compendium/presenters/option'
require 'compendium/option'
describe Compendium::Presenters::Option do
let(:template) do
t = double('Template')
allow(t).to receive(:t) { |key| key } # Stub I18n.t to just return the given value
t
end
let(:option) { Compendium::Option.new(... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/presenters/table_spec.rb | Ruby | mit | 86 | master | 2,781 | require 'spec_helper'
require 'compendium/presenters/table'
describe Compendium::Presenters::Table do
let(:template) { double('Template') }
let(:results) { double('Results', records: [{ one: 1, two: 2 }, { one: 3, two: 4 }], keys: [:one, :two]) }
let(:query) { double('Query', results: results, options: {}, table... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/presenters/settings/table_spec.rb | Ruby | mit | 86 | master | 2,136 | require 'spec_helper'
require 'compendium/presenters/table'
describe Compendium::Presenters::Settings::Table do
let(:results) { double('Results', records: [{ one: 1, two: 2 }, { one: 3, two: 4 }], keys: [:one, :two]) }
let(:query) { double('Query', results: results, options: {}, table_settings: nil) }
let(:table... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | spec/presenters/settings/query_spec.rb | Ruby | mit | 86 | master | 538 | require 'spec_helper'
require 'compendium/presenters/settings/query'
describe Compendium::Presenters::Settings::Query do
subject { described_class.new }
describe '#update' do
before { subject.foo = :bar }
it 'should override previous settings' do
subject.update do |s|
s.foo :quux
end
... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | app/controllers/compendium/reports_controller.rb | Ruby | mit | 86 | master | 2,824 | module Compendium
class ReportsController < ::ApplicationController
helper Compendium::ReportsHelper
include Compendium::ReportsHelper
before_filter :find_report
before_filter :find_query
before_filter :validate_options, only: [:run, :export]
before_filter :run_report, only: [:run, :export]
... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | app/classes/compendium/presenters/csv.rb | Ruby | mit | 86 | master | 721 | require 'csv'
module Compendium::Presenters
class CSV < Table
def initialize(object, &block)
super(nil, object, &block)
end
def render
::CSV.generate do |csv|
csv << headings.map{ |_, val| formatted_heading(val) }
records.each do |row|
csv << row.map{ |key, val| fo... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | app/classes/compendium/presenters/table.rb | Ruby | mit | 86 | master | 2,511 | module Compendium::Presenters
class Table < Query
attr_reader :records, :totals, :settings
def initialize(*)
super
@records = results.records
@settings = settings_class.new(query)
@settings.set_headings(results.keys)
@settings.update(&query.table_settings) if query.table_setti... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | app/classes/compendium/presenters/query.rb | Ruby | mit | 86 | master | 516 | require 'compendium/presenters/base'
require 'compendium/presenters/settings/query'
require 'compendium/presenters/settings/table'
module Compendium::Presenters
class Query < Base
presents :query
def initialize(template, object)
super(template, object)
end
def render
raise NotImplemente... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | app/classes/compendium/presenters/metric.rb | Ruby | mit | 86 | master | 664 | module Compendium::Presenters
class Metric < Base
presents :metric
delegate :name, :query, :description, :ran?, to: :metric
def initialize(template, object, options = {})
super(template, object)
@options = options
end
def label
@options[:label] || t("#{query}.#{name}")
end... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | app/classes/compendium/presenters/option.rb | Ruby | mit | 86 | master | 3,119 | module Compendium::Presenters
class Option < Base
MISSING_CHOICES_ERROR = "choices must be specified"
presents :option
delegate :hidden?, to: :option
def name
t("options.#{option.name}", cascade: { offset: 2 })
end
def label(form)
if option.note?
key = option.note == tru... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | app/classes/compendium/presenters/base.rb | Ruby | mit | 86 | master | 578 | module Compendium::Presenters
class Base
def initialize(template, object)
@object = object
@template = template
end
def to_s
"#<#{self.class.name}:0x00#{'%x' % (object_id << 1)}>"
end
private
def self.presents(name)
define_method(name) do
@object
end
... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | app/classes/compendium/presenters/chart.rb | Ruby | mit | 86 | master | 2,481 | require 'compendium/presenters/query'
module Compendium::Presenters
class Chart < Query
attr_reader :data, :params, :container, :chart_provider
attr_accessor :options
def initialize(template, object, *args, &setup)
super(template, object)
self.options = args.extract_options!
type, con... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | app/classes/compendium/presenters/settings/table.rb | Ruby | mit | 86 | master | 1,153 | require 'compendium/presenters/settings/query'
module Compendium::Presenters::Settings
class Table < Query
attr_reader :headings
def initialize(*)
super
@headings = {}
# Set default values for settings
number_format '%0.2f'
table_class 'results'
header_cla... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | app/classes/compendium/presenters/settings/query.rb | Ruby | mit | 86 | master | 716 | module Compendium::Presenters::Settings
class Query
attr_reader :query
delegate :[], :fetch, to: :@settings
delegate :report, to: :query, allow_nil: true
def initialize(query = nil)
@settings = {}.with_indifferent_access
@query = query
end
def update(&block)
instance_exec(... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | app/helpers/compendium/reports_helper.rb | Ruby | mit | 86 | master | 682 | module Compendium
module ReportsHelper
private
def expose(*args)
klass = args.pop if args.last.is_a?(Class)
klass ||= "Compendium::Presenters::#{args.first.class}".constantize
presenter = klass.new(self, *(args.empty? ? [nil] : args))
yield presenter if block_given?
presenter
e... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium.rb | Ruby | mit | 86 | master | 2,021 | require 'compendium/engine'
require 'compendium/errors'
require 'compendium/version'
require 'active_support/configurable'
require 'active_support/core_ext'
module Compendium
autoload :AbstractChartProvider, 'compendium/abstract_chart_provider'
autoload :ChartProvider, 'compendium/abstract_chart_provider... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium/through_query.rb | Ruby | mit | 86 | master | 1,334 | require 'compendium/query'
module Compendium
class ThroughQuery < Query
attr_accessor :through
def initialize(*args)
@report = args.shift if arg_is_report?(args.first)
@through = args.slice!(1)
super(*args)
end
private
def collect_results(context, params)
results = collec... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium/params.rb | Ruby | mit | 86 | master | 1,105 | require 'compendium/open_hash'
require 'compendium/param_types'
require 'active_model'
module Compendium
class Params < OpenHash
include ActiveModel::Validations
attr_reader :options
def initialize(hash = {}, options = {})
@options = options
super(prepare_hash_from_options(hash))
end
... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium/collection_query.rb | Ruby | mit | 86 | master | 1,351 | require 'compendium/query'
module Compendium
# A CollectionQuery is a Query which runs once for each in a given set of criteria
class CollectionQuery < Query
attr_accessor :collection
def initialize(*)
super
self.collection = prepare_collection(@options[:collection])
end
def run(param... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium/result_set.rb | Ruby | mit | 86 | master | 811 | require 'active_support/core_ext/module/delegation'
module Compendium
class ResultSet
delegate :first, :last, :to_a, :empty?, :each, :map, :inject, :select, :detect, :[], :count, :length, :size, :==, to: :records
attr_reader :records
alias :all :records
def initialize(records)
@records = if r... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium/option.rb | Ruby | mit | 86 | master | 1,006 | require 'compendium/open_hash'
require 'active_support/string_inquirer'
module Compendium
class Option
attr_accessor :name, :type, :default, :choices, :options
delegate :boolean?, :date?, :dropdown?, :radio?, :scalar?, to: :type
delegate :merge, :merge!, :[], to: :@options
def initialize(hash = {})... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium/count_query.rb | Ruby | mit | 86 | master | 505 | require 'compendium/errors'
require 'compendium/query'
module Compendium
# A CountQuery is a Query which runs an SQL count statement
# Often useful in conjunction with a grouped query
class CountQuery < Query
def initialize(*args)
super
@options.reverse_merge!(order: 'COUNT(*)', reverse: true)
... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium/report.rb | Ruby | mit | 86 | master | 4,188 | require 'compendium/dsl'
module Compendium
class Report
attr_accessor :params, :results
extend Compendium::DSL
delegate :valid?, :errors, to: :params
delegate :report_name, :url, to: 'self.class'
class << self
delegate :validate, to: :params_class
def inherited(report)
Com... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium/sum_query.rb | Ruby | mit | 86 | master | 706 | require 'compendium/errors'
require 'compendium/query'
module Compendium
# A SumQuery is a Query which runs an SQL sum statement (with a given column)
# Often useful in conjunction with a grouped query and counter cache
# (alternately, see CountQuery)
class SumQuery < Query
attr_accessor :column
def ... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium/query.rb | Ruby | mit | 86 | master | 4,405 | require 'compendium/result_set'
require 'compendium/params'
require 'compendium/metric'
require 'compendium/presenters/chart'
require 'compendium/presenters/table'
require 'collection_of'
module Compendium
class Query
attr_reader :name, :results, :metrics, :filters
attr_accessor :options, :proc, :report, :ta... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium/abstract_chart_provider.rb | Ruby | mit | 86 | master | 1,312 | module Compendium
# Abstract wrapper for rendering charts
# To add a new chart provider, #initialize and #render must be implemented
# Custom providers should also override Compendium::AbstractChartProvider.find_chart_provider (but fallback to super)
module ChartProvider; end
class AbstractChartProvider
... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium/metric.rb | Ruby | mit | 86 | master | 775 | module Compendium
Metric = Struct.new(:name, :query, :command, :options) do
attr_accessor :result
def initialize(*)
super
self.options ||= {}
end
def run(ctx, data)
self.result = if condition_failed?(ctx)
nil
else
command.is_a?(Symbol) ? ctx.send(command, data... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium/open_hash.rb | Ruby | mit | 86 | master | 1,437 | require 'active_support/hash_with_indifferent_access'
module Compendium
class OpenHash < ::HashWithIndifferentAccess
class << self
def [](hash = {})
new(hash)
end
end
def dup
self.class.new(self)
end
protected
def convert_value(value)
if value.is_a? Hash
... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium/param_types.rb | Ruby | mit | 86 | master | 2,186 | require_relative '../../config/initializers/ruby/numeric'
require 'delegate'
module Compendium
class Param < ::SimpleDelegator
def scalar?; false; end
def boolean?; false; end
def date?; false; end
def dropdown?; false; end
def radio?; false; end
def ==(other)
return true if (value == ... |
github | dvandersluis/compendium | https://github.com/dvandersluis/compendium | lib/compendium/dsl.rb | Ruby | mit | 86 | master | 4,860 | require 'collection_of'
require 'inheritable_attr'
require 'compendium/option'
module Compendium
module DSL
def self.extended(klass)
klass.inheritable_attr :queries, default: ::Collection[Query]
klass.inheritable_attr :options, default: ::Collection[Option]
klass.inheritable_attr :exporters, de... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.