adapter_extensions 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,2 @@
1
+ 0.1.0 - March 5, 2007
2
+ * Initial release
data/LICENSE ADDED
@@ -0,0 +1,16 @@
1
+ Copyright (c) 2007 Anthony Eden
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
4
+ associated documentation files (the "Software"), to deal in the Software without restriction, including
5
+ without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6
+ copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
7
+ following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial
10
+ portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
13
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
14
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
16
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1 @@
1
+ This library provides extensions to Rails' ActiveRecord adapters.
data/Rakefile ADDED
@@ -0,0 +1,126 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/packagetask'
5
+ require 'rake/gempackagetask'
6
+ require 'rake/contrib/rubyforgepublisher'
7
+
8
+ require File.join(File.dirname(__FILE__), 'lib/adapter_extensions', 'version')
9
+
10
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
11
+ PKG_NAME = 'adapter_extensions'
12
+ PKG_VERSION = AdapterExtensions::VERSION::STRING + PKG_BUILD
13
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
14
+ PKG_DESTINATION = ENV["PKG_DESTINATION"] || "../#{PKG_NAME}"
15
+
16
+ RELEASE_NAME = "REL #{PKG_VERSION}"
17
+
18
+ RUBY_FORGE_PROJECT = "activewarehouse"
19
+ RUBY_FORGE_USER = "aeden"
20
+
21
+ desc 'Default: run unit tests.'
22
+ task :default => :test
23
+
24
+ desc 'Test the ETL application.'
25
+ Rake::TestTask.new(:test) do |t|
26
+ t.libs << 'lib'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = true
29
+ # TODO: reset the database
30
+ end
31
+
32
+ desc 'Generate documentation for the AdapterExtensions library.'
33
+ Rake::RDocTask.new(:rdoc) do |rdoc|
34
+ rdoc.rdoc_dir = 'rdoc'
35
+ rdoc.title = 'Extensions for Rails adapters'
36
+ rdoc.options << '--line-numbers' << '--inline-source'
37
+ rdoc.rdoc_files.include('README')
38
+ rdoc.rdoc_files.include('lib/**/*.rb')
39
+ end
40
+
41
+ PKG_FILES = FileList[
42
+ 'CHANGELOG',
43
+ 'README',
44
+ 'LICENSE',
45
+ 'Rakefile',
46
+ 'doc/**/*',
47
+ 'lib/**/*',
48
+ ] - [ 'test' ]
49
+
50
+ spec = Gem::Specification.new do |s|
51
+ s.name = 'adapter_extensions'
52
+ s.version = PKG_VERSION
53
+ s.summary = "Extensions to Rails ActiveRecord adapters."
54
+ s.description = <<-EOF
55
+ Provides various extensions to the Rails ActiveRecord adapters.
56
+ EOF
57
+
58
+ s.add_dependency('rake', '>= 0.7.1')
59
+ s.add_dependency('activesupport', '>= 1.3.1')
60
+ s.add_dependency('activerecord', '>= 1.14.4')
61
+ s.add_dependency('fastercsv', '>= 1.0.0')
62
+
63
+ s.rdoc_options << '--exclude' << '.'
64
+ s.has_rdoc = false
65
+
66
+ s.files = PKG_FILES.to_a.delete_if {|f| f.include?('.svn')}
67
+ s.require_path = 'lib'
68
+
69
+ s.author = "Anthony Eden"
70
+ s.email = "anthonyeden@gmail.com"
71
+ s.homepage = "http://activewarehouse.rubyforge.org/adapter_extensions"
72
+ s.rubyforge_project = "activewarehouse"
73
+ end
74
+
75
+ Rake::GemPackageTask.new(spec) do |pkg|
76
+ pkg.gem_spec = spec
77
+ pkg.need_tar = true
78
+ pkg.need_zip = true
79
+ end
80
+
81
+ desc "Generate code statistics"
82
+ task :lines do
83
+ lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
84
+
85
+ for file_name in FileList["lib/**/*.rb"]
86
+ next if file_name =~ /vendor/
87
+ f = File.open(file_name)
88
+
89
+ while line = f.gets
90
+ lines += 1
91
+ next if line =~ /^\s*$/
92
+ next if line =~ /^\s*#/
93
+ codelines += 1
94
+ end
95
+ puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
96
+
97
+ total_lines += lines
98
+ total_codelines += codelines
99
+
100
+ lines, codelines = 0, 0
101
+ end
102
+
103
+ puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
104
+ end
105
+
106
+ desc "Publish the release files to RubyForge."
107
+ task :release => [ :package ] do
108
+ `rubyforge login`
109
+
110
+ for ext in %w( gem tgz zip )
111
+ release_command = "rubyforge add_release activewarehouse #{PKG_NAME} 'REL #{PKG_VERSION}' pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}"
112
+ puts release_command
113
+ system(release_command)
114
+ end
115
+ end
116
+
117
+ desc "Publish the API documentation"
118
+ task :pdoc => [:rdoc] do
119
+ Rake::SshDirPublisher.new("aeden@rubyforge.org", "/var/www/gforge-projects/activewarehouse/adapter_extensions/rdoc", "rdoc").upload
120
+ end
121
+
122
+ desc "Reinstall the gem from a local package copy"
123
+ task :reinstall => [:package] do
124
+ `sudo gem uninstall -x #{PKG_NAME}`
125
+ `sudo gem install pkg/#{PKG_NAME}-#{PKG_VERSION}`
126
+ end
@@ -0,0 +1,20 @@
1
+ # This source file contains extensions to the abstract adapter.
2
+ module ActiveRecord #:nodoc:
3
+ module ConnectionAdapters #:nodoc:
4
+ # Extensions to the AbstractAdapter. In some cases a default implementation is provided,
5
+ # in others it is adapter-dependent and the method will raise a NotImplementedError if
6
+ # the adapter does not implement that method
7
+ class AbstractAdapter
8
+ # Truncate the specified table
9
+ def truncate(table_name)
10
+ execute("TRUNCATE #{table_name}")
11
+ end
12
+
13
+ # Bulk loading interface. Load the data from the specified file into the given
14
+ # table. Note that options will be adapter-dependent.
15
+ def bulk_load(file, table_name, options={})
16
+ raise NotImplementedError, "bulk_load is an abstract method"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ # Source code for the MysqlAdapter extensions.
2
+ module ActiveRecord #:nodoc:
3
+ module ConnectionAdapters #:nodoc:
4
+ # Adds new functionality to ActiveRecord MysqlAdapter.
5
+ class MysqlAdapter < AbstractAdapter
6
+ # Bulk load the data in the specified file. This implementation always uses the LOCAL keyword
7
+ # so the file must be found locally, not on the remote server, to be loaded.
8
+ #
9
+ # Options:
10
+ # * <tt>:ignore</tt> -- Ignore the specified number of lines from the source file
11
+ # * <tt>:columns</tt> -- Array of column names defining the source file column order
12
+ # * <tt>:fields</tt> -- Hash of options for fields:
13
+ # * <tt>:delimited_by</tt> -- The field delimiter
14
+ # * <tt>:enclosed_by</tt> -- The field enclosure
15
+ def bulk_load(file, table_name, options={})
16
+ q = "LOAD DATA LOCAL INFILE '#{file}' INTO TABLE #{table_name}"
17
+ if options[:fields]
18
+ q << " FIELDS"
19
+ q << " TERMINATED BY '#{options[:fields][:delimited_by]}'" if options[:fields][:delimited_by]
20
+ q << " ENCLOSED BY '#{options[:fields][:enclosed_by]}'" if options[:fields][:enclosed_by]
21
+ end
22
+ q << " IGNORE #{options[:ignore]} LINES" if options[:ignore]
23
+ q << " (#{options[:columns].join(',')})" if options[:columns]
24
+ execute(q)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,10 @@
1
+ # Source file identifying the version of AdapterExtensions in this package
2
+ module AdapterExtensions#:nodoc:
3
+ module VERSION #:nodoc:
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ TINY = 0
7
+
8
+ STRING = [MAJOR, MINOR, TINY].join('.')
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ # Extensions to the Rails ActiveRecord adapters.
2
+ #
3
+ # Requiring this file will require all of the necessary files to function.
4
+
5
+ puts "Using AdapterExtensions"
6
+
7
+ require 'rubygems'
8
+ unless Kernel.respond_to?(:gem)
9
+ Kernel.send :alias_method, :gem, :require_gem
10
+ end
11
+
12
+ unless defined?(ActiveSupport)
13
+ gem 'activesupport'
14
+ require 'active_support'
15
+ end
16
+
17
+ unless defined?(ActiveRecord)
18
+ gem 'activerecord'
19
+ require 'active_record'
20
+ end
21
+
22
+ $:.unshift(File.dirname(__FILE__))
23
+ require 'adapter_extensions/version'
24
+ Dir[File.dirname(__FILE__) + "/active_record/**/*.rb"].each { |file| require(file) }
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0.10
3
+ specification_version: 1
4
+ name: adapter_extensions
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-03-05 00:00:00 -05:00
8
+ summary: Extensions to Rails ActiveRecord adapters.
9
+ require_paths:
10
+ - lib
11
+ email: anthonyeden@gmail.com
12
+ homepage: http://activewarehouse.rubyforge.org/adapter_extensions
13
+ rubyforge_project: activewarehouse
14
+ description: Provides various extensions to the Rails ActiveRecord adapters.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Anthony Eden
31
+ files:
32
+ - CHANGELOG
33
+ - README
34
+ - LICENSE
35
+ - Rakefile
36
+ - lib/active_record
37
+ - lib/adapter_extensions
38
+ - lib/adapter_extensions.rb
39
+ - lib/active_record/abstract_adapter.rb
40
+ - lib/active_record/connection_adapters
41
+ - lib/active_record/connection_adapters/mysql_adapter.rb
42
+ - lib/adapter_extensions/version.rb
43
+ test_files: []
44
+
45
+ rdoc_options:
46
+ - --exclude
47
+ - .
48
+ extra_rdoc_files: []
49
+
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ requirements: []
55
+
56
+ dependencies:
57
+ - !ruby/object:Gem::Dependency
58
+ name: rake
59
+ version_requirement:
60
+ version_requirements: !ruby/object:Gem::Version::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 0.7.1
65
+ version:
66
+ - !ruby/object:Gem::Dependency
67
+ name: activesupport
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Version::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 1.3.1
74
+ version:
75
+ - !ruby/object:Gem::Dependency
76
+ name: activerecord
77
+ version_requirement:
78
+ version_requirements: !ruby/object:Gem::Version::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.14.4
83
+ version:
84
+ - !ruby/object:Gem::Dependency
85
+ name: fastercsv
86
+ version_requirement:
87
+ version_requirements: !ruby/object:Gem::Version::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 1.0.0
92
+ version: