activerecord-mysql-adapter-flags 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,23 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ doc
21
+ .yardoc
22
+
23
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 zerobearing2
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ = activerecord-mysql-adapter-flags
2
+
3
+ MysqlAdapter patch to allow passing driver flags from config/database.yml.
4
+
5
+ == Why
6
+
7
+ Needed to enable mysql driver compression for a few projects. The default MysqlAdapter shipped with Rails doesn't allow for
8
+ flags. Therefore, this is a simple patch to allow Mysql::CONST's to be defined in the database.yml file.
9
+
10
+ == Example
11
+
12
+ config/database.yml
13
+
14
+ development:
15
+ adapter: mysql
16
+ username: dbuser
17
+ password: "secert"
18
+ host: localhost
19
+ database: test
20
+ flags: "CLIENT_MULTI_RESULTS, CLIENT_COMPRESS"
21
+
22
+ Note: the flags get OR'd together before passing onto the connect method. If the flag const doesn't exist in the Mysql class,
23
+ it will be ignored.
24
+
25
+ == TODO's
26
+
27
+ * write some specs
28
+ * test against more versions of ActiveRecord
29
+ * find cleaner way to implement other than opening the class and overriding custom initializer.
30
+
31
+ == Note on Patches/Pull Requests
32
+
33
+ * Fork the project.
34
+ * Make your feature addition or bug fix.
35
+ * Add tests for it. This is important so I don't break it in a
36
+ future version unintentionally.
37
+ * Commit, do not mess with rakefile, version, or history.
38
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
39
+ * Send me a pull request. Bonus points for topic branches.
40
+
41
+ == Copyright
42
+
43
+ Copyright (c) 2010 zerobearing2. See LICENSE for details.
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "activerecord-mysql-adapter-flags"
8
+ gem.summary = %Q{Add mysql driver flags to MysqlAdpater.}
9
+ gem.description = %Q{Allow setting mysql driver flags in database.yml for Rails apps.}
10
+ gem.email = "david@zerobearing.com"
11
+ gem.homepage = "http://github.com/zerobearing2/activerecord-mysql-adapter-flags"
12
+ gem.authors = ["David Bradford"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_dependency "activerecord", ">= 2.3.2"
15
+ gem.add_dependency "mysql", ">= 2.8.1"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "activerecord-mysql-adapter-flags #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.3
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{activerecord-mysql-adapter-flags}
8
+ s.version = "0.0.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["David Bradford"]
12
+ s.date = %q{2010-03-10}
13
+ s.description = %q{Allow setting mysql driver flags in database.yml for Rails apps.}
14
+ s.email = %q{david@zerobearing.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "activerecord-mysql-adapter-flags.gemspec",
27
+ "lib/active_record/connection_adapters/mysql_adapter_flags.rb",
28
+ "lib/activerecord-mysql-adapter-flags.rb",
29
+ "spec/activerecord-mysql-adapter-flags_spec.rb",
30
+ "spec/spec.opts",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/zerobearing2/activerecord-mysql-adapter-flags}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.6}
37
+ s.summary = %q{Add mysql driver flags to MysqlAdpater.}
38
+ s.test_files = [
39
+ "spec/activerecord-mysql-adapter-flags_spec.rb",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
49
+ s.add_runtime_dependency(%q<activerecord>, [">= 2.3.2"])
50
+ s.add_runtime_dependency(%q<mysql>, [">= 2.8.1"])
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
53
+ s.add_dependency(%q<activerecord>, [">= 2.3.2"])
54
+ s.add_dependency(%q<mysql>, [">= 2.8.1"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
58
+ s.add_dependency(%q<activerecord>, [">= 2.3.2"])
59
+ s.add_dependency(%q<mysql>, [">= 2.8.1"])
60
+ end
61
+ end
62
+
@@ -0,0 +1,46 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+
4
+ class MysqlAdapter
5
+
6
+ def initialize(connection, logger, connection_options, config)
7
+ super(connection, logger)
8
+ @connection_options, @config = connection_options, config
9
+ @quoted_column_names, @quoted_table_names = {}, {}
10
+
11
+ # allow mysql flags to be set in the database.yml
12
+ # development:
13
+ # adapter: mysql
14
+ # username: "dbuser"
15
+ # password: "secert"
16
+ # host: localhost
17
+ # database: test
18
+ # flags: "CLIENT_COMPRESS"
19
+ unless config[:flags].blank?
20
+
21
+ # append nil's until we get 7 options
22
+ # real_connect(host,user,password,db,port,socket,flags)
23
+ while(@connection_options.length<7) do; @connection_options << nil; end
24
+
25
+ previous_flags = @connection_options[-1].to_i
26
+ flag_strings = config[:flags].split(",").map{|f| f.to_s.strip.upcase}
27
+ flag_vals = flag_strings.collect{|f| Mysql.const_defined?(f) ? Mysql.const_get(f) : nil}.compact
28
+ flags = flag_vals.inject(previous_flags){|val,i| val|i}
29
+
30
+ @connection_options[-1] = flags
31
+ # puts "MySQL Options: #{@connection_options.inspect}"
32
+ end
33
+
34
+ connect
35
+ end
36
+
37
+ #------------------
38
+ def session_status
39
+ settings = {}
40
+ execute("show status").each{|x| settings[x[0].to_s.downcase.to_sym] = x[1]}
41
+ settings
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
2
+ dir = Pathname(__FILE__).dirname.expand_path
3
+
4
+ # include the original (MySQL Adapter) first
5
+ require 'active_record/connection_adapters/mysql_adapter'
6
+
7
+ # Require our internal libraries
8
+ require dir.join('active_record/connection_adapters/mysql_adapter_flags')
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ #TODO: write some meaningful specs
4
+
5
+ # describe "ActiverecordMysqlAdapterFlags" do
6
+ # it "fails" do
7
+ # fail "hey buddy, you should probably rename this file and start specing for real"
8
+ # end
9
+ # end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'activerecord-mysql-adapter-flags'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-mysql-adapter-flags
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 3
9
+ version: 0.0.3
10
+ platform: ruby
11
+ authors:
12
+ - David Bradford
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-10 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: activerecord
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 3
44
+ - 2
45
+ version: 2.3.2
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: mysql
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 8
58
+ - 1
59
+ version: 2.8.1
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ description: Allow setting mysql driver flags in database.yml for Rails apps.
63
+ email: david@zerobearing.com
64
+ executables: []
65
+
66
+ extensions: []
67
+
68
+ extra_rdoc_files:
69
+ - LICENSE
70
+ - README.rdoc
71
+ files:
72
+ - .document
73
+ - .gitignore
74
+ - LICENSE
75
+ - README.rdoc
76
+ - Rakefile
77
+ - VERSION
78
+ - activerecord-mysql-adapter-flags.gemspec
79
+ - lib/active_record/connection_adapters/mysql_adapter_flags.rb
80
+ - lib/activerecord-mysql-adapter-flags.rb
81
+ - spec/activerecord-mysql-adapter-flags_spec.rb
82
+ - spec/spec.opts
83
+ - spec/spec_helper.rb
84
+ has_rdoc: true
85
+ homepage: http://github.com/zerobearing2/activerecord-mysql-adapter-flags
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options:
90
+ - --charset=UTF-8
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project:
110
+ rubygems_version: 1.3.6
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Add mysql driver flags to MysqlAdpater.
114
+ test_files:
115
+ - spec/activerecord-mysql-adapter-flags_spec.rb
116
+ - spec/spec_helper.rb