tune_my_query 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "3.0.3"
4
+ gem "rspec", "2.4.0"
5
+ gem "mysql", "2.8.1"
6
+ gem "pg", "0.10.1"
@@ -0,0 +1,85 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.3)
6
+ actionpack (= 3.0.3)
7
+ mail (~> 2.2.9)
8
+ actionpack (3.0.3)
9
+ activemodel (= 3.0.3)
10
+ activesupport (= 3.0.3)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.4)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.13)
16
+ rack-test (~> 0.5.6)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.3)
19
+ activesupport (= 3.0.3)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4)
22
+ activerecord (3.0.3)
23
+ activemodel (= 3.0.3)
24
+ activesupport (= 3.0.3)
25
+ arel (~> 2.0.2)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.3)
28
+ activemodel (= 3.0.3)
29
+ activesupport (= 3.0.3)
30
+ activesupport (3.0.3)
31
+ arel (2.0.7)
32
+ builder (2.1.2)
33
+ diff-lcs (1.1.2)
34
+ erubis (2.6.6)
35
+ abstract (>= 1.0.0)
36
+ i18n (0.5.0)
37
+ mail (2.2.14)
38
+ activesupport (>= 2.3.6)
39
+ i18n (>= 0.4.0)
40
+ mime-types (~> 1.16)
41
+ treetop (~> 1.4.8)
42
+ mime-types (1.16)
43
+ mysql (2.8.1)
44
+ pg (0.10.1)
45
+ polyglot (0.3.1)
46
+ rack (1.2.1)
47
+ rack-mount (0.6.13)
48
+ rack (>= 1.0.0)
49
+ rack-test (0.5.7)
50
+ rack (>= 1.0)
51
+ rails (3.0.3)
52
+ actionmailer (= 3.0.3)
53
+ actionpack (= 3.0.3)
54
+ activerecord (= 3.0.3)
55
+ activeresource (= 3.0.3)
56
+ activesupport (= 3.0.3)
57
+ bundler (~> 1.0)
58
+ railties (= 3.0.3)
59
+ railties (3.0.3)
60
+ actionpack (= 3.0.3)
61
+ activesupport (= 3.0.3)
62
+ rake (>= 0.8.7)
63
+ thor (~> 0.14.4)
64
+ rake (0.8.7)
65
+ rspec (2.4.0)
66
+ rspec-core (~> 2.4.0)
67
+ rspec-expectations (~> 2.4.0)
68
+ rspec-mocks (~> 2.4.0)
69
+ rspec-core (2.4.0)
70
+ rspec-expectations (2.4.0)
71
+ diff-lcs (~> 1.1.2)
72
+ rspec-mocks (2.4.0)
73
+ thor (0.14.6)
74
+ treetop (1.4.9)
75
+ polyglot (>= 0.3.1)
76
+ tzinfo (0.3.24)
77
+
78
+ PLATFORMS
79
+ ruby
80
+
81
+ DEPENDENCIES
82
+ mysql (= 2.8.1)
83
+ pg (= 0.10.1)
84
+ rails (= 3.0.3)
85
+ rspec (= 2.4.0)
data/HISTORY CHANGED
@@ -0,0 +1,7 @@
1
+ 21 January 2011
2
+ ----------------
3
+
4
+ * Upgraded to Rails3
5
+ * Upgraded to Bundler
6
+ * Bumped version from 0.1.1 -> 0.2.0
7
+
@@ -36,9 +36,9 @@ Specs
36
36
  -----
37
37
  In order to run the specs you should have mysql and postgresql installed. [Here's](http://developer.apple.com/internet/opensource/postgres.html) how to install PostgreSql on a Mac. And, just do:
38
38
 
39
- sudo gem install postgres-pr
39
+ sudo gem install pg
40
40
 
41
- to install postgreSql adapter.
41
+ to install postgreSql adapter or you can use bundler and install project dependencies with it.
42
42
 
43
43
 
44
44
  Bugs
@@ -55,4 +55,4 @@ Authors
55
55
 
56
56
  Roadmap
57
57
  -------
58
- * To make it work for any database extension. At the moment it would only work for PostgreSql specific SQL extensions.
58
+ * To make it work for any database extension. At the moment it would only work for PostgreSql specific SQL extensions.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -1,6 +1,7 @@
1
1
  $: << File.join(File.dirname(__FILE__), "..", "lib")
2
2
 
3
3
  require "tune_my_query/tune_my_query"
4
+
4
5
  Dir.glob("#{File.dirname(__FILE__)}/tune_my_query/commands/*.*").each{|file| require file}
5
6
 
6
- ActiveRecord::Base.send(:include, TuneMyQuery)
7
+ ActiveRecord::Base.send(:include, TuneMyQuery)
@@ -8,8 +8,8 @@ class LikeCommand
8
8
  if condition.is_a?(Array)
9
9
  condition.each { |c| execute(c) } # Calling itself on each element if the supplied parameter is an Array
10
10
  elsif condition.is_a?(String)
11
- condition.gsub!(/ ilike /i, " like ") if condition.is_a?(String)
12
- end
13
- end
11
+ condition.gsub!(/ ilike /i, " like ") if condition.is_a?(String)
12
+ end
13
+ end
14
14
  end
15
- end
15
+ end
@@ -1,51 +1,51 @@
1
1
  module TuneMyQuery
2
-
2
+
3
3
  # Hook invoked in include
4
4
  def self.included(base)
5
5
  base.class_eval do
6
6
  extend ClassMethods
7
7
  class << self
8
- alias_method :super_merge_conditions, :merge_conditions
9
- alias_method :merge_conditions, :standardise_sql
8
+ alias_method :super_where, :where
9
+ alias_method :where, :standardise_sql
10
10
  end
11
11
  end
12
12
  end
13
-
13
+
14
14
  # #
15
15
  # Adds tune_my_query method to ActiveRecord and its subclasses. #
16
16
  # #
17
- # USAGE: #
17
+ # USAGE: #
18
18
  # tune_my_query :like #
19
19
  # #
20
20
  # 'like' signifies the command to be invoked. #
21
21
  # It also makes it apparent that an extension to LIKE needs to be standardise. Works only for #
22
22
  # PostgreSQL specfific extensions. If MySql were to add its own extension to the standard SQL then #
23
- # this gem would cease to work. #
23
+ # this gem would cease to work. #
24
24
  # #
25
- # METHODS: #
25
+ # METHODS: #
26
26
  # #
27
27
  # tune_my_query - Adds the command_type to to an instance variable namely, @command_type #
28
28
  # #
29
29
  # standardise_sql - Checks if PostgreSQLAdapter is used only then runs the conditions through the #
30
30
  # Command. if not leaves the conditions untouched #
31
31
  # #
32
- # #
33
- module ClassMethods
32
+ # #
33
+ module ClassMethods
34
34
  def tune_my_query(command_type)
35
- @command_type = command_type
35
+ @command_type = command_type
36
36
  end
37
-
37
+
38
38
  def standardise_sql(*conditions)
39
39
  if @command_type
40
40
  conditions = conditions.dup
41
41
  @adapter = connection && !connection.class.to_s.include?("PostgreSQLAdapter")
42
42
  command = "#{@command_type.to_s.camelize}Command".constantize
43
- if @adapter
43
+ if @adapter
44
44
  conditions.each { |condition| command.execute(condition) }
45
45
  end
46
46
  end
47
- super_merge_conditions(*conditions)
48
- end
47
+ super_where(*conditions)
48
+ end
49
49
  end
50
-
51
- end
50
+
51
+ end
@@ -1,12 +1,12 @@
1
1
  mysql:
2
2
  :adapter: mysql
3
- :database: tune_my_query
3
+ :database: tune_my_query
4
4
  :username: root
5
5
  :hostname: localhost
6
-
6
+
7
7
  postgres:
8
8
  :adapter: postgresql
9
9
  :database: tune_my_query
10
10
  :username: postgres
11
- :password: postgres
12
- :hostname: localhost
11
+ :password: postgres
12
+ :hostname: localhost
@@ -1,7 +1,7 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  describe "TuneMyQuery" do
4
-
4
+
5
5
  shared_examples_for "a class that responds to tune_my_query method" do
6
6
  it "should respond to method tune_my_query" do
7
7
  Auberdine.should respond_to(:tune_my_query)
@@ -10,48 +10,45 @@ describe "TuneMyQuery" do
10
10
 
11
11
  shared_examples_for "" do
12
12
  end
13
-
13
+
14
14
  context "When connected to MySql" do
15
- before do
15
+ before do
16
16
  connect('mysql')
17
17
  end
18
-
18
+
19
19
  it_should_behave_like "a class that responds to tune_my_query method"
20
-
20
+
21
21
  context "for LIKE SQL command" do
22
22
  it "should convert from postgresql specific to standard SQL" do
23
- Auberdine.merge_conditions(["name = 'joe'"], ["address ilike 'main'"]).
24
- should be_eql("(name = 'joe') AND (address like 'main')")
23
+ Auberdine.where("name = 'joe' AND description ilike 'main'").to_sql.should include %{name = 'joe' AND description like 'main'}
25
24
  end
26
-
25
+
27
26
  it "should ensure that other model objects work normally" do
28
- Exodar.merge_conditions(["name = 'joe'"]).should be_eql("(name = 'joe')")
27
+ Exodar.where("name = 'joe'").to_sql.should include %{name = 'joe'}
29
28
  end
30
-
29
+
31
30
  end
32
-
31
+
33
32
  end
34
-
35
-
33
+
36
34
  context "When connected to PostgreSql" do
37
- before do
35
+ before do
38
36
  connect('postgres')
39
37
  end
40
-
41
- it_should_behave_like "a class that responds to tune_my_query method"
42
-
38
+
39
+ #it_should_behave_like "a class that responds to tune_my_query method"
40
+
43
41
  context "for LIKE SQL command" do
44
42
  it "should not convert from postgresql specific to standard SQL" do
45
- Auberdine.merge_conditions(["name = 'joe'"], ["address ilike 'main'"]).
46
- should be_eql("(name = 'joe') AND (address ilike 'main')")
43
+ Auberdine.where("name = 'joe' AND description ilike 'main'").to_sql.should include %{name = 'joe' AND description ilike 'main'}
47
44
  end
48
-
45
+
49
46
  it "should ensure that other model objects work normally" do
50
- Exodar.merge_conditions(["name = 'joe'"]).should be_eql("(name = 'joe')")
47
+ Exodar.where("name = 'joe'").to_sql.should include %{name = 'joe'}
51
48
  end
52
-
49
+
53
50
  end
54
-
51
+
55
52
  end
56
-
57
- end
53
+
54
+ end
@@ -3,4 +3,4 @@ class Auberdine < ActiveRecord::Base
3
3
  end
4
4
 
5
5
  class Exodar < ActiveRecord::Base
6
- end
6
+ end
@@ -1,8 +1,11 @@
1
- %w(activerecord active_support yaml spec).each{|path| require path }
1
+ #%w(activerecord active_support yaml spec).each{|path| require path }
2
2
 
3
- require File.join(File.dirname(__FILE__), "..", "lib", "tune_my_query")
3
+ require "bundler"
4
+ Bundler.setup
4
5
 
5
- %w(models).each{|path| require File.join(File.dirname(__FILE__), path) }
6
+ require 'active_record'
7
+ require File.expand_path('../../lib/tune_my_query', __FILE__)
8
+ require File.expand_path('../models', __FILE__)
6
9
 
7
10
  def connect(adapter)
8
11
  fix_quote_ident_postgres_error if adapter == "postgres"
@@ -12,6 +15,6 @@ def connect(adapter)
12
15
  end
13
16
 
14
17
  def fix_quote_ident_postgres_error
15
- require "postgres"
18
+ require "pg"
16
19
  def PGconn.quote_ident(name); %("#{name}") end
17
- end
20
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tune_my_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Anuj Dutta
@@ -9,10 +14,69 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-12-16 00:00:00 +05:30
17
+ date: 2011-01-21 00:00:00 +00:00
13
18
  default_executable:
14
- dependencies: []
15
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rails
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - "="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 3
29
+ - 0
30
+ - 3
31
+ version: 3.0.3
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - "="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 2
44
+ - 4
45
+ - 0
46
+ version: 2.4.0
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: mysql
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - "="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 2
59
+ - 8
60
+ - 1
61
+ version: 2.8.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: pg
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - "="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ - 10
75
+ - 1
76
+ version: 0.10.1
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *id004
16
80
  description: Switches between standard SQL and extended SQL syntax depending on the adapter.
17
81
  email: anuj@andhapp.com
18
82
  executables: []
@@ -23,6 +87,9 @@ extra_rdoc_files:
23
87
  - LICENSE
24
88
  - README.markdown
25
89
  files:
90
+ - .rspec
91
+ - Gemfile
92
+ - Gemfile.lock
26
93
  - HISTORY
27
94
  - LICENSE
28
95
  - README.markdown
@@ -33,6 +100,7 @@ files:
33
100
  - lib/tune_my_query/commands/LikeCommand.rb
34
101
  - lib/tune_my_query/tune_my_query.rb
35
102
  - pkg/tune_my_query-0.1.0.gem
103
+ - pkg/tune_my_query-0.1.1.gem
36
104
  - spec/database.yml
37
105
  - spec/lib/tune_my_query_spec.rb
38
106
  - spec/models.rb
@@ -44,26 +112,30 @@ homepage: http://github.com/andhapp/tune_my_query
44
112
  licenses: []
45
113
 
46
114
  post_install_message:
47
- rdoc_options:
48
- - --charset=UTF-8
115
+ rdoc_options: []
116
+
49
117
  require_paths:
50
118
  - lib
51
119
  required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
52
121
  requirements:
53
122
  - - ">="
54
123
  - !ruby/object:Gem::Version
124
+ segments:
125
+ - 0
55
126
  version: "0"
56
- version:
57
127
  required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
58
129
  requirements:
59
130
  - - ">="
60
131
  - !ruby/object:Gem::Version
132
+ segments:
133
+ - 0
61
134
  version: "0"
62
- version:
63
135
  requirements: []
64
136
 
65
137
  rubyforge_project:
66
- rubygems_version: 1.3.5
138
+ rubygems_version: 1.3.7
67
139
  signing_key:
68
140
  specification_version: 3
69
141
  summary: Standardises SQL syntax across databases.