benhoskings-ambitious-activerecord 0.1.3.7 → 0.1.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2007 Chris Wanstrath
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,234 @@
1
+ h2. An Ambitious ActiveRecord Adapter
2
+
3
+ I could tell you all about how awesome the internals are, or
4
+ how fun it was to write, or how it'll make you rich and famous,
5
+ but instead I'm just going to show you some examples.
6
+
7
+ h2. Get It
8
+
9
+ @$ sudo gem install ambitious-activerecord@
10
+
11
+ This will suck in the adapter and its dependencies (ActiveRecord & Ambition).
12
+ It's fully usable outside of Rails (I use it in a Camping app or two), as long
13
+ as you're riding ActiveRecord.
14
+
15
+ Now require it in your app:
16
+
17
+ <pre>
18
+ require 'rubygems'
19
+ require 'ambition/adapters/activerecord'
20
+ </pre>
21
+
22
+ h2. Examples
23
+
24
+ Basically, you write your SQL in Ruby. No, not in Ruby. As Ruby.
25
+
26
+ <ruby>
27
+ User.select { |u| u.city == 'San Francisco' }.each do |user|
28
+ puts user.name
29
+ end
30
+ </ruby>
31
+
32
+ And that's it.
33
+
34
+ The key is that queries aren't actually run until the data they represent is
35
+ requested. Usually this is done with what I call a kicker method. You can call them
36
+ that, too.
37
+
38
+ Kicker methods are guys like @detect@, @each@, @each_with_index@, @map@, @entries@,
39
+ @to_a@, and @first@ (with no argument). Methods like @select@, @sort_by@, and @first@
40
+ (with an argument) are not kicker methods and return a @Context@ object without running any SQL.
41
+
42
+ Our @Context@ object has two useful methods: @to_s@ and @to_hash@. With these,
43
+ we can check out what exactly we're building. Not everyone has @to_s@,
44
+ though. Mostly ignore these methods and treat everything like you normally
45
+ would.
46
+
47
+ See, @to_s@:
48
+
49
+ <ruby>
50
+ >> User.select { |m| m.name == 'jon' }.to_s
51
+ => "SELECT * FROM users WHERE users.name = 'jon'"
52
+ </ruby>
53
+
54
+ See, @to_hash@:
55
+
56
+ <ruby>
57
+ >> User.select { |m| m.name == 'jon' }.to_hash
58
+ => { :conditions => "users.name = 'jon'" }
59
+ </ruby>
60
+
61
+ h2. Equality - select { |u| u.field == 'bob' }
62
+
63
+ <ruby>
64
+ User.select { |m| m.name == 'jon' }
65
+ "SELECT * FROM users WHERE users.name = 'jon'"
66
+
67
+ User.select { |m| m.created_at > 2.days.ago }
68
+ "SELECT * FROM users WHERE users.created_at > '2007-09-26 20:37:47'"
69
+
70
+ User.select { |m| m.name == 'jon' }
71
+ "SELECT * FROM users WHERE users.name = 'jon'"
72
+
73
+ User.select { |m| m.name != 'jon' }
74
+ "SELECT * FROM users WHERE users.name <> 'jon'"
75
+
76
+ User.select { |m| m.name == 'jon' && m.age == 21 }
77
+ "SELECT * FROM users WHERE (users.name = 'jon' AND users.age = 21)"
78
+
79
+ User.select { |m| m.name == 'jon' || m.age == 21 }
80
+ "SELECT * FROM users WHERE (users.name = 'jon' OR users.age = 21)"
81
+
82
+ User.select { |m| m.name == 'jon' || m.age == 21 && m.password == 'pass' }
83
+ "SELECT * FROM users WHERE
84
+ (users.name = 'jon' OR (users.age = 21 AND users.password = 'pass'))"
85
+
86
+ User.select { |m| (m.name == 'jon' || m.name == 'rick') && m.age == 21 }
87
+ "SELECT * FROM users WHERE
88
+ ((users.name = 'jon' OR users.name = 'rick') AND users.age = 21)"
89
+ </ruby>
90
+
91
+ h2. Associations - select { |u| u.field == 'bob' && u.association.field == 'bob@bob.com' }
92
+
93
+ The @to_s@ method doesn't work on associations yet, but that's okay: they can
94
+ still query through ActiveRecord just fine.
95
+
96
+ <ruby>
97
+ User.select do |u|
98
+ u.email == 'chris@ozmm.org' && u.profile.name == 'chris wanstrath'
99
+ end.map(&:title)
100
+
101
+ "SELECT users.id AS t0_r0, ... FROM users
102
+ LEFT OUTER JOIN profiles ON profiles.user_id = users.id
103
+ WHERE ((users.email = 'chris@ozmm.org' AND profiles.name = 'chris wanstrath'))"
104
+ </ruby>
105
+
106
+ h2. Comparisons - select { |u| u.age > 21 }
107
+
108
+ <ruby>
109
+ User.select { |m| m.age > 21 }
110
+ "SELECT * FROM users WHERE users.age > 21"
111
+
112
+ User.select { |m| m.age < 21 }.to_s
113
+ "SELECT * FROM users WHERE users.age < 21"
114
+
115
+ User.select { |m| [1, 2, 3, 4].include? m.id }
116
+ "SELECT * FROM users WHERE users.id IN (1, 2, 3, 4)"
117
+ </ruby>
118
+
119
+ h2. LIKE and REGEXP (RLIKE) - select { |m| m.name =~ 'chris' }
120
+
121
+ <ruby>
122
+ User.select { |m| m.name =~ 'chris' }
123
+ "SELECT * FROM users WHERE users.name LIKE 'chris'"
124
+
125
+ User.select { |m| m.name =~ 'chri%' }
126
+ "SELECT * FROM users WHERE users.name LIKE 'chri%'"
127
+
128
+ User.select { |m| m.name !~ 'chris' }
129
+ "SELECT * FROM users WHERE users.name NOT LIKE 'chris'"
130
+
131
+ User.select { |m| !(m.name =~ 'chris') }
132
+ "SELECT * FROM users WHERE users.name NOT LIKE 'chris'"
133
+
134
+ User.select { |m| m.name =~ /chris/ }
135
+ "SELECT * FROM users WHERE users.name REGEXP 'chris'"
136
+ </ruby>
137
+
138
+ h2. #detect
139
+
140
+ <ruby>
141
+ User.detect { |m| m.name == 'chris' }
142
+ "SELECT * FROM users WHERE users.name = 'chris' LIMIT 1"
143
+ </ruby>
144
+
145
+ h2. LIMITs - first, first(x), [offset, limit], [range], slice
146
+
147
+ <ruby>
148
+ User.select { |m| m.name == 'jon' }.first
149
+ "SELECT * FROM users WHERE users.name = 'jon' LIMIT 1"
150
+
151
+ User.select { |m| m.name == 'jon' }.first(5)
152
+ "SELECT * FROM users WHERE users.name = 'jon' LIMIT 5"
153
+
154
+ User.select { |m| m.name == 'jon' }[10, 20]
155
+ "SELECT * FROM users WHERE users.name = 'jon' LIMIT 10, 20"
156
+
157
+ User.select { |m| m.name == 'jon' }[10..20]
158
+ "SELECT * FROM users WHERE users.name = 'jon' LIMIT 10, 10"
159
+ </ruby>
160
+
161
+ h2. ORDER - sort_by { |u| u.field }
162
+
163
+ <ruby>
164
+ User.select { |m| m.name == 'jon' }.sort_by { |m| m.name }
165
+ "SELECT * FROM users WHERE users.name = 'jon' ORDER BY users.name"
166
+
167
+ User.select { |m| m.name == 'jon' }.sort_by { |m| [ m.name, m.age ] }
168
+ "SELECT * FROM users WHERE users.name = 'jon' ORDER BY users.name, users.age"
169
+
170
+ User.select { |m| m.name == 'jon' }.sort_by { |m| [ m.name, -m.age ] }
171
+ "SELECT * FROM users WHERE users.name = 'jon'
172
+ ORDER BY users.name, users.age DESC"
173
+
174
+ User.select { |m| m.name == 'jon' }.sort_by { |m| [ -m.name, -m.age ] }
175
+ "SELECT * FROM users WHERE users.name = 'jon'
176
+ ORDER BY users.name DESC, users.age DESC"
177
+
178
+ User.select { |m| m.name == 'jon' }.sort_by { |m| -m.age }
179
+ "SELECT * FROM users WHERE users.name = 'jon' ORDER BY users.age DESC"
180
+
181
+ User.select { |m| m.name == 'jon' }.sort_by { |m| -m.profiles.title }
182
+ "SELECT users.id AS t0_r0, ... FROM users
183
+ LEFT OUTER JOIN profiles ON profiles.user_id = users.id
184
+ WHERE (users.name = 'jon') ORDER BY profiles.title DESC"
185
+
186
+ User.select { |m| m.name == 'jon' }.sort_by { rand }
187
+ "SELECT * FROM users WHERE users.name = 'jon' ORDER BY RAND()"
188
+ </ruby>
189
+
190
+ h2. COUNT - select { |u| u.name == 'jon' }.size
191
+
192
+ <ruby>
193
+ User.select { |m| m.name == 'jon' }.size
194
+ "SELECT count(*) AS count_all FROM users WHERE (users.name = 'jon')"
195
+
196
+ >> User.select { |m| m.name == 'jon' }.size
197
+ => 21
198
+ </ruby>
199
+
200
+ h2. Other Enumerables
201
+
202
+ These methods perform COUNT() operations rather than loading your array into memory. They're all
203
+ kickers.
204
+
205
+ <ruby>
206
+ User.any? { |m| m.name == 'jon' }
207
+ User.all? { |m| m.name == 'jon' }
208
+ User.select { |m| m.name == 'jon' }.empty?
209
+ </ruby>
210
+
211
+ h2. More Sugar
212
+
213
+ The @downcase@ and @upcase@ methods will map to LOWER() and UPPER(), respectively.
214
+
215
+ <ruby>
216
+ >> User.select { |m| m.name.downcase =~ 'jon%' }.to_s
217
+ => "SELECT * FROM users WHERE LOWER(users.name) LIKE 'jon%'"
218
+ </ruby>
219
+
220
+ h2. Quoting
221
+
222
+ Columns and values will be quoted using ActiveRecord's quote_column_name and quote methods, if
223
+ possible.
224
+
225
+ h2. SELECT * FROM bugs
226
+
227
+ Found a bug? Sweet. Add it at "the Lighthouse":http://err.lighthouseapp.com/projects/466-plugins/tickets/new.
228
+
229
+ More information on Ambition:
230
+
231
+ * "http://ambition.rubyforge.org":http://ambition.rubyforge.org
232
+ * "http://groups.google.com/group/ambition-rb/":http://groups.google.com/group/ambition-rb/
233
+
234
+ - Chris Wanstrath [ chris@ozmm.org ]
@@ -0,0 +1,13 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "benhoskings-ambitious-activerecord"
5
+ gemspec.summary = "An ambitious adapter for ActiveRecord"
6
+ gemspec.email = "chris@ozmm.org"
7
+ gemspec.homepage = "http://errtheblog.com/"
8
+ gemspec.authors = ['Chris Wanstrath', 'Ben Hoskings']
9
+ gemspec.add_dependency 'activerecord', '>=1.15.6'
10
+ end
11
+ rescue LoadError
12
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
13
+ end
@@ -4,13 +4,13 @@
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{ambitious-activerecord}
7
- s.version = "0.1.3.7"
7
+ s.version = "0.1.3.8"
8
8
 
9
9
  s.specification_version = 2 if s.respond_to? :specification_version=
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Chris Wanstrath", "Ben Hoskings"]
13
- s.date = %q{2009-05-04}
13
+ s.date = %q{2009-10-04}
14
14
  s.description = %q{An ambitious adapter for ActiveRecord}
15
15
  s.email = %q{chris@ozmm.org, ben@hoskings.net}
16
16
  s.extra_rdoc_files = ["lib/ambition/adapters/active_record/base.rb", "lib/ambition/adapters/active_record/query.rb", "lib/ambition/adapters/active_record/select.rb", "lib/ambition/adapters/active_record/slice.rb", "lib/ambition/adapters/active_record/sort.rb", "lib/ambition/adapters/active_record/statements.rb", "lib/ambition/adapters/active_record.rb"]
@@ -12,9 +12,9 @@ module Ambition
12
12
  end
13
13
 
14
14
  case value
15
- when true, 'true'
15
+ when true
16
16
  '1'
17
- when false, 'false'
17
+ when false
18
18
  '0'
19
19
  when Regexp
20
20
  "'#{value.source}'"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benhoskings-ambitious-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3.7
4
+ version: 0.1.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-05-04 00:00:00 -07:00
13
+ date: 2009-10-22 00:00:00 +10:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -23,39 +23,30 @@ dependencies:
23
23
  - !ruby/object:Gem::Version
24
24
  version: 1.15.6
25
25
  version:
26
- - !ruby/object:Gem::Dependency
27
- name: benhoskings-ambition
28
- type: :runtime
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ~>
33
- - !ruby/object:Gem::Version
34
- version: 0.5.4.3
35
- version:
36
- description: An ambitious adapter for ActiveRecord
37
- email: chris@ozmm.org, ben@hoskings.net
26
+ description:
27
+ email: chris@ozmm.org
38
28
  executables: []
39
29
 
40
30
  extensions: []
41
31
 
42
32
  extra_rdoc_files:
43
- - lib/ambition/adapters/active_record/base.rb
44
- - lib/ambition/adapters/active_record/query.rb
45
- - lib/ambition/adapters/active_record/select.rb
46
- - lib/ambition/adapters/active_record/slice.rb
47
- - lib/ambition/adapters/active_record/sort.rb
48
- - lib/ambition/adapters/active_record/statements.rb
49
- - lib/ambition/adapters/active_record.rb
33
+ - LICENSE
34
+ - README
50
35
  files:
36
+ - .gitignore
37
+ - LICENSE
38
+ - Manifest
39
+ - README
40
+ - Rakefile
41
+ - ambitious-activerecord.gemspec
42
+ - lib/ambition/adapters/active_record.rb
51
43
  - lib/ambition/adapters/active_record/base.rb
44
+ - lib/ambition/adapters/active_record/context.rb
52
45
  - lib/ambition/adapters/active_record/query.rb
53
46
  - lib/ambition/adapters/active_record/select.rb
54
47
  - lib/ambition/adapters/active_record/slice.rb
55
48
  - lib/ambition/adapters/active_record/sort.rb
56
49
  - lib/ambition/adapters/active_record/statements.rb
57
- - lib/ambition/adapters/active_record/context.rb
58
- - lib/ambition/adapters/active_record.rb
59
50
  - test/benchmark.rb
60
51
  - test/chaining_test.rb
61
52
  - test/count_test.rb
@@ -69,18 +60,13 @@ files:
69
60
  - test/sort_test.rb
70
61
  - test/source_test.rb
71
62
  - test/types_test.rb
72
- - Manifest
73
- - ambitious-activerecord.gemspec
74
63
  has_rdoc: true
75
- homepage: http://ambition.rubyforge.org/
64
+ homepage: http://errtheblog.com/
65
+ licenses: []
66
+
76
67
  post_install_message:
77
68
  rdoc_options:
78
- - --line-numbers
79
- - --inline-source
80
- - --title
81
- - Ambitious-activerecord
82
- - --main
83
- - README
69
+ - --charset=UTF-8
84
70
  require_paths:
85
71
  - lib
86
72
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -97,16 +83,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
83
  version:
98
84
  requirements: []
99
85
 
100
- rubyforge_project: ambition
101
- rubygems_version: 1.2.0
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.5
102
88
  signing_key:
103
- specification_version: 2
89
+ specification_version: 3
104
90
  summary: An ambitious adapter for ActiveRecord
105
91
  test_files:
92
+ - test/benchmark.rb
106
93
  - test/chaining_test.rb
107
94
  - test/count_test.rb
108
95
  - test/enumerable_test.rb
96
+ - test/helper.rb
109
97
  - test/join_test.rb
98
+ - test/profiler.rb
110
99
  - test/ruby_test.rb
111
100
  - test/select_test.rb
112
101
  - test/slice_test.rb