mysql2_downcase 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ #
6
+ gem 'mysql2'
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "shoulda", ">= 0"
12
+ gem "bundler", "~> 1.0.0"
13
+ gem "jeweler", "~> 1.6.4"
14
+ gem "rcov", ">= 0"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ mysql2 (0.3.7)
10
+ rake (0.9.2)
11
+ rcov (0.9.9)
12
+ shoulda (2.11.3)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 1.0.0)
19
+ jeweler (~> 1.6.4)
20
+ mysql2
21
+ rcov
22
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Danil Pismenny
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.
data/README.rdoc ADDED
@@ -0,0 +1,29 @@
1
+ = mysql2_downcase
2
+
3
+ mysql2 driver that helps you to work with PHP-based databases having uppercased columns. Connect with this driver and use `User.first.id` instead of `User.first.ID`
4
+
5
+ == Usage
6
+
7
+ Set `mysql2_downcase` driver in database configuration:
8
+
9
+ ```
10
+ production:
11
+ adapter: mysql2_downcase
12
+ ...
13
+ ```
14
+
15
+ == Contributing to mysql2_downcase
16
+
17
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
18
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
19
+ * Fork the project
20
+ * Start a feature/bugfix branch
21
+ * Commit and push until you are happy with your contribution
22
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
23
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
24
+
25
+ == Copyright
26
+
27
+ Copyright (c) 2011 Danil Pismenny. See LICENSE.txt for
28
+ further details.
29
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "mysql2_downcase"
18
+ gem.homepage = "http://github.com/dapi/mysql2_downcase"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{mysql2 connection driver that downcase column names}
21
+ gem.description = %Q{mysql2 driver that helps you to work with PHP-based databases having uppercased columns. Connect with this driver and use User.first.id instead of User.first.ID}
22
+ gem.email = "danil@orionet.ru"
23
+ gem.authors = ["Danil Pismenny"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "mysql2_downcase #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,76 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Just use 'mysql2_downcase' adapter in database.yml
3
+ #
4
+
5
+ require 'active_record/connection_adapters/mysql2_adapter'
6
+
7
+ module ActiveRecord
8
+ class Base
9
+ # Establishes a connection to the database that's used by all Active Record objects.
10
+ def self.mysql2_downcase_connection(config)
11
+ config[:username] = 'root' if config[:username].nil?
12
+
13
+ if Mysql2::Client.const_defined? :FOUND_ROWS
14
+ config[:flags] = Mysql2::Client::FOUND_ROWS
15
+ end
16
+
17
+ client = Mysql2::Client.new(config.symbolize_keys)
18
+ options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0]
19
+ ConnectionAdapters::Mysql2DowncaseAdapter.new(client, logger, options, config)
20
+ # ActiveRecord::Base.mysql2_connection(config)
21
+ end
22
+ end
23
+
24
+ class Result
25
+
26
+ # Это выполняется через ActiveRecord::Result.new в mysql2_adapter
27
+ # при выполнении запроса
28
+ def initialize(columns, rows)
29
+ @columns = columns.map { |c| c.downcase }
30
+ @rows = rows
31
+ @hash_rows = nil
32
+ end
33
+ end
34
+
35
+ module ConnectionAdapters
36
+ class Column
37
+
38
+ alias_method :old_initialize, :initialize
39
+
40
+ # Это выполняется при выборке списка аттрибутов на уровне класса
41
+ #
42
+ def initialize(name, default, sql_type = nil, null = true)
43
+ old_initialize name.downcase, default, sql_type, null
44
+ end
45
+
46
+ end
47
+
48
+ class Mysql2DowncaseAdapter < Mysql2Adapter
49
+
50
+ ADAPTER_NAME = 'Mysql2Downcase'
51
+
52
+ # Надо бы глобально сделать тут:
53
+ # def execute(sql, name = nil)
54
+ # debugger
55
+ # end
56
+
57
+ # Это чтобы нормально определся primary_key
58
+ def pk_and_sequence_for(table)
59
+ keys = []
60
+ result = execute("DESCRIBE #{quote_table_name(table)}", 'SCHEMA')
61
+ result.each(:symbolize_keys => true, :as => :hash) do |row|
62
+ keys << row[:Field].downcase if row[:Key] == "PRI"
63
+ end
64
+ keys.length == 1 ? [keys.first, nil] : nil
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+
71
+
72
+ # Возможно понадобится исправить этот метод
73
+ # quote_column_name
74
+
75
+ # Хороший пример адаптера - http://virtuoso.rubyforge.org/activerecord-mysql2spatial-adapter/
76
+ # https://github.com/dazuma/activerecord-mysql2spatial-adapter
File without changes
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'mysql2_downcase'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestMysql2Downcase < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mysql2_downcase
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Danil Pismenny
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-30 00:00:00.000000000 +04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mysql2
17
+ requirement: &2152968320 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2152968320
26
+ - !ruby/object:Gem::Dependency
27
+ name: shoulda
28
+ requirement: &2152967560 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2152967560
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ requirement: &2152966300 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.0.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2152966300
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &2152965060 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.6.4
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2152965060
59
+ - !ruby/object:Gem::Dependency
60
+ name: rcov
61
+ requirement: &2152955460 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2152955460
70
+ description: mysql2 driver that helps you to work with PHP-based databases having
71
+ uppercased columns. Connect with this driver and use User.first.id instead of User.first.ID
72
+ email: danil@orionet.ru
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files:
76
+ - LICENSE.txt
77
+ - README.rdoc
78
+ files:
79
+ - .document
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.rdoc
84
+ - Rakefile
85
+ - VERSION
86
+ - lib/connection_adapters/mysql2_downcase_adapter.rb
87
+ - lib/mysql2_downcase.rb
88
+ - test/helper.rb
89
+ - test/test_mysql2_downcase.rb
90
+ has_rdoc: true
91
+ homepage: http://github.com/dapi/mysql2_downcase
92
+ licenses:
93
+ - MIT
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ segments:
105
+ - 0
106
+ hash: -1626924357624329889
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.6.2
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: mysql2 connection driver that downcase column names
119
+ test_files: []