ambition 0.1.3 → 0.1.4

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/README CHANGED
@@ -178,13 +178,21 @@ still query through ActiveRecord just fine.
178
178
 
179
179
  == Other Enumerables
180
180
 
181
- These methods perform COUNT() operations rather than loading your array into memory. They're all
182
- kickers.
181
+ These methods perform COUNT() operations rather than loading your array into memory. They're all
182
+ kickers.
183
183
 
184
184
  User.any? { |m| m.name == 'jon' }
185
185
  User.all? { |m| m.name == 'jon' }
186
186
  User.select { |m| m.name == 'jon' }.empty?
187
187
 
188
+ == More Sugar
189
+
190
+ The +downcase+ and +upcase+ methods will map to LOWER() and UPPER(), respectively.
191
+
192
+ >> User.select { |m| m.name.downcase =~ 'jon%' }.to_sql
193
+ => "SELECT * FROM users WHERE LOWER(users.`name`) LIKE 'jon%'"
194
+
195
+
188
196
  == SELECT * FROM bugs
189
197
 
190
198
  Found a bug? Sweet. Add it at the Lighthouse: http://err.lighthouseapp.com/projects/466-plugins/tickets/new
data/Rakefile CHANGED
@@ -2,13 +2,27 @@ require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/rdoctask'
4
4
 
5
+ Version = '0.1.4'
6
+
7
+ module Rake::TaskManager
8
+ def redefine_task(task_class, args, &block)
9
+ task_name, deps = resolve_args(args)
10
+ @tasks.delete(task_class.scope_name(@scope, task_name).to_s)
11
+ define_task(task_class, args, &block)
12
+ end
13
+ end
14
+ class Rake::Task
15
+ def self.redefine_task(args, &block) Rake.application.redefine_task(self, args, &block) end
16
+ end
17
+ def redefine_task(args, &block) Rake::Task.redefine_task(args, &block) end
18
+
5
19
  begin
6
20
  require 'rubygems'
7
21
  gem 'echoe', '=1.3'
8
22
  ENV['RUBY_FLAGS'] = ""
9
23
  require 'echoe'
10
24
 
11
- Echoe.new('ambition', '0.1.3') do |p|
25
+ Echoe.new('ambition', Version) do |p|
12
26
  p.rubyforge_name = 'err'
13
27
  p.summary = "Ambition builds SQL from plain jane Ruby."
14
28
  p.description = "Ambition builds SQL from plain jane Ruby."
@@ -23,6 +37,12 @@ begin
23
37
  rescue LoadError
24
38
  end
25
39
 
40
+ redefine_task(:test) { }
41
+
42
+ Rake::TestTask.new('test') do |t|
43
+ t.pattern = 'test/*_test.rb'
44
+ end
45
+
26
46
  desc 'Default: run unit tests.'
27
47
  task :default => :test
28
48
 
@@ -63,7 +63,7 @@ module Ambition
63
63
  end
64
64
 
65
65
  def process_match3(exp)
66
- regexp, target = exp.shift.last.inspect.gsub('/',''), process(exp.shift)
66
+ regexp, target = exp.shift.last.inspect.gsub(/\/([^\/]+)\/\S*/, '\1'), process(exp.shift)
67
67
  "#{target} REGEXP '#{regexp}'"
68
68
  end
69
69
 
@@ -121,11 +121,16 @@ module Ambition
121
121
  raise "Not implemented: #{method}"
122
122
  end
123
123
  end
124
-
124
+
125
125
  def translation(receiver, method, other)
126
126
  case method.to_s
127
127
  when '=='
128
- "#{process(receiver)} = #{process(other)}"
128
+ case other_value = process(other)
129
+ when "NULL"
130
+ "#{process(receiver)} is #{other_value}"
131
+ else
132
+ "#{process(receiver)} = #{other_value}"
133
+ end
129
134
  when '<>', '>', '<'
130
135
  "#{process(receiver)} #{method} #{process(other)}"
131
136
  when 'include?'
@@ -134,8 +139,12 @@ module Ambition
134
139
  "#{process(receiver)} LIKE #{process(other)}"
135
140
  when '!~'
136
141
  "#{process(receiver)} NOT LIKE #{process(other)}"
142
+ when 'upcase'
143
+ "UPPER(#{process(receiver)})"
144
+ when 'downcase'
145
+ "LOWER(#{process(receiver)})"
137
146
  else
138
- extract_includes(receiver, method) || "#{process(receiver)}.`#{method}` #{process(other)}"
147
+ extract_includes(receiver, method) || "#{process(receiver)}.`#{method}`"
139
148
  end
140
149
  end
141
150
  end
data/test/types_test.rb CHANGED
@@ -8,7 +8,6 @@ context "Different types" do
8
8
  :symbol => "'--- :symbol\n'",
9
9
  1 => '1',
10
10
  1.2 => '1.2',
11
- nil => 'NULL',
12
11
  true => '1',
13
12
  false => '0',
14
13
  Time.now => "'#{Time.now.to_s(:db)}'",
@@ -27,17 +26,17 @@ context "Different types" do
27
26
  sql = User.select { |m| m.name == 1.2 }.to_sql
28
27
  sql.should == "SELECT * FROM users WHERE users.`name` = 1.2"
29
28
  end
30
-
29
+
31
30
  specify "integer" do
32
31
  sql = User.select { |m| m.name == 1 }.to_sql
33
32
  sql.should == "SELECT * FROM users WHERE users.`name` = 1"
34
33
  end
35
-
34
+
36
35
  specify "true" do
37
36
  sql = User.select { |m| m.name == true }.to_sql
38
37
  sql.should == "SELECT * FROM users WHERE users.`name` = 1"
39
38
  end
40
-
39
+
41
40
  specify "false" do
42
41
  sql = User.select { |m| m.name == false }.to_sql
43
42
  sql.should == "SELECT * FROM users WHERE users.`name` = 0"
@@ -45,7 +44,7 @@ context "Different types" do
45
44
 
46
45
  specify "nil" do
47
46
  sql = User.select { |m| m.name == nil }.to_sql
48
- sql.should == "SELECT * FROM users WHERE users.`name` = NULL"
47
+ sql.should == "SELECT * FROM users WHERE users.`name` is NULL"
49
48
  end
50
49
 
51
50
  xspecify "Time" do
data/test/where_test.rb CHANGED
@@ -109,14 +109,25 @@ context "Where (using select)" do
109
109
  sql.should == "SELECT * FROM users WHERE users.`name` REGEXP 'chris'"
110
110
  end
111
111
 
112
+ specify "simple =~ with regexp flags" do
113
+ sql = User.select { |m| m.name =~ /chris/i }.to_sql
114
+ sql.should == "SELECT * FROM users WHERE users.`name` REGEXP 'chris'"
115
+ end
116
+
117
+ specify "simple LOWER()" do
118
+ sql = User.select { |m| m.name.downcase =~ 'chris%' }.to_sql
119
+ sql.should == "SELECT * FROM users WHERE LOWER(users.`name`) LIKE 'chris%'"
120
+ end
121
+
122
+ specify "simple UPPER()" do
123
+ sql = User.select { |m| m.name.upcase =~ 'chris%' }.to_sql
124
+ sql.should == "SELECT * FROM users WHERE UPPER(users.`name`) LIKE 'chris%'"
125
+ end
126
+
112
127
  specify "undefined equality symbol" do
113
128
  should.raise { User.select { |m| m.name =* /chris/ }.to_sql }
114
129
  end
115
130
 
116
- specify "undefined inequality symbol" do
117
- should.raise { User.select { |m| m.name !+ 'chris' }.to_sql }
118
- end
119
-
120
131
  xspecify "simple == with inline ruby" do
121
132
  # TODO: implement this
122
133
  sql = User.select { |m| m.created_at == 2.days.ago.to_s(:db) }.to_sql
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: ambition
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.3
6
+ version: 0.1.4
7
7
  date: 2007-08-30 00:00:00 -07:00
8
8
  summary: Ambition builds SQL from plain jane Ruby.
9
9
  require_paths: