Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

(Re)?move some files and fix RDoc clean tasks

Move stats.rb file from both sequel/extra and sequel_core/extra
subdirectories, place in the extra directory in the root of the
repository.

Move the stress tests from sequel_core/stress to extra/stress.

Remove the postgres_perf.rb stress test.

Remove the TODO files, since I don't plan on implementing the
suggestions therein.

Remove the autotest files.

Remove the sequel_core/examples files.

Make the clean tests delete the temporary directories created,
such as pkg, rdoc, and coverage.
  • Loading branch information...
commit c988cc8abec6a44744defeca99ac566322d99686 1 parent fb59da9
@jeremyevans authored
View
9 Rakefile
@@ -7,6 +7,7 @@ require "fileutils"
include FileUtils
PROJECTS = %w{sequel_core sequel}
+CLEAN.include ["rdoc", "coverage"]
def with_each_project
PROJECTS.each do |p|
@@ -51,6 +52,12 @@ task :release do
sh_with_each_project "rake release"
end
+task :clean => [:clean_subdirs]
+desc "Clean files from both subdirectories"
+task :clean_subdirs do
+ sh_with_each_project "rake clean"
+end
+
##############################################################################
# rspec
##############################################################################
@@ -119,7 +126,7 @@ STATS_DIRECTORIES = [
desc "Report code statistics (KLOCs, etc) from the application"
task :stats do
- require "sequel_core/extra/stats"
+ require "extra/stats"
verbose = true
CodeStatistics.new(*STATS_DIRECTORIES).to_s
end
View
0  sequel_core/extra/stats.rb → extra/stats.rb
File renamed without changes
View
2  sequel_core/stress/access_perf.rb → extra/stress/access_perf.rb
@@ -1,6 +1,6 @@
require 'benchmark'
require 'rubygems'
-require File.join(File.dirname(__FILE__), '../lib/sequel_core/adapters/sqlite')
+require 'sequel'
DB = Sequel.sqlite
View
2  sequel_core/stress/dataset_perf.rb → extra/stress/dataset_perf.rb
@@ -1,6 +1,6 @@
require 'benchmark'
require 'rubygems'
-require File.join(File.dirname(__FILE__), '../lib/sequel_core/adapters/sqlite')
+require 'sequel'
DB = Sequel.sqlite
View
30 extra/stress/filter_perf.rb
@@ -0,0 +1,30 @@
+require 'benchmark'
+require 'rubygems'
+require 'sequel'
+
+DB = Sequel.sqlite
+DS = DB[:t]
+
+N = 10_000
+
+Benchmark::bm(6) do |x|
+ x.report('hash') do
+ N.times {DS.filter(:x => 100, :y => 200).sql}
+ end
+
+ x.report('param') do
+ N.times {DS.filter('(x = ?) AND (y = ?)', 200).sql}
+ end
+
+ x.report('string') do
+ N.times {DS.filter('(x = 100) AND (y = 200)').sql}
+ end
+
+ x.report('proc') do
+ N.times {DS.filter {:x == 100 && :y == 200}.sql}
+ end
+
+ x.report('blockless') do
+ N.times {DS.filter((:x > 100) & (:y < 200)).sql}
+ end
+end
View
2  sequel_core/stress/proc_filter.rb → extra/stress/proc_filter.rb
@@ -1,5 +1,5 @@
require 'rubygems'
-require File.join(File.dirname(__FILE__), '../lib/sequel_core/adapters/sqlite')
+require 'sequel'
DB = Sequel.sqlite
DS = DB[:t]
View
4 sequel/Rakefile
@@ -11,7 +11,7 @@ include FileUtils
NAME = "sequel"
VERS = "1.5.1"
SEQUEL_CORE_VERS= "1.5.1"
-CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "rdoc/*", "coverage/*"]
+CLEAN.include ["**/.*.sw?", "pkg", ".config", "rdoc", "coverage"]
RDOC_OPTS = ["--quiet", "--line-numbers", "--inline-source", '--title', \
'Sequel: The Database Toolkit for Ruby: Model Classes', '--main', 'README']
@@ -124,7 +124,7 @@ STATS_DIRECTORIES = [
desc "Report code statistics (KLOCs, etc) from the application"
task :stats do
- require "extra/stats"
+ require "../extra/stats"
verbose = true
CodeStatistics.new(*STATS_DIRECTORIES).to_s
end
View
9 sequel/TODO
@@ -1,9 +0,0 @@
-* Observer pattern:
-
- class MyObserver < Sequel::Observer
- observe Item, Post
-
- def after_save
- ...
- end
- end
View
3  sequel/autotest/discover.rb
@@ -1,3 +0,0 @@
-Autotest.add_discovery do
- "sequel"
-end
View
103 sequel/autotest/rspec_sequel.rb
@@ -1,103 +0,0 @@
-require "autotest"
-
-class RspecCommandError < StandardError; end
-
-class Autotest::RspecSequel < Autotest
-
- def initialize(kernel=Kernel, separator=File::SEPARATOR, alt_separator=File::ALT_SEPARATOR) # :nodoc:
- super()
- @kernel, @separator, @alt_separator = kernel, separator, alt_separator
- @spec_command = spec_command
-
- # watch out: Ruby bug (1.8.6):
- # %r(/) != /\//
- # since Ruby compares the REGEXP source, not the resulting pattern
- @test_mappings = {
- %r%^spec/.*_spec\.rb$% => kernel.proc { |filename, _| filename },
- %r%^lib/sequel_core/(.*)\.rb$% => kernel.proc do |_, m|
- [
- "spec/#{m[1]}_spec.rb",
- "spec/sequel/#{m[1]}_spec.rb"
- ]
- end,
- %r%^lib/sequel_model/(.*)\.rb$% => kernel.proc do |_, m|
- [
- "spec/model/#{m[1]}_spec.rb"#,
- #"spec/sequel/#{m[1]}_spec.rb",
- #"spec/sequel/#{m[1]}_mixin_spec.rb"
- ]
- end,
- %r%^lib/sequel\.rb$% => kernel.proc { files_matching %r%^spec/.*_spec\.rb$% },
- %r%^spec/(spec_helper|shared/.*)\.rb$% => kernel.proc { files_matching %r%^spec/.*_spec\.rb$% }
- }
- end
-
- def tests_for_file(filename)
- super.select { |f| @files.has_key? f }
- end
-
- alias :specs_for_file :tests_for_file
-
- def failed_results(results)
- results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
- end
-
- def handle_results(results)
- @files_to_test = consolidate_failures failed_results(results)
- unless @files_to_test.empty? then
- hook :red
- else
- hook :green
- end unless $TESTING
- @tainted = true unless @files_to_test.empty?
- end
-
- def consolidate_failures(failed)
- filters = Hash.new { |h,k| h[k] = [] }
- failed.each do |spec, failed_trace|
- @files.keys.select{|f| f =~ /spec\//}.each do |f|
- if failed_trace =~ Regexp.new(f)
- filters[f] << spec
- break
- end
- end
- end
- return filters
- end
-
- def make_test_cmd(files_to_test)
- return "#{ruby} -S #{@spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
- end
-
- def add_options_if_present
- File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
- end
-
- # Finds the proper spec command to use. Precendence
- # is set in the lazily-evaluated method spec_commands. Alias + Override
- # that in ~/.autotest to provide a different spec command
- # then the default paths provided.
- def spec_command
- spec_commands.each do |command|
- if File.exists?(command)
- return @alt_separator ? (command.gsub @separator, @alt_separator) : command
- end
- end
-
- raise RspecCommandError, "No spec command could be found!"
- end
-
- # Autotest will look for spec commands in the following
- # locations, in this order:
- #
- # * bin/spec
- # * default spec bin/loader installed in Rubygems
- def spec_commands
- [
- File.join("bin", "spec"),
- File.join("usr","bin","spec"),
- File.join(Config::CONFIG["bindir"], "spec")
- ]
- end
-
-end
View
101 sequel/extra/stats.rb
@@ -1,101 +0,0 @@
-# Unashamedly appropriated from Rails
-
-class CodeStatistics
- def initialize(*pairs)
- @pairs = pairs
- @statistics = calculate_statistics
- @total = calculate_total if pairs.length > 1
- end
-
- def to_s
- print_header
- @statistics.each{ |k, v| print_line(k, v) }
- print_splitter
-
- if @total
- print_line('Total', @total)
- print_splitter
- print_code_to_test
- end
- end
-
- private
- def calculate_statistics
- @pairs.inject({}) do |stats, pair|
- stats[pair.first] = calculate_directory_statistics(pair.last); stats
- end
- end
-
- def get_file_statistics(fn, stats)
- f = File.open(fn)
- while line = f.gets
- stats[:lines] += 1
- stats[:classes] += 1 if line =~ /class [A-Z]/ || line =~ /context/
- stats[:methods] += 1 if line =~ /def [a-z]/ || line =~ /specify/
- stats[:codelines] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
- end
- end
-
- def get_directory_statistics(dir, stats)
- Dir.foreach(dir) do |fn|
- next if fn =~ /^\./
- fn = File.join(dir, fn)
- if File.directory?(fn)
- get_directory_statistics fn, stats
- else
- next unless fn =~ /.*rb/
- get_file_statistics fn, stats
- end
- end
- stats
- end
-
- def calculate_directory_statistics(directory, pattern = /.*rb/)
- stats = { :lines => 0, :codelines => 0, :classes => 0, :methods => 0 }
- get_directory_statistics directory, stats
- stats
- end
-
- def calculate_total
- total = { :lines => 0, :codelines => 0, :classes => 0, :methods => 0 }
- @statistics.each_value { |pair| pair.each { |k, v| total[k] += v } }
- total
- end
-
- def print_header
- print_splitter
- puts '| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |'
- print_splitter
- end
-
- def print_splitter
- puts '+---------------+-------+-------+---------+---------+-----+-------+'
- end
-
- def print_line(name, statistics)
- m_over_c = (statistics[:methods] / statistics[:classes]) rescue m_over_c = 0
- loc_over_m = (statistics[:codelines] / statistics[:methods]) - 2 rescue loc_over_m = 0
-
- puts "| #{name.ljust(13)} " +
- "| #{statistics[:lines].to_s.rjust(5)} " +
- "| #{statistics[:codelines].to_s.rjust(5)} " +
- "| #{statistics[:classes].to_s.rjust(7)} " +
- "| #{statistics[:methods].to_s.rjust(7)} " +
- "| #{m_over_c.to_s.rjust(3)} " +
- "| #{loc_over_m.to_s.rjust(5)} |"
- end
-
- def print_code_to_test
- c_loc = 0
- t_loc = 0
- @statistics.each do |n, s|
- if n =~ /spec/i
- t_loc += s[:codelines]
- else
- c_loc += s[:codelines]
- end
- end
- ratio = (((t_loc.to_f / c_loc)*10).round.to_f/10).to_s[0,4]
- puts " Code LOC: #{c_loc} Spec LOC: #{t_loc} Code to Spec Ratio: 1:#{ratio}"
- end
-end
View
4 sequel_core/Rakefile
@@ -10,7 +10,7 @@ include FileUtils
##############################################################################
NAME = "sequel_core"
VERS = "1.5.1"
-CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "rdoc/*", "coverage/*"]
+CLEAN.include ["**/.*.sw?", "pkg", ".config", "rdoc", "coverage"]
RDOC_OPTS = ["--quiet", "--line-numbers", "--inline-source", '--title', \
'Sequel: The Database Toolkit for Ruby: Core Library and Adapters', \
'--main', 'README']
@@ -151,7 +151,7 @@ STATS_DIRECTORIES = [
desc "Report code statistics (KLOCs, etc) from the application"
task :stats do
- require "extra/stats"
+ require "../extra/stats"
verbose = true
CodeStatistics.new(*STATS_DIRECTORIES).to_s
end
View
30 sequel_core/TODO
@@ -1,30 +0,0 @@
-* unit of work
-
-* option echo for Database.new, adds a logger to STDOUT
-
-
-
-
-* Database introspection. schema extraction and database dumping and copying.
-
-* Add Dataset#update_or_create:
-
- DB[:items].filter(:name => 'abc').update_or_create(:price => 100)
-
- # equivalent to:
-
- if (DB[:items].filter(:name => 'abc').update(:price => 100) < 1)
- DB[:items] << {:name => 'abc', :price => 100}
-
- MySQL also supports a REPLACE INTO syntax which does the same:
-
- REPLACE INTO items SET price = 100 WHERE name = 'abc'
-
-* Adapters:
-
- frontbase, interbase (http://ruby-dbi.rubyforge.org/)
- openbase (http://ruby-openbase.rubyforge.org)
-
-* Sharding
-
-* Generating an object graph from a result-set.
View
3  sequel_core/autotest/discover.rb
@@ -1,3 +0,0 @@
-Autotest.add_discovery do
- "sequel"
-end
View
103 sequel_core/autotest/rspec_sequel.rb
@@ -1,103 +0,0 @@
-require "autotest"
-
-class RspecCommandError < StandardError; end
-
-class Autotest::RspecSequel < Autotest
-
- def initialize(kernel=Kernel, separator=File::SEPARATOR, alt_separator=File::ALT_SEPARATOR) # :nodoc:
- super()
- @kernel, @separator, @alt_separator = kernel, separator, alt_separator
- @spec_command = spec_command
-
- # watch out: Ruby bug (1.8.6):
- # %r(/) != /\//
- # since Ruby compares the REGEXP source, not the resulting pattern
- @test_mappings = {
- %r%^spec/.*_spec\.rb$% => kernel.proc { |filename, _| filename },
- %r%^lib/sequel/(.*)\.rb$% => kernel.proc do |_, m|
- [
- "spec/#{m[1]}_spec.rb",
- "spec/sequel/#{m[1]}_spec.rb"
- ]
- end,
- %r%^lib/sequel/model/(.*)\.rb$% => kernel.proc do |_, m|
- [
- "spec/model/#{m[1]}_spec.rb"#,
- #"spec/sequel/#{m[1]}_spec.rb",
- #"spec/sequel/#{m[1]}_mixin_spec.rb"
- ]
- end,
- %r%^lib/sequel\.rb$% => kernel.proc { files_matching %r%^spec/.*_spec\.rb$% },
- %r%^spec/(spec_helper|shared/.*)\.rb$% => kernel.proc { files_matching %r%^spec/.*_spec\.rb$% }
- }
- end
-
- def tests_for_file(filename)
- super.select { |f| @files.has_key? f }
- end
-
- alias :specs_for_file :tests_for_file
-
- def failed_results(results)
- results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
- end
-
- def handle_results(results)
- @files_to_test = consolidate_failures failed_results(results)
- unless @files_to_test.empty? then
- hook :red
- else
- hook :green
- end unless $TESTING
- @tainted = true unless @files_to_test.empty?
- end
-
- def consolidate_failures(failed)
- filters = Hash.new { |h,k| h[k] = [] }
- failed.each do |spec, failed_trace|
- @files.keys.select{|f| f =~ /spec\//}.each do |f|
- if failed_trace =~ Regexp.new(f)
- filters[f] << spec
- break
- end
- end
- end
- return filters
- end
-
- def make_test_cmd(files_to_test)
- return "#{ruby} -S #{@spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
- end
-
- def add_options_if_present
- File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
- end
-
- # Finds the proper spec command to use. Precendence
- # is set in the lazily-evaluated method spec_commands. Alias + Override
- # that in ~/.autotest to provide a different spec command
- # then the default paths provided.
- def spec_command
- spec_commands.each do |command|
- if File.exists?(command)
- return @alt_separator ? (command.gsub @separator, @alt_separator) : command
- end
- end
-
- raise RspecCommandError, "No spec command could be found!"
- end
-
- # Autotest will look for spec commands in the following
- # locations, in this order:
- #
- # * bin/spec
- # * default spec bin/loader installed in Rubygems
- def spec_commands
- [
- File.join("bin", "spec"),
- File.join("usr","bin","spec"),
- File.join(Config::CONFIG["bindir"], "spec")
- ]
- end
-
-end
View
30 sequel_core/examples/basic.rb
@@ -1,30 +0,0 @@
-require 'rubygems'
-require 'sequel/sqlite'
-
-# Let's open an in-memory database
-DB = Sequel.open 'sqlite:/'
-
-# Create a new table
-DB.create_table :items do
- primary_key :id, :integer, :auto_increment => true
- column :name, :text
- column :price, :float
-end
-
-# Create a dataset
-items = DB[:items]
-
-# Populate the table
-items << {:name => 'abc', :price => rand * 100}
-items << {:name => 'def', :price => rand * 100}
-items << {:name => 'ghi', :price => rand * 100}
-
-# Print out the number of records
-puts "Item count: #{items.count}"
-
-# Print out the records
-items.print(:name, :price)
-
-# Print out the average price
-puts "The average price is: #{items.avg(:price)}"
-
View
23 sequel_core/examples/countries.rb
@@ -1,23 +0,0 @@
-require 'sequel/sqlite'
-
-DB = Sequel.open 'sqlite:///countries.db'
-countries = DB[:countries]
-
-# select name, region and popuplation
-countries.select(:name, :region, :population).all
-
-# show the name for the countries that have a population of
-# at least 200 million.
-large_populations = countries.filter {population >= 200_000_000}
-large_populations.map(:name)
-
-# Give the name and the per capita GDP for those countries
-# with a population of at least 200 million.
-large_populations.hash_map(:name, :gdp)
-
-# Show the name and population in millions for the countries of Asia
-countries.filter(:region => 'Asia').select(:name, 'population/1000000').all
-
-# Show the name and population for France, Germany, Italy
-countries.filter(:name => ['France', 'Germany', 'Italy']).hash_map(:name, :population)
-
View
16 sequel_core/examples/csv.rb
@@ -1,16 +0,0 @@
-require 'rubygems'
-require 'faster_csv'
-require File.join(File.dirname(__FILE__), '../lib/sequel_core')
-
-DB = Sequel.open 'sqlite:///test.db'
-DB.create_table :countries do
- column :name, :text
- column :population, :integer
-end unless DB.table_exists?(:countries)
-
-FCSV.foreach('/home/sharon/reality/server/trunk/test.csv',
- :headers => true, :header_converters => :symbol) do |l|
- DB[:countries] << l.to_hash
-end
-
-DB[:countries].print(:name, :population)
View
30 sequel_core/examples/filters.rb
@@ -1,30 +0,0 @@
-require 'rubygems'
-require 'sequel/sqlite' # gem install sequel (and sqlite3 as well)
-
-DB = Sequel.open 'sqlite:/' # memory DB
-
-DB.create_table :items do
- text :name
- decimal :price
-end
-
-items = DB[:items]
-
-1000.times {|i| items << {:name => "item#{i}", :price => rand * 100}}
-
-puts "#{items.count} total items"
-
-puts "Average price: #{items.avg(:price)}"
-
-puts "3 most expensive items:"
-items.order(:price.DESC).limit(3).print(:name, :price)
-
-puts "#{items.filter {price < items.avg(:price)}.count} below the average"
-#{}
-
-puts "Changing price for expensive items"
-items.filter {price > items.avg(:price)}.update(:price => 'price + 10'.expr)
-
-puts "Highest price: #{items.max(:price)}"
-
-puts "Updated average price: #{items.avg(:price)}"
View
40 sequel_core/examples/view.rb
@@ -1,40 +0,0 @@
-require 'rubygems'
-require File.join(File.dirname(__FILE__), '../lib/sequel_core')
-
-db = Sequel.open("sqlite:/:memory:")
-db << "create table k1 (id integer primary key autoincrement, f1 text)"
-db << "create table k2 (id integer primary key autoincrement, f2 text)"
-db << "create table k3 (id integer primary key autoincrement, f3 text)"
-db << "create table records (id integer primary key autoincrement,
- k1_id integer, k2_id integer, k3_id integer, value text)"
-db << "create unique index records_key_unique on records(k1_id,k2_id,k3_id)"
-db << "create view data as select records.id as id, k1.f1 as f1, k2.f2 as f2,
- k3.f3 as f3, records.value as value
- from records inner join k1 on records.k1_id = k1.id
- inner join k2 on records.k2_id = k2.id
- inner join k3 on records.k3_id = k3.id
- order by k1.f1, k2.f2, k3.f3"
-k1 = db[:k1]
-k1 << [1, 'Alfred']
-k1 << [2,'Barry']
-k1 << [3, 'Charles']
-k1 << [4,'Dave']
-k1 << [5,'Douglas']
-k2 = db[:k2]
-k2 << [1,'USA']
-k2 << [2,'Japan']
-k2 << [3,'Brazil']
-k3 = db[:k3]
-k3 << [1,'APL']
-k3 << [2,'BASIC']
-k3 << [3,'COBOL']
-k3 << [4,'Ruby']
-records = db[:records]
-records << [1,1,1,1,'Red']
-records << [2,2,2,2,'Yellow']
-records << [3,3,3,3,'Green']
-records << [4,4,1,4,'Magenta']
-records << [5,5,2,4,'Blue']
-data = db[:data].filter(:f1 => ['Dave','Douglas'])
-puts data.sql
-data.print(:id, :f1, :f2, :f3, :value)
View
26 sequel_core/stress/filter_perf.rb
@@ -1,26 +0,0 @@
- require 'benchmark'
- require 'rubygems'
- require File.join(File.dirname(__FILE__), '../lib/sequel_core/adapters/sqlite')
-
- DB = Sequel.sqlite
- DS = DB[:t]
-
- N = 10_000
-
- Benchmark::bm(6) do |x|
- x.report('hash') do
- N.times {DS.filter(:x => 100, :y => 200).sql}
- end
-
- x.report('param') do
- N.times {DS.filter('(x = ?) AND (y = ?)', 200).sql}
- end
-
- x.report('string') do
- N.times {DS.filter('(x = 100) AND (y = 200)').sql}
- end
-
- x.report('proc') do
- N.times {DS.filter {:x == 100 && :y == 200}.sql}
- end
- end
View
16 sequel_core/stress/postgres_perf.rb
@@ -1,16 +0,0 @@
-require 'benchmark'
-require 'rubygems'
-# require 'fastthread'
-require File.join(File.dirname(__FILE__), '../lib/sequel_core/adapters/postgres')
-
-DB = Sequel('postgres://postgres:postgres@localhost:5432/reality_development')
-
-N = 100
-
-Benchmark::bmbm(20) do |x|
- x.report('postgres read') do
- N.times do
- DB[:timeline].each {|t| [t[:stamp], t[:kind], t[:node_id]]}
- end
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.