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 | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/6_pv_networks/miserables_data.rb | Ruby | bsd-2-clause | 241 | master | 20,219 | # This file contains the weighted network of coappearances of characters in
# Victor Hugo's novel "Les Miserables". Nodes represent characters as indicated
# by the labels, and edges connect any pair of characters that appear in the
# same chapter of the book. The values on the edges are the number of such
# coappearan... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/5_pv_hierarchies/circle_packing.rb | Ruby | bsd-2-clause | 241 | master | 1,618 | # = Circle Packing
# Enclosure diagrams are also space-filling, using containment rather than adjacency to represent the hierarchy. As with adjacency diagrams, the size of any node in the tree is quickly revealed. Although circle packing does not use space as efficiently as a treemap, the “wasted” space effectively rev... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/5_pv_hierarchies/node_link_tree.rb | Ruby | bsd-2-clause | 241 | master | 1,298 | # = Node-Link Trees
# The tree layout implements the Reingold-Tilford algorithm for efficient, tidy arrangement of layered nodes. This node-link diagram is similar to the dendrogram, except the depth of nodes is computed by distance from the root, leading to a ragged appearance. Cartesian orientations are also supporte... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/5_pv_hierarchies/bubble_charts_matrix.rb | Ruby | bsd-2-clause | 241 | master | 1,187 | # = Bubble charts matrix
#
# Why have one boring bubble chart when
# you can have 20 multicolor charts?
$:.unshift(File.dirname(__FILE__)+"/../../lib")
require 'rubyvis'
panes=20
cols=2
p_w=200
p_h=150
#p data
w = 20+p_w*cols
h = (panes/cols)*10+p_h*(panes/cols)
colors20=Rubyvis::Colors.category20()
c20=Rubyvis::... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/5_pv_hierarchies/indent.rb | Ruby | bsd-2-clause | 241 | master | 1,947 | # = Indented Tree
# Indented trees are widely-used to represent file systems, among other applications. Although indented trees require much vertical space and do not easily facilitate multiscale inference, they do allow efficient interactive exploration of the tree to find a specific node.
# In addition, the indent la... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/5_pv_hierarchies/icicle.rb | Ruby | bsd-2-clause | 241 | master | 1,329 | # = Icicle
# An icicle is simply a sunburst transformed from polar to cartesian coordinates. Here we show the various files on Rubyvis package; the color of each cell corresponds to the package, while the area encodes the size of the source code in bytes
# Uses Protovis API
$:.unshift(File.dirname(__FILE__)+"/../../li... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/5_pv_hierarchies/dendogram.rb | Ruby | bsd-2-clause | 241 | master | 1,279 | # = Dendogram
# A dendrogram (or cluster layout) is a node-link diagram that places leaf nodes of the tree at the same depth. In this example, the classes (orange leaf nodes) are aligned on the right edge, with the packages (blue internal nodes) to the left. As with other tree layouts, dendrograms can also be oriented ... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/5_pv_hierarchies/bubble_charts.rb | Ruby | bsd-2-clause | 241 | master | 2,042 | # = Bubble charts
# Bubble charts, such as those provided by "Many Eyes":http://manyeyes.alphaworks.ibm.com/manyeyes/page/Bubble_Chart.html, encode data in the area of circles. Although less perceptually accurate than bar charts, they can pack hundreds of values into a small space. A similar technique is the Dorling ca... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/5_pv_hierarchies/treemap.rb | Ruby | bsd-2-clause | 241 | master | 1,732 | # = Treemap
# Introduced by Ben Shneiderman in 1991, a treemap recursively subdivides area into rectangles. As with adjacency diagrams, the size of any node in the tree is quickly revealed. This example uses color to encode different packages of the rubyvis package, and area to encode file size. “Squarified” treemaps u... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/5_pv_hierarchies/sunburst.rb | Ruby | bsd-2-clause | 241 | master | 1,606 | # = Sunbursts
# A sunburst is an adjacency diagram: a space-filling variant of the node-link diagram. Rather than drawing a link between parent and child in the hierarchy, nodes are drawn as solid areas (either wedges or bars), and their placement relative to adjacent nodes reveals their position in the hierarchy. Beca... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/3_pv_conventional/grouped_charts.rb | Ruby | bsd-2-clause | 241 | master | 1,759 | # = Grouped charts
# In this multi-series bar chart, we group bars together rather than stack them. A grouped chart allows accurate comparison of individual values thanks to an aligned baseline: a position, rather than length, judgment is used.
# An ordinal scale positions the groups vertically; the bars are then repli... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/3_pv_conventional/bar_column_chart.rb | Ruby | bsd-2-clause | 241 | master | 1,566 | # = Bar & Column Charts
# This simple bar chart is constructed using a bar mark. A linear scale is used to compute the width of the bar, while an ordinal scale sets the top position and height for the categorical dimension. Next, rules and labels are added for reference values.
# Bars can be used in a variety of ways. ... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/3_pv_conventional/scatterplot.rb | Ruby | bsd-2-clause | 241 | master | 1,500 | # = Scatterplot
# Scatterplots can facilitate visual analysis along multiple dimensions, though care should be taken to avoid interference. In this example, we encode three dimensions: two are encoded using position, while the third is redundantly encoded as both area and color.
$:.unshift(File.dirname(__FILE__)+"/../... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/3_pv_conventional/line_and_step.rb | Ruby | bsd-2-clause | 241 | master | 1,665 | # = Line and Step Chart
# Line charts are often used to visualize time series data, encoding the value of a variable over time using position. Typically, linear interpolation is used between samples. However, in some cases, the data does not vary smoothly, but instead changes in response to discrete events.
# Using the... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/3_pv_conventional/stacked_charts.rb | Ruby | bsd-2-clause | 241 | master | 1,104 | # = Stacked Area
# This example uses the Stack layout to stack areas one over another.
$:.unshift(File.dirname(__FILE__)+"/../../lib")
require 'rubyvis'
data = pv.range(4).map {|i|
pv.range(0, 10, 0.1).map {|x|
OpenStruct.new({:x=> x, :y=> Math.sin(x) + rand() * 0.5 + 2})
}
}
w = 400
h = 200
x = pv.Scale.lin... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/3_pv_conventional/pie_and_donut.rb | Ruby | bsd-2-clause | 241 | master | 760 | $:.unshift(File.dirname(__FILE__)+"/../../lib")
require 'rubyvis'
# Sizing and scales. */
data = pv.range(10).map {rand()}
w = 400
h = 400
r = w / 2.0
a = pv.Scale.linear(0, pv.sum(data)).range(0, 2 * Math::PI)
#/* The root panel. */
vis = pv.Panel.new()
.width(w)
.height(h);
#/* The wedge, with centered... |
github | clbustos/rubyvis | https://github.com/clbustos/rubyvis | examples/3_pv_conventional/area.rb | Ruby | bsd-2-clause | 241 | master | 1,469 | # = Area Charts
# This simple area chart is constructed using an area mark, with an added line for emphasis on the top edge. Next, rules and labels are added for reference values.
# Although this example is basic, it provides a good starting point for adding more complex features. For instance, multiple series of data ... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | Rakefile | Ruby | mit | 240 | master | 400 | require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "appraisal"
# In Rails 6 this isn't required in the right order and worked by accident; fixed in rails@0f5e7a66143
require "logger"
require_relative File.join("lib", "pg_ha_migrations")
RSpec::Core::RakeTask.new(:spec)
if !ENV["APPRAISAL_INITIALIZED"]... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | Appraisals | Ruby | mit | 240 | master | 219 | 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 "rails-8.1" do
gem "rails", "~> 8.1.0"
end |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | pg_ha_migrations.gemspec | Ruby | mit | 240 | master | 1,583 | # coding: utf-8
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "pg_ha_migrations/version"
Gem::Specification.new do |spec|
spec.name = "pg_ha_migrations"
spec.version = PgHaMigrations::VERSION
spec.authors = %w{
celeen
cosgr... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | spec/test_helpers.rb | Ruby | mit | 240 | master | 3,677 | module TestHelpers
TableLock = Struct.new(:table, :lock_type, :granted, :pid)
def self.locks_for_table(table, connection:)
identifiers = table.to_s.split(".")
identifiers.prepend("public") if identifiers.size == 1
schema, table = identifiers
connection.structs_from_sql(TableLock, <<-SQL)
SE... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | spec/utility_methods_spec.rb | Ruby | mit | 240 | master | 12,222 | require "spec_helper"
RSpec.describe PgHaMigrations::SafeStatements, "utility methods" do
let(:migration_klass) { ActiveRecord::Migration::Current }
describe "#safe_set_maintenance_work_mem_gb" do
it "sets the maintenance work memory for building indexes" do
begin
migration = Class.new(migration... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | spec/lock_mode_spec.rb | Ruby | mit | 240 | master | 9,784 | require "spec_helper"
RSpec.describe PgHaMigrations::LockMode do
subject { described_class.new(mode) }
describe "when mode is access_share" do
let(:mode) { :access_share }
it "returns correct comparisons" do
aggregate_failures do
expect(subject).to eq(described_class.new(mode))
%i[... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | spec/safe_statements_spec.rb | Ruby | mit | 240 | master | 138,441 | require "spec_helper"
RSpec.describe PgHaMigrations::SafeStatements do
PgHaMigrations::AllowedVersions::ALLOWED_VERSIONS.each do |migration_klass|
describe migration_klass do
describe "#safe_create_table" do
# This test is also particularly helpful for exposing issues
# with inheritance fro... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | spec/blocking_database_transactions_reporter_spec.rb | Ruby | mit | 240 | master | 6,736 | require "spec_helper"
RSpec.describe PgHaMigrations::BlockingDatabaseTransactionsReporter do
describe "self.run" do
before(:each) do
@output = ""
allow(PgHaMigrations::BlockingDatabaseTransactionsReporter).to receive(:_puts) do |msg|
@output << msg
end
end
it "does not puts whe... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | spec/partman_renaming_spec.rb | Ruby | mit | 240 | master | 23,617 | require "spec_helper"
# Note: This test file is split out for speed purposes; partman renaming tests
# are slow, and we aren't often modifying those methods, so in local
# development, we can run this test separately from the rest of the safe
# statements tests.
RSpec.describe PgHaMigrations::UnsafeStatements, "partma... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | spec/spec_helper.rb | Ruby | mit | 240 | master | 2,358 | require "bundler/setup"
require "pg_ha_migrations"
require "db-query-matchers"
require "pry"
require "test_helpers"
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
# Disable RSpec exposing methods globally on `Modul... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | spec/dependent_object_checks_spec.rb | Ruby | mit | 240 | master | 6,856 | require "spec_helper"
RSpec.describe PgHaMigrations::UnsafeStatements do
PgHaMigrations::AllowedVersions::ALLOWED_VERSIONS.each do |migration_klass|
describe migration_klass do
describe "#dependent_objects_for_migration_method" do
it "doesn't return spurious matches for indexes" do
setup_... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | spec/migrations_class_versions_spec.rb | Ruby | mit | 240 | master | 3,505 | require "spec_helper"
RSpec.describe "migrations" do
PgHaMigrations::AllowedVersions::ALLOWED_VERSIONS.each do |migration_klass|
describe migration_klass do
let(:schema_migration) do
ActiveRecord::Base.connection.schema_migration if ActiveRecord::Base.connection.respond_to?(:schema_migration)
... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | spec/table_collection_spec.rb | Ruby | mit | 240 | master | 4,465 | require "spec_helper"
RSpec.describe PgHaMigrations::TableCollection do
let(:table_a) { PgHaMigrations::Table.new("a", "public") }
let(:table_b) { PgHaMigrations::Table.new("b", "public") }
let(:table_c) { PgHaMigrations::Table.new("c", "public", :exclusive) }
let(:table_d) { PgHaMigrations::Table.new("d", "pu... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | spec/pg_ha_migrations_spec.rb | Ruby | mit | 240 | master | 7,073 | require "spec_helper"
RSpec.describe PgHaMigrations do
it "has a version number" do
expect(PgHaMigrations::VERSION).not_to be nil
end
it "disables ddl transactions" do
expect(ActiveRecord::Migration.disable_ddl_transaction).to be_truthy
end
describe "config" do
after(:each) do
PgHaMigrati... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | spec/lock_acquisition_spec.rb | Ruby | mit | 240 | master | 35,280 | require "spec_helper"
# Note: This test file is split out for speed purposes; lock acquisition tests
# are slow, and we aren't often modifying those methods, so in local
# development, we can run this test separately from the rest of the safe
# statements tests.
RSpec.describe PgHaMigrations::SafeStatements, "lock acq... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | spec/unsafe_statements_spec.rb | Ruby | mit | 240 | master | 48,209 | require "spec_helper"
RSpec.describe PgHaMigrations::UnsafeStatements do
PgHaMigrations::AllowedVersions::ALLOWED_VERSIONS.each do |migration_klass|
describe migration_klass do
it "outputs the operation" do
original_stdout = $stdout
begin
$stdout = StringIO.new
migratio... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations.rb | Ruby | mit | 240 | master | 3,871 | require "pg_ha_migrations/version"
require "rails"
require "active_record"
require "active_record/migration"
require "active_record/connection_adapters/postgresql/utils"
require "active_support/core_ext/numeric/bytes"
require "relation_to_struct"
require "ruby2_keywords"
module PgHaMigrations
Config = Struct.new(
... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/extension.rb | Ruby | mit | 240 | master | 753 | module PgHaMigrations
class Extension
attr_reader :name, :schema, :version
def initialize(name)
@name = name
@schema, @version = ActiveRecord::Base.connection.select_rows(<<~SQL).first
SELECT nspname, extversion
FROM pg_namespace JOIN pg_extension
ON pg_namespace.oid = ... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/relation.rb | Ruby | mit | 240 | master | 7,614 | module PgHaMigrations
# This object represents a pointer to an actual relation in Postgres.
# The mode attribute is optional metadata which can represent a lock
# that has already been acquired or a potential lock that we are
# looking to acquire.
Relation = Struct.new(:name, :schema, :mode) do
def self.c... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/partman_rename_adapter.rb | Ruby | mit | 240 | master | 5,155 | module PgHaMigrations
class AbstractPartmanRenameAdapter
def initialize(part_config)
if part_config.datetime_string != source_datetime_string
raise PgHaMigrations::InvalidPartmanConfigError,
"Expected datetime_string to be #{source_datetime_string.inspect} " \
"but received #{par... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/partman_config.rb | Ruby | mit | 240 | master | 3,154 | # This is an internal class that is not meant to be used directly
class PgHaMigrations::PartmanConfig < ActiveRecord::Base
SUPPORTED_PARTITION_TYPES = %w[native range]
delegate :connection, to: :class
self.primary_key = :parent_table
def self.find(parent_table, partman_extension:)
unless partman_extensio... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/allowed_versions.rb | Ruby | mit | 240 | master | 800 | require "active_record/migration/compatibility"
module PgHaMigrations::AllowedVersions
ALLOWED_VERSIONS = [4.2, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, 7.1, 7.2, 8.0, 8.1].map do |v|
begin
ActiveRecord::Migration[v]
rescue ArgumentError
nil
end
end.compact
def inherited(subclass)
super
unl... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/dependent_objects_checks.rb | Ruby | mit | 240 | master | 2,604 | module PgHaMigrations::DependentObjectsChecks
ALLOWED_TYPES_OPTIONS = [:indexes].freeze
ObjectDependency = Struct.new(:owner_type, :owner_name, :dependent_type, :dependent_name) do
def error_text
"#{dependent_type} '#{dependent_name}' depends on #{owner_type} '#{owner_name}'"
end
end
def depende... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/constraint.rb | Ruby | mit | 240 | master | 344 | PgHaMigrations::CheckConstraint = Struct.new(:name, :definition, :validated) do
def initialize(name, definition, validated)
# pg_get_constraintdef includes NOT VALID in the definition,
# but we return that as a separate attribute.
definition = definition&.gsub(/ NOT VALID\Z/, "")
super(name, definitio... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/blocking_database_transactions.rb | Ruby | mit | 240 | master | 3,341 | module PgHaMigrations
class BlockingDatabaseTransactions
LongRunningTransaction = Struct.new(:database, :current_query, :state, :transaction_age, :tables_with_locks) do
def initialize(*args)
super
self.tables_with_locks = tables_with_locks.map { |args| Table.new(*args) }.select(&:present?)
... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/lock_mode.rb | Ruby | mit | 240 | master | 2,099 | module PgHaMigrations
class LockMode
include Comparable
MODE_CONFLICTS = ActiveSupport::OrderedHash.new
MODE_CONFLICTS[:access_share] = %i[
access_exclusive
]
MODE_CONFLICTS[:row_share] = %i[
exclusive
access_exclusive
]
MODE_CONFLICTS[:row_exclusive] = %i[
shar... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/unsafe_statements.rb | Ruby | mit | 240 | master | 14,921 | module PgHaMigrations::UnsafeStatements
def self.disable_or_delegate_default_method(method_name, error_message, allow_reentry_from_compatibility_module: false)
define_method(method_name) do |*args, &block|
if PgHaMigrations.config.disable_default_migration_methods
# Most migration methods are only e... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/safe_statements.rb | Ruby | mit | 240 | master | 33,451 | module PgHaMigrations::SafeStatements
def safe_added_columns_without_default_value
@safe_added_columns_without_default_value ||= []
end
def partman_extension
@partman_extension ||= PgHaMigrations::Extension.new("pg_partman")
end
def safe_create_table(table, **options, &block)
if options[:force]
... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/blocking_database_transactions_reporter.rb | Ruby | mit | 240 | master | 1,739 | require 'stringio'
module PgHaMigrations
class BlockingDatabaseTransactionsReporter
CHECK_DURATION = "30 seconds"
def self.run
blocking_transactions = get_blocking_transactions
has_transactions = blocking_transactions.values.flatten.present?
_puts(report(blocking_transactions)) if has_tran... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/hacks/disable_ddl_transaction.rb | Ruby | mit | 240 | master | 429 | require "active_record/migration"
module PgHaMigrations
module ActiveRecordHacks
module DisableDdlTransaction
def disable_ddl_transaction
# Default to disabled unless someone has set it elsewhere
defined?(@disable_ddl_transaction) ? @disable_ddl_transaction : true
end
end
end
en... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/hacks/cleanup_unnecessary_output.rb | Ruby | mit | 240 | master | 1,280 | require "active_record/migration/compatibility"
module PgHaMigrations
module ActiveRecordHacks
module CleanupUnnecessaryOutput
# This is fixed in Rails 6+, but previously there were several
# places where #adapter_name was called directly which implicitly
# delegated to the connection through #... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/pg_ha_migrations/hacks/add_index_on_only.rb | Ruby | mit | 240 | master | 952 | require "active_record/connection_adapters/postgresql_adapter"
require "active_record/connection_adapters/postgresql/schema_creation"
module PgHaMigrations
module ActiveRecordHacks
module IndexAlgorithms
def index_algorithms
super.merge(only: "ONLY")
end
end
module CreateIndexDefinit... |
github | braintree/pg_ha_migrations | https://github.com/braintree/pg_ha_migrations | lib/tasks/blocking_transactions.rake | Ruby | mit | 240 | master | 260 | require_relative File.join("..", "pg_ha_migrations")
namespace :pg_ha_migrations do
desc "Check if blocking database transactions exist"
task :check_blocking_database_transactions do
PgHaMigrations::BlockingDatabaseTransactionsReporter.run
end
end |
github | defunkt/cheat | https://github.com/defunkt/cheat | cheat.gemspec | Ruby | mit | 240 | master | 1,118 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'cheat/version'
Gem::Specification.new do |spec|
spec.add_dependency 'pager', '~> 1.0'
spec.add_development_dependency 'bundler', '~> 1.0'
spec.name = 'cheat'
spec.description ... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/cheat.rb | Ruby | mit | 240 | master | 6,412 | %w( tempfile fileutils net/http yaml open-uri cheat/wrap ).each { |f| require f }
require 'pager'
RUBY_PLATFORM = PLATFORM unless defined? RUBY_PLATFORM # Ruby 1.8 compatibility
def mswin?
(RUBY_PLATFORM =~ /(:?mswin|mingw)/) || (RUBY_PLATFORM == 'java' && (ENV['OS'] || ENV['os']) =~ /windows/i)
end
module Cheat
... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/Rakefile | Ruby | mit | 240 | master | 766 | require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test it!'
Rake::TestTask.new(:test) do |t|
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate RDoc documentation'
Rake::RDocTask.new(:rdoc) do |rdoc|
files = ['README', '... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/test/order_test.rb | Ruby | mit | 240 | master | 1,692 | require File.dirname(__FILE__) + '/helper'
context "Order" do
setup do
@sql = User.select { |m| m.name == 'jon' }
end
specify "simple order" do
string = @sql.sort_by { |m| m.name }.to_sql
string.should == "SELECT * FROM users WHERE users.`name` = 'jon' ORDER BY users.name"
end
specify "simple c... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/test/helper.rb | Ruby | mit | 240 | master | 831 | require 'rubygems'
require 'test/spec'
require 'mocha'
require 'redgreen'
require 'active_support'
require 'active_record'
$:.unshift File.dirname(__FILE__) + '/../lib'
require 'ambition'
class User
extend Ambition
def self.reflections
return @reflections if @reflections
@reflections = {}
@reflection... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/test/types_test.rb | Ruby | mit | 240 | master | 1,602 | require File.dirname(__FILE__) + '/helper'
##
# Once dynamically, once hardcoded
context "Different types" do
types_hash = {
'string' => "'string'",
:symbol => "'--- :symbol\n'",
1 => '1',
1.2 => '1.2',
nil => 'NULL',
true => '1',
false => '0',
Time.now =>... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/test/chaining_test.rb | Ruby | mit | 240 | master | 1,508 | require File.dirname(__FILE__) + '/helper'
context "Chaining" do
specify "should join selects with AND" do
sql = User.select { |m| m.name == 'jon' }
sql = sql.select { |m| m.age == 22 }
sql.to_sql.should == "SELECT * FROM users WHERE users.`name` = 'jon' AND users.`age` = 22"
end
specify "should joi... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/test/count_test.rb | Ruby | mit | 240 | master | 306 | require File.dirname(__FILE__) + '/helper'
context "Count" do
setup do
hash = { :conditions => "users.`name` = 'jon'" }
User.expects(:count).with(hash)
@sql = User.select { |m| m.name == 'jon' }
end
specify "size" do
@sql.size
end
specify "length" do
@sql.length
end
end |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/test/join_test.rb | Ruby | mit | 240 | master | 1,047 | require File.dirname(__FILE__) + '/helper'
context "Joins" do
specify "simple == on an association" do
sql = User.select { |m| m.account.email == 'chris@ozmm.org' }
sql.to_hash.should == {
:conditions => "accounts.email = 'chris@ozmm.org'",
:includes => [:account]
}
end
specify "simp... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/test/limit_test.rb | Ruby | mit | 240 | master | 1,027 | require File.dirname(__FILE__) + '/helper'
context "Limit" do
setup do
@sql = User.select { |m| m.name == 'jon' }
end
specify "first" do
conditions = { :conditions => "users.`name` = 'jon'", :limit => '1' }
User.expects(:find).with(:first, conditions)
@sql.first
end
specify "first with argu... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/test/where_test.rb | Ruby | mit | 240 | master | 4,509 | require File.dirname(__FILE__) + '/helper'
context "Where (using select)" do
specify "simple ==" do
sql = User.select { |m| m.name == 'jon' }.to_sql
sql.should == "SELECT * FROM users WHERE users.`name` = 'jon'"
end
specify "simple !=" do
sql = User.select { |m| m.name != 'jon' }.to_sql
sql.shou... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/test/enumerable_test.rb | Ruby | mit | 240 | master | 1,527 | require File.dirname(__FILE__) + '/helper'
context "Each" do
specify "simple ==" do
hash = { :conditions => "users.`age` = 21" }
User.expects(:find).with(:all, hash).returns([])
User.select { |m| m.age == 21 }.each do |user|
puts user.name
end
end
specify "limit and conditions" do
hash... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/lib/proc_to_ruby.rb | Ruby | mit | 240 | master | 835 | ##
# Taken from ruby2ruby, Copyright (c) 2006 Ryan Davis under the MIT License
require 'parse_tree'
require 'unique'
require 'sexp_processor'
class Method
def with_class_and_method_name
if self.inspect =~ /<Method: (.*)\#(.*)>/ then
klass = eval $1
method = $2.intern
raise "Couldn't determine ... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/lib/ambition.rb | Ruby | mit | 240 | master | 430 | require 'rubygems'
require 'proc_to_ruby'
require 'ambition/processor'
require 'ambition/query'
require 'ambition/where'
require 'ambition/order'
require 'ambition/limit'
require 'ambition/count'
require 'ambition/enumerable'
module Ambition
include Where, Order, Limit, Enumerable, Count
attr_accessor :query_con... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/lib/ambition/order.rb | Ruby | mit | 240 | master | 1,018 | module Ambition
module Order
def sort_by(&block)
query_context.add OrderProcessor.new(table_name, block)
end
end
class OrderProcessor < Processor
def initialize(table_name, block)
super()
@receiver = nil
@table_name = table_name
@block = block
@key ... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/lib/ambition/limit.rb | Ruby | mit | 240 | master | 654 | module Ambition
module Limit
def first(limit = 1, offset = nil)
query_context.add LimitProcessor.new(limit, offset)
find(limit == 1 ? :first : :all, query_context.to_hash)
end
def [](offset, limit = nil)
return first(offset, limit) if limit
if offset.is_a? Range
limit = ... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/lib/ambition/processor.rb | Ruby | mit | 240 | master | 1,185 | require 'active_record/connection_adapters/abstract/quoting'
module Ambition
class Processor < SexpProcessor
include ActiveRecord::ConnectionAdapters::Quoting
attr_reader :key, :join_string, :prefix
def initialize
super()
@strict = false
@expected = String
@auto... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/lib/ambition/where.rb | Ruby | mit | 240 | master | 3,547 | module Ambition
module Where
def select(*args, &block)
##
# XXX: AR::Base hack / workaround
if args.empty?
query_context.add WhereProcessor.new(self, block)
else
super
end
end
def detect(&block)
select(&block).first
end
end
class WhereProcessor... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/ambition/lib/ambition/query.rb | Ruby | mit | 240 | master | 1,879 | module Ambition
class Query
@@select = 'SELECT * FROM %s %s'
def initialize(owner)
@table_name = owner.table_name
@owner = owner
@clauses = []
end
def add(clause)
@clauses << clause
self
end
def query_context
self
end
def method_missing... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/cheat/diffr.rb | Ruby | mit | 240 | master | 1,288 | require 'diff/lcs'
require 'diff/lcs/hunk'
module Cheat
class Diffr
def self.diff(sheet_old, sheet_new)
format, lines, output = :unified, 10000, ''
file_length_difference = 0
data_old = sheet_old.body.wrap.split(/\n/).map! { |e| e.chomp }
data_new = sheet_new.body.wrap.split(/\n/).map! {... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/cheat/wrap.rb | Ruby | mit | 240 | master | 892 | # >> Evan Weaver
# => http://blog.evanweaver.com/articles/2006/09/03/smart-plaintext-wrapping
class String
def wrap(width = 80, hanging_indent = 0, magic_lists = false)
lines = self.split(/\n/)
lines.collect! do |line|
if magic_lists
line =~ /^([\s\-\d\.\:]*\s)/
else
line =~ /^([... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/cheat/version.rb | Ruby | mit | 240 | master | 431 | module Cheat
class Version
class << self
# @return [Integer]
def major
1
end
# @return [Integer]
def minor
3
end
# @return [Integer]
def patch
3
end
# @return [String, NilClass]
def pre
nil
end
# @re... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/cheat/site.rb | Ruby | mit | 240 | master | 18,650 | #
# According to Wikipedia, Cheat can refer to:
# Cheating, to take advantage of a situation by the breaking of accepted rules
# or standards
# Cheating (casino)
# Cheating in poker
# Cheating in online games
# In relationships, to have an affair
# A cheat code, a hidden means of gaining an advantage in... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/cheat/rv_harness.rb | Ruby | mit | 240 | master | 1,149 | # Example mongrel harness for camping apps with rv
#
# author: Evan Weaver
# url: http://blog.evanweaver.com/articles/2006/12/19/rv-a-tool-for-luxurious-camping
# license: AFL 3.0
require 'mongrel'
require 'mongrel/camping'
LOGFILE = 'mongrel.log'
PIDFILE = 'mongrel.pid'
# or whatever else you want passed in
PORT = A... |
github | defunkt/cheat | https://github.com/defunkt/cheat | lib/cheat/responder.rb | Ruby | mit | 240 | master | 1,063 | # class Something < R 'route'
# include Responder
#
# def get
# ... important code ...
#
# respond_to do |wants|
# wants.html { render :something }
# wants.text { "Just some text." }
# wants.yaml { "Something neat!".to_yaml }
# wants.xml { "Also, XML.".to_xml }
# end
# end
# en... |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | method_decorators.gemspec | Ruby | mit | 240 | master | 908 | # -*- encoding: utf-8 -*-
lib_dir = File.expand_path('lib', File.dirname(__FILE__))
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
require 'method_decorators/version'
Gem::Specification.new do |gem|
gem.authors = ["Michael Fairley"]
gem.email = ["michaelfairley@gmail.com"]
gem.desc... |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | lib/method_decorators.rb | Ruby | mit | 240 | master | 1,555 | require "method_decorators/version"
require "method_decorators/decorator"
module MethodDecorators
def method_added(name)
super
orig_method = instance_method(name)
decorators = Decorator.current_decorators
return if decorators.empty?
if private_method_defined?(name); visibility = :private
... |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | lib/method_decorators/memoize.rb | Ruby | mit | 240 | master | 516 | require "method_decorators"
module MethodDecorators
class Memoize < Decorator
def initialize
@memo_ivar = "@_memoize_cache#{rand(10**10)}"
end
def call(orig, this, *args, &blk)
return cache(this)[args] if cache(this).has_key?(args)
cache(this)[args] = orig.call(*args, &blk)
end
... |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | lib/method_decorators/precondition.rb | Ruby | mit | 240 | master | 415 | require "method_decorators"
module MethodDecorators
class Precondition < Decorator
def initialize(&blk)
@block = blk
end
def call(orig, this, *args, &blk)
unless passes?(this, *args)
raise ArgumentError, "failed precondition"
end
orig.call(*args, &blk)
end
private
... |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | lib/method_decorators/decorator.rb | Ruby | mit | 240 | master | 297 | module MethodDecorators
class Decorator
@@current_decorators = []
def self.current_decorators
decs = @@current_decorators
@@current_decorators = []
decs
end
def self.+@
+new
end
def +@
@@current_decorators.unshift(self)
end
end
end |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | lib/method_decorators/retry.rb | Ruby | mit | 240 | master | 527 | require "method_decorators"
module MethodDecorators
class Retry < Decorator
def initialize(max, options = {})
@max = max
@options = options
@exceptions = options[:exceptions] || [StandardError]
end
def call(orig, this, *args, &blk)
attempts = 0
begin
attempts += 1
... |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | lib/method_decorators/deprecated.rb | Ruby | mit | 240 | master | 2,691 | require 'method_decorators'
module MethodDecorators
# Example:
# class MyClass
# extend MethodDecorators
#
# +MethodDecorators::Deprecated
# def deprecated_method
# brand_new_method
# end
# end
# When deprecated_method is called, message
# "MyClass#deprecated_method is... |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | lib/method_decorators/within.rb | Ruby | mit | 240 | master | 374 | require "method_decorators"
require 'timeout'
module MethodDecorators
class Within < Decorator
def initialize(timeout, exception_class = nil)
@seconds = timeout
@exception_class = exception_class
end
def call(orig, this, *args, &blk)
Timeout.timeout(@seconds, @exception_class) do
... |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | spec/spec_helper.rb | Ruby | mit | 240 | master | 639 | require 'method_decorators'
require 'support/stringify'
require 'support/add_n'
require 'support/reverse'
class Base
extend MethodDecorators
end
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# Require this f... |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | spec/method_decorators_spec.rb | Ruby | mit | 240 | master | 4,485 | require 'spec_helper'
describe MethodDecorators do
subject { klass.new }
describe "decorating with a simple decorator" do
let(:klass) do
Class.new Base do
+Stringify
def three
3
end
end
end
it "works" do
subject.three.should == '3'
end
end
... |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | spec/decorators/retry_spec.rb | Ruby | mit | 240 | master | 2,586 | require 'spec_helper'
require 'method_decorators/retry'
describe MethodDecorators::Retry do
let(:method) { double(:method, :call => false) }
subject { MethodDecorators::Retry.new(3) }
describe "#call" do
it "executes the method again if the first time failed " do
method.stub(:call){ raise }
met... |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | spec/decorators/deprecated_spec.rb | Ruby | mit | 240 | master | 3,352 | require 'spec_helper'
require 'method_decorators/deprecated'
require 'stringio'
describe MethodDecorators::Deprecated do
let(:method) { double(:method, :call => 'return value of original method', :name => 'deprecated_method') }
describe '#call' do
subject { MethodDecorators::Deprecated.new }
it 'calls or... |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | spec/decorators/within_spec.rb | Ruby | mit | 240 | master | 1,944 | require 'spec_helper'
require 'method_decorators/within'
describe MethodDecorators::Within do
let(:method) { double(:method, :call => false) }
subject { MethodDecorators::Within.new(2) }
describe "#call" do
it "raises when the timeout seconds have elapsed" do
method.stub(:call){ sleep 3 }
expect... |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | spec/decorators/memoize_spec.rb | Ruby | mit | 240 | master | 2,160 | require 'spec_helper'
require 'method_decorators/memoize'
describe MethodDecorators::Memoize do
describe "#call" do
let(:method) { double(:method, :call => :calculation) }
let(:this) { Object.new }
subject { MethodDecorators::Memoize.new }
it "calculates the value the first time the arguments are su... |
github | michaelfairley/method_decorators | https://github.com/michaelfairley/method_decorators | spec/decorators/precondition_spec.rb | Ruby | mit | 240 | master | 1,721 | require 'spec_helper'
require 'method_decorators/precondition'
describe MethodDecorators::Precondition do
let(:receiver) { double(:receiver) }
let(:method) { double(:method, :call => :secret, :receiver => receiver) }
let(:block) { proc { |arg| true } }
subject { MethodDecorators::Precondition.new(&block) }
... |
github | nepalez/rspec-sqlimit | https://github.com/nepalez/rspec-sqlimit | rspec-sqlimit.gemspec | Ruby | mit | 240 | master | 645 | Gem::Specification.new do |gem|
gem.name = "rspec-sqlimit"
gem.version = "1.0.0"
gem.author = "Andrew Kozin (nepalez)"
gem.email = "andrew.kozin@gmail.com"
gem.homepage = "https://github.com/nepalez/rspec-sqlimit"
gem.summary = "RSpec matcher to control SQL queries made by block... |
github | nepalez/rspec-sqlimit | https://github.com/nepalez/rspec-sqlimit | Gemfile | Ruby | mit | 240 | master | 247 | source "https://rubygems.org"
gemspec
group :test do
gem "database_cleaner", ">= 1.5"
end
group :test, :development do
gem "debug" unless ENV["CI"] == "true"
gem "rails"
gem "rake", ">= 10"
gem "rubocop"
gem "sqlite3", ">= 1.3"
end |
github | nepalez/rspec-sqlimit | https://github.com/nepalez/rspec-sqlimit | Rakefile | Ruby | mit | 240 | master | 246 | require "bundler/setup"
Bundler::GemHelper.install_tasks
require "rspec/core/rake_task"
# Adds dummy:db tasks.
load "spec/dummy/Rakefile"
desc "Runs test suite."
task default: %w[db:reset db:schema:load] do
exec "bundle exec rspec spec"
end |
github | nepalez/rspec-sqlimit | https://github.com/nepalez/rspec-sqlimit | lib/rspec/sqlimit.rb | Ruby | mit | 240 | master | 1,166 | require "active_support/notifications"
require "active_record"
require "rspec"
module RSpec
module SQLimit
require_relative "sqlimit/counter"
require_relative "sqlimit/reporter"
end
Matchers.define :exceed_query_limit do |expected|
chain :with do |matcher|
@matcher = matcher
end
match... |
github | nepalez/rspec-sqlimit | https://github.com/nepalez/rspec-sqlimit | lib/rspec/sqlimit/reporter.rb | Ruby | mit | 240 | master | 866 | module RSpec::SQLimit
class Reporter
attr_reader :matcher
def initialize(counter)
@counter = counter
@count = counter.count
@queries = counter.queries
@matcher = counter.matcher
end
def call
suffix = " among others (see mark ->)" if @matcher
return "No queries w... |
github | nepalez/rspec-sqlimit | https://github.com/nepalez/rspec-sqlimit | lib/rspec/sqlimit/counter.rb | Ruby | mit | 240 | master | 1,218 | module RSpec::SQLimit
class Counter
attr_reader :queries, :matcher
def self.[](*args)
new(*args).tap(&:call)
end
def initialize(matcher, block)
@queries = []
@matcher = matcher
@block = block
@mutex = Mutex.new
end
def call
@mutex.synchronize do
... |
github | nepalez/rspec-sqlimit | https://github.com/nepalez/rspec-sqlimit | spec/spec_helper.rb | Ruby | mit | 240 | master | 429 | require "debug" unless ENV["CI"] == "true"
require "rspec-sqlimit"
require "database_cleaner"
require_relative "dummy/config/environment"
DatabaseCleaner.strategy = :truncation
RSpec.configure do |config|
config.order = :random
config.filter_run focus: true
config.run_all_when_everything_filtered = true
# P... |
github | nepalez/rspec-sqlimit | https://github.com/nepalez/rspec-sqlimit | spec/rspec/sqlimit_spec.rb | Ruby | mit | 240 | master | 1,496 | require "spec_helper"
describe "exceed_query_limit" do
context "without restrictions" do
it "works when no queries are made" do
expect { User.new }.not_to exceed_query_limit(0)
end
it "works when nil is used as a parameter" do
expect { User.create id: nil }.to exceed_query_limit(0)
end
... |
github | nepalez/rspec-sqlimit | https://github.com/nepalez/rspec-sqlimit | spec/rspec/sqlimit/reporter_spec.rb | Ruby | mit | 240 | master | 2,165 | require "spec_helper"
describe RSpec::SQLimit::Reporter do
subject { described_class.new(counter) }
context "no params were passed to the query" do
let(:counter) { RSpec::SQLimit::Counter[/CREATE/, proc{ User.create }] }
it "doesn't print binds" do
# INSERT INTO "users" DEFAULT VALUES (0.284 ms)
... |
github | nepalez/rspec-sqlimit | https://github.com/nepalez/rspec-sqlimit | spec/dummy/config/application.rb | Ruby | mit | 240 | master | 227 | require "active_record/railtie"
module Dummy
class Application < Rails::Application
config.api_only = true
config.eager_load = false
config.enable_reloading = false
config.cache_store = :null_store
end
end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.