ambition 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -6,15 +6,16 @@ I could tell you all about how awesome the internals are, or
6
6
  how fun it was to write, or how it'll make you rich and famous,
7
7
  but instead I'm just going to show you some examples.
8
8
 
9
- The goal is this: write once, run with ActiveRecord, Sequel, DataMapper, whatever. Kind
10
- of like Rack for databases.
9
+ The goal is this: write once, run with ActiveRecord, Sequel, DataMapper,
10
+ whatever. Kind of like Rack for databases.
11
11
 
12
12
  == Git It (Not with Git, though)
13
13
 
14
14
  $ sudo gem install ambition -y
15
15
 
16
- This will suck in Ambition and its dependencies (ParseTree & ActiveRecord). It's fully usable
17
- outside of Rails (I use it in a Camping app or two), as long as you're riding ActiveRecord.
16
+ This will suck in Ambition and its dependencies (ParseTree & ActiveRecord).
17
+ It's fully usable outside of Rails (I use it in a Camping app or two), as long
18
+ as you're riding ActiveRecord.
18
19
 
19
20
  To use with Rails, after installing the gem:
20
21
 
@@ -33,13 +34,15 @@ Basically, you write your SQL in Ruby. No, not in Ruby. As Ruby.
33
34
 
34
35
  And that's it.
35
36
 
36
- The key is the +each+ method. You build up a +Query+ using +select+, +first+, and +sort_by+,
37
- then call +each+ on it. This'll run the query and enumerate through the results. Really, you
38
- can use any Enumerable method: +map+, +each_with_index+, etc.
37
+ The key is the +each+ method. You build up a +Query+ using +select+, +first+,
38
+ and +sort_by+, then call +each+ on it. This'll run the query and enumerate
39
+ through the results. Really, you can use any Enumerable method: +map+,
40
+ +each_with_index+, etc.
39
41
 
40
- Our +Query+ object has two useful methods: +to_sql+ and +to_hash+. With these, we can
41
- check out what exactly we're building. Not everyone has +to_sql+, though. Mostly ignore
42
- these methods and treat everything like you normally would.
42
+ Our +Query+ object has two useful methods: +to_sql+ and +to_hash+. With these,
43
+ we can check out what exactly we're building. Not everyone has +to_sql+,
44
+ though. Mostly ignore these methods and treat everything like you normally
45
+ would.
43
46
 
44
47
  See, +to_sql+:
45
48
  >> User.select { |m| m.name == 'jon' }.to_sql
@@ -52,7 +55,7 @@ See, +to_hash+:
52
55
  == Limitations
53
56
 
54
57
  You can use variables, but any more complex Ruby (right now) won't work
55
- inside your blocks. Just do it outside the block and assign it to a variable, okay?
58
+ inside your blocks. Just do it outside the block and assign it to a variable.
56
59
 
57
60
  Instead of:
58
61
  User.select { |m| m.date == 2.days.ago }
@@ -85,8 +88,8 @@ Instance variables and globals work, too. Same with method calls.
85
88
 
86
89
  == Associations -- select { |u| u.field == 'bob' && u.association.field == 'bob@bob.com' }
87
90
 
88
- The +to_sql+ method doesn't work on associations yet, but that's okay: they can still query through
89
- ActiveRecord just fine.
91
+ The +to_sql+ method doesn't work on associations yet, but that's okay: they can
92
+ still query through ActiveRecord just fine.
90
93
 
91
94
  User.select { |u| u.email == 'chris@ozmm.org' && u.profile.name == 'chris wanstrath' }.map(&:title)
92
95
  SELECT users.`id` AS t0_r0, ... FROM users LEFT OUTER JOIN profiles ON profiles.user_id = users.id WHERE ((users.`email` = 'chris@ozmm.org' AND profiles.name = 'chris wanstrath'))
@@ -172,4 +175,4 @@ Found a bug? Sweet. Add it at the Lighthouse: http://err.lighthouseapp.com/pro
172
175
 
173
176
  Feature requests are welcome.
174
177
 
175
- * Chris Wanstrath [ chris@ozmm.org ]
178
+ * Chris Wanstrath [ chris@ozmm.org ]
data/Rakefile CHANGED
@@ -2,15 +2,30 @@ require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/rdoctask'
4
4
 
5
- desc 'Default: run unit tests.'
6
- task :default => :test
5
+ begin
6
+ require 'rubygems'
7
+ gem 'echoe', '=1.3'
8
+ ENV['RUBY_FLAGS'] = ""
9
+ require 'echoe'
10
+
11
+ Echoe.new('ambition', '0.1.1') do |p|
12
+ p.rubyforge_name = 'err'
13
+ p.summary = "Ambition builds SQL from plain jane Ruby."
14
+ p.description = "Ambition builds SQL from plain jane Ruby."
15
+ p.url = "http://errtheblog.com/"
16
+ p.author = 'Chris Wanstrath'
17
+ p.email = "chris@ozmm.org"
18
+ p.extra_deps << ['ParseTree', '=2.0.1']
19
+ p.extra_deps << ['activerecord', '>=1.15.0']
20
+ p.test_globs = 'test/*_test.rb'
21
+ end
7
22
 
8
- desc 'Test it!'
9
- Rake::TestTask.new(:test) do |t|
10
- t.pattern = 'test/**/*_test.rb'
11
- t.verbose = true
23
+ rescue LoadError
12
24
  end
13
25
 
26
+ desc 'Default: run unit tests.'
27
+ task :default => :test
28
+
14
29
  desc 'Generate RDoc documentation'
15
30
  Rake::RDocTask.new(:rdoc) do |rdoc|
16
31
  files = ['README', 'LICENSE', 'lib/**/*.rb']
@@ -27,26 +42,3 @@ task :rcov do
27
42
  `rcov -e gems test/*_test.rb`
28
43
  puts 'Generated coverage reports.'
29
44
  end
30
-
31
-
32
- begin
33
- require 'rubygems'
34
- gem 'echoe', '=1.3'
35
- ENV['RUBY_FLAGS'] = ""
36
- require 'echoe'
37
-
38
- Echoe.new('ambition', '0.1.0') do |p|
39
- p.rubyforge_name = 'err'
40
- p.summary = "Ambition builds SQL from plain jane Ruby."
41
- p.description = "Ambition builds SQL from plain jane Ruby."
42
- p.url = "http://errtheblog.com/"
43
- p.author = 'Chris Wanstrath'
44
- p.email = "chris@ozmm.org"
45
- p.extra_deps << ['ParseTree', '=2.0.1']
46
- p.extra_deps << ['activerecord', '>=1.15.0']
47
- end
48
-
49
- rescue LoadError => boom
50
- puts "You are missing a dependency required for meta-operations on this gem."
51
- puts "#{boom.to_s.capitalize}."
52
- end
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
+ require 'active_record' unless defined? ActiveRecord
2
3
  require 'proc_to_ruby'
3
4
  require 'ambition/processor'
4
5
  require 'ambition/query'
@@ -77,5 +77,9 @@ module Ambition
77
77
  hash
78
78
  end
79
79
  end
80
+
81
+ def inspect
82
+ "(Query object: call #to_sql or #to_hash to inspect, call an Enumerable (such as #each or #first) to request data)"
83
+ end
80
84
  end
81
85
  end
@@ -1,10 +1,16 @@
1
1
  require 'rubygems'
2
- require 'test/spec'
3
- require 'mocha'
4
- require 'redgreen'
5
- require 'active_support'
2
+ begin
3
+ require 'test/spec'
4
+ require 'mocha'
5
+ require 'active_support'
6
+ rescue LoadError
7
+ puts "=> You need the test-spec, mocha, and activesupport gems to run these tests."
8
+ exit
9
+ end
6
10
  require 'active_record'
7
11
 
12
+ begin require 'redgreen'; rescue LoadError; end
13
+
8
14
  $:.unshift File.dirname(__FILE__) + '/../lib'
9
15
  require 'ambition'
10
16
 
metadata CHANGED
@@ -3,8 +3,8 @@ 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.0
7
- date: 2007-08-29 00:00:00 -07:00
6
+ version: 0.1.1
7
+ date: 2007-08-30 00:00:00 -07:00
8
8
  summary: Ambition builds SQL from plain jane Ruby.
9
9
  require_paths:
10
10
  - lib
@@ -52,8 +52,15 @@ files:
52
52
  - ./test/types_test.rb
53
53
  - ./test/where_test.rb
54
54
  - ./Manifest
55
- test_files: []
56
-
55
+ test_files:
56
+ - test/chaining_test.rb
57
+ - test/count_test.rb
58
+ - test/enumerable_test.rb
59
+ - test/join_test.rb
60
+ - test/limit_test.rb
61
+ - test/order_test.rb
62
+ - test/types_test.rb
63
+ - test/where_test.rb
57
64
  rdoc_options: []
58
65
 
59
66
  extra_rdoc_files: []