ambition 0.3.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +41 -48
- data/README +6 -203
- data/ambition.gemspec +111 -0
- data/app_generators/ambition_adapter/USAGE +1 -0
- data/app_generators/ambition_adapter/ambition_adapter_generator.rb +66 -0
- data/app_generators/ambition_adapter/templates/LICENSE +18 -0
- data/app_generators/ambition_adapter/templates/README +6 -0
- data/app_generators/ambition_adapter/templates/Rakefile +31 -0
- data/app_generators/ambition_adapter/templates/lib/base.rb.erb +12 -0
- data/app_generators/ambition_adapter/templates/lib/init.rb.erb +22 -0
- data/app_generators/ambition_adapter/templates/lib/query.rb.erb +52 -0
- data/app_generators/ambition_adapter/templates/lib/select.rb.erb +100 -0
- data/app_generators/ambition_adapter/templates/lib/slice.rb.erb +19 -0
- data/app_generators/ambition_adapter/templates/lib/sort.rb.erb +43 -0
- data/app_generators/ambition_adapter/templates/test/helper.rb.erb +9 -0
- data/app_generators/ambition_adapter/templates/test/select_test.rb.erb +157 -0
- data/app_generators/ambition_adapter/templates/test/slice_test.rb.erb +36 -0
- data/app_generators/ambition_adapter/templates/test/sort_test.rb.erb +53 -0
- data/bin/ambition_adapter +13 -0
- data/lib/ambition.rb +8 -13
- data/lib/ambition/api.rb +42 -35
- data/lib/ambition/context.rb +62 -0
- data/lib/ambition/{proc_to_ruby.rb → core_ext.rb} +13 -0
- data/lib/ambition/enumerable.rb +6 -0
- data/lib/ambition/processors/base.rb +126 -0
- data/lib/ambition/processors/ruby.rb +24 -0
- data/lib/ambition/processors/select.rb +105 -0
- data/lib/ambition/processors/slice.rb +15 -0
- data/lib/ambition/processors/sort.rb +51 -0
- data/test/adapters/exemplar/association_test.rb +34 -0
- data/test/adapters/exemplar/count_test.rb +0 -0
- data/test/adapters/exemplar/detect_test.rb +9 -0
- data/test/adapters/exemplar/enumerable_test.rb +0 -0
- data/test/adapters/exemplar/helper.rb +3 -0
- data/test/adapters/exemplar/index_operator.rb +6 -0
- data/test/adapters/exemplar/reject_test.rb +0 -0
- data/test/adapters/exemplar/select_test.rb +151 -0
- data/test/adapters/exemplar/slice_test.rb +0 -0
- data/test/adapters/exemplar/sort_test.rb +0 -0
- data/test/debug +9 -0
- data/test/helper.rb +2 -52
- metadata +56 -71
- data/Rakefile +0 -64
- data/init.rb +0 -1
- data/lib/ambition/database_statements.rb +0 -31
- data/lib/ambition/processor.rb +0 -123
- data/lib/ambition/query.rb +0 -91
- data/lib/ambition/ruby_processor.rb +0 -22
- data/lib/ambition/select_processor.rb +0 -149
- data/lib/ambition/simple_processor.rb +0 -10
- data/lib/ambition/sort_processor.rb +0 -47
- data/lib/ambition/source.rb +0 -53
- data/test/benchmark.rb +0 -68
- data/test/chaining_test.rb +0 -34
- data/test/console +0 -9
- data/test/count_test.rb +0 -17
- data/test/databases/boot.rb +0 -3
- data/test/databases/database.yml +0 -17
- data/test/databases/fixtures/admin.rb +0 -3
- data/test/databases/fixtures/companies.yml +0 -24
- data/test/databases/fixtures/company.rb +0 -23
- data/test/databases/fixtures/developer.rb +0 -11
- data/test/databases/fixtures/developers_projects.yml +0 -13
- data/test/databases/fixtures/project.rb +0 -4
- data/test/databases/fixtures/projects.yml +0 -7
- data/test/databases/fixtures/replies.yml +0 -20
- data/test/databases/fixtures/reply.rb +0 -5
- data/test/databases/fixtures/topic.rb +0 -19
- data/test/databases/fixtures/topics.yml +0 -32
- data/test/databases/fixtures/user.rb +0 -2
- data/test/databases/fixtures/users.yml +0 -35
- data/test/databases/lib/activerecord_test_connector.rb +0 -65
- data/test/databases/lib/load_fixtures.rb +0 -13
- data/test/databases/lib/schema.rb +0 -41
- data/test/enumerable_test.rb +0 -95
- data/test/join_test.rb +0 -61
- data/test/limit_test.rb +0 -41
- data/test/order_test.rb +0 -52
- data/test/profiler.rb +0 -34
- data/test/ruby_test.rb +0 -9
- data/test/source_test.rb +0 -43
- data/test/types_test.rb +0 -59
- data/test/where_test.rb +0 -245
data/Manifest
CHANGED
@@ -1,48 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
./test/limit_test.rb
|
43
|
-
./test/order_test.rb
|
44
|
-
./test/profiler.rb
|
45
|
-
./test/source_test.rb
|
46
|
-
./test/ruby_test.rb
|
47
|
-
./test/types_test.rb
|
48
|
-
./test/where_test.rb
|
1
|
+
app_generators/ambition_adapter/ambition_adapter_generator.rb
|
2
|
+
app_generators/ambition_adapter/templates/lib/base.rb.erb
|
3
|
+
app_generators/ambition_adapter/templates/lib/init.rb.erb
|
4
|
+
app_generators/ambition_adapter/templates/lib/query.rb.erb
|
5
|
+
app_generators/ambition_adapter/templates/lib/select.rb.erb
|
6
|
+
app_generators/ambition_adapter/templates/lib/slice.rb.erb
|
7
|
+
app_generators/ambition_adapter/templates/lib/sort.rb.erb
|
8
|
+
app_generators/ambition_adapter/templates/LICENSE
|
9
|
+
app_generators/ambition_adapter/templates/Rakefile
|
10
|
+
app_generators/ambition_adapter/templates/README
|
11
|
+
app_generators/ambition_adapter/templates/test/helper.rb.erb
|
12
|
+
app_generators/ambition_adapter/templates/test/select_test.rb.erb
|
13
|
+
app_generators/ambition_adapter/templates/test/slice_test.rb.erb
|
14
|
+
app_generators/ambition_adapter/templates/test/sort_test.rb.erb
|
15
|
+
app_generators/ambition_adapter/USAGE
|
16
|
+
bin/ambition_adapter
|
17
|
+
lib/ambition/api.rb
|
18
|
+
lib/ambition/context.rb
|
19
|
+
lib/ambition/core_ext.rb
|
20
|
+
lib/ambition/enumerable.rb
|
21
|
+
lib/ambition/processors/base.rb
|
22
|
+
lib/ambition/processors/ruby.rb
|
23
|
+
lib/ambition/processors/select.rb
|
24
|
+
lib/ambition/processors/slice.rb
|
25
|
+
lib/ambition/processors/sort.rb
|
26
|
+
lib/ambition.rb
|
27
|
+
LICENSE
|
28
|
+
Manifest
|
29
|
+
README
|
30
|
+
test/adapters/exemplar/association_test.rb
|
31
|
+
test/adapters/exemplar/count_test.rb
|
32
|
+
test/adapters/exemplar/detect_test.rb
|
33
|
+
test/adapters/exemplar/enumerable_test.rb
|
34
|
+
test/adapters/exemplar/helper.rb
|
35
|
+
test/adapters/exemplar/index_operator.rb
|
36
|
+
test/adapters/exemplar/reject_test.rb
|
37
|
+
test/adapters/exemplar/select_test.rb
|
38
|
+
test/adapters/exemplar/slice_test.rb
|
39
|
+
test/adapters/exemplar/sort_test.rb
|
40
|
+
test/debug
|
41
|
+
test/helper.rb
|
data/README
CHANGED
@@ -1,207 +1,10 @@
|
|
1
|
-
|
1
|
+
Ambition
|
2
|
+
========
|
2
3
|
|
3
|
-
|
4
|
+
http://github.com/defunkt/ambition
|
4
5
|
|
5
|
-
|
6
|
-
how fun it was to write, or how it'll make you rich and famous,
|
7
|
-
but instead I'm just going to show you some examples.
|
6
|
+
$ git clone git://github.com/defunkt/ambition.git
|
8
7
|
|
9
|
-
The goal is this: write once, run with ActiveRecord, Sequel, DataMapper,
|
10
|
-
whatever. Kind of like Rack for databases.
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
$ sudo gem install ambition -y
|
15
|
-
|
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.
|
19
|
-
|
20
|
-
To use with Rails, after installing the gem:
|
21
|
-
|
22
|
-
$ cd vendor/plugins
|
23
|
-
$ gem unpack ambition
|
24
|
-
|
25
|
-
RDoc exists: http://rock.errtheblog.com/ambition
|
26
|
-
|
27
|
-
Have at the Git repo:
|
28
|
-
|
29
|
-
$ git clone git://errtheblog.com/git/ambition
|
30
|
-
|
31
|
-
== Examples
|
32
|
-
|
33
|
-
Basically, you write your SQL in Ruby. No, not in Ruby. As Ruby.
|
34
|
-
|
35
|
-
User.select { |u| u.city == 'San Francisco' }.each do |user|
|
36
|
-
puts user.name
|
37
|
-
end
|
38
|
-
|
39
|
-
And that's it.
|
40
|
-
|
41
|
-
The key is that queries arent actually run until the data they represent is
|
42
|
-
requested. Usually this is done with what I call a kicker method. You can call them
|
43
|
-
that, too.
|
44
|
-
|
45
|
-
Kicker methods are guys like +detect+, +each+, +each_with_index+, +map+, +entries+,
|
46
|
-
+to_a+, and +first+ (with no argument). Methods like +select+, +sort_by+, and +first+
|
47
|
-
(with an argument) are not kicker methods and return a +Query+ object without running any SQL.
|
48
|
-
|
49
|
-
Our +Query+ object has two useful methods: +to_sql+ and +to_hash+. With these,
|
50
|
-
we can check out what exactly we're building. Not everyone has +to_sql+,
|
51
|
-
though. Mostly ignore these methods and treat everything like you normally
|
52
|
-
would.
|
53
|
-
|
54
|
-
See, +to_sql+:
|
55
|
-
>> User.select { |m| m.name == 'jon' }.to_sql
|
56
|
-
=> "SELECT * FROM users WHERE users.name = 'jon'"
|
57
|
-
|
58
|
-
See, +to_hash+:
|
59
|
-
>> User.select { |m| m.name == 'jon' }.to_hash
|
60
|
-
=> {:conditions=>"users.name = 'jon'"}
|
61
|
-
|
62
|
-
== Equality -- select { |u| u.field == 'bob' }
|
63
|
-
|
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 (users.name = 'jon' OR (users.age = 21 AND users.password = 'pass'))"
|
84
|
-
|
85
|
-
User.select { |m| (m.name == 'jon' || m.name == 'rick') && m.age == 21 }
|
86
|
-
"SELECT * FROM users WHERE ((users.name = 'jon' OR users.name = 'rick') AND users.age = 21)"
|
87
|
-
|
88
|
-
== Associations -- select { |u| u.field == 'bob' && u.association.field == 'bob@bob.com' }
|
89
|
-
|
90
|
-
The +to_sql+ method doesn't work on associations yet, but that's okay: they can
|
91
|
-
still query through ActiveRecord just fine.
|
92
|
-
|
93
|
-
User.select { |u| u.email == 'chris@ozmm.org' && u.profile.name == 'chris wanstrath' }.map(&:title)
|
94
|
-
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'))
|
95
|
-
|
96
|
-
== Comparisons -- select { |u| u.age > 21 }
|
97
|
-
|
98
|
-
User.select { |m| m.age > 21 }
|
99
|
-
"SELECT * FROM users WHERE users.age > 21"
|
100
|
-
|
101
|
-
User.select { |m| m.age < 21 }.to_sql
|
102
|
-
"SELECT * FROM users WHERE users.age < 21"
|
103
|
-
|
104
|
-
User.select { |m| [1, 2, 3, 4].include? m.id }
|
105
|
-
"SELECT * FROM users WHERE users.id IN (1, 2, 3, 4)"
|
106
|
-
|
107
|
-
== LIKE and REGEXP (RLIKE) -- select { |m| m.name =~ 'chris' }
|
108
|
-
|
109
|
-
User.select { |m| m.name =~ 'chris' }
|
110
|
-
"SELECT * FROM users WHERE users.name LIKE 'chris'"
|
111
|
-
|
112
|
-
User.select { |m| m.name =~ 'chri%' }
|
113
|
-
"SELECT * FROM users WHERE users.name LIKE 'chri%'"
|
114
|
-
|
115
|
-
User.select { |m| m.name !~ 'chris' }
|
116
|
-
"SELECT * FROM users WHERE users.name NOT LIKE 'chris'"
|
117
|
-
|
118
|
-
User.select { |m| !(m.name =~ 'chris') }
|
119
|
-
"SELECT * FROM users WHERE users.name NOT LIKE 'chris'"
|
120
|
-
|
121
|
-
User.select { |m| m.name =~ /chris/ }
|
122
|
-
"SELECT * FROM users WHERE users.name REGEXP 'chris'"
|
123
|
-
|
124
|
-
== #detect
|
125
|
-
|
126
|
-
User.detect { |m| m.name == 'chris' }
|
127
|
-
"SELECT * FROM users WHERE users.name = 'chris' LIMIT 1"
|
128
|
-
|
129
|
-
== LIMITs -- first, first(x), [offset, limit], [range], slice
|
130
|
-
|
131
|
-
User.select { |m| m.name == 'jon' }.first
|
132
|
-
"SELECT * FROM users WHERE users.name = 'jon' LIMIT 1"
|
133
|
-
|
134
|
-
User.select { |m| m.name == 'jon' }.first(5)
|
135
|
-
"SELECT * FROM users WHERE users.name = 'jon' LIMIT 5"
|
136
|
-
|
137
|
-
User.select { |m| m.name == 'jon' }[10, 20]
|
138
|
-
"SELECT * FROM users WHERE users.name = 'jon' LIMIT 10, 20"
|
139
|
-
|
140
|
-
User.select { |m| m.name == 'jon' }[10..20]
|
141
|
-
"SELECT * FROM users WHERE users.name = 'jon' LIMIT 10, 10"
|
142
|
-
|
143
|
-
== ORDER -- sort_by { |u| u.field }
|
144
|
-
|
145
|
-
User.select { |m| m.name == 'jon' }.sort_by { |m| m.name }
|
146
|
-
"SELECT * FROM users WHERE users.name = 'jon' ORDER BY users.name"
|
147
|
-
|
148
|
-
User.select { |m| m.name == 'jon' }.sort_by { |m| [ m.name, m.age ] }
|
149
|
-
"SELECT * FROM users WHERE users.name = 'jon' ORDER BY users.name, users.age"
|
150
|
-
|
151
|
-
User.select { |m| m.name == 'jon' }.sort_by { |m| [ m.name, -m.age ] }
|
152
|
-
"SELECT * FROM users WHERE users.name = 'jon' ORDER BY users.name, users.age DESC"
|
153
|
-
|
154
|
-
User.select { |m| m.name == 'jon' }.sort_by { |m| [ -m.name, -m.age ] }
|
155
|
-
"SELECT * FROM users WHERE users.name = 'jon' ORDER BY users.name DESC, users.age DESC"
|
156
|
-
|
157
|
-
User.select { |m| m.name == 'jon' }.sort_by { |m| -m.age }
|
158
|
-
"SELECT * FROM users WHERE users.name = 'jon' ORDER BY users.age DESC"
|
159
|
-
|
160
|
-
User.select { |m| m.name == 'jon' }.sort_by { |m| -m.profiles.title }
|
161
|
-
"SELECT users.id AS t0_r0, ... FROM users LEFT OUTER JOIN profiles ON profiles.user_id = users.id
|
162
|
-
WHERE (users.name = 'jon') ORDER BY profiles.title DESC"
|
163
|
-
|
164
|
-
User.select { |m| m.name == 'jon' }.sort_by { rand }
|
165
|
-
"SELECT * FROM users WHERE users.name = 'jon' ORDER BY RAND()"
|
166
|
-
|
167
|
-
== COUNT -- select { |u| u.name == 'jon' }.size
|
168
|
-
|
169
|
-
User.select { |m| m.name == 'jon' }.size
|
170
|
-
SELECT count(*) AS count_all FROM users WHERE (users.name = 'jon')
|
171
|
-
|
172
|
-
>> User.select { |m| m.name == 'jon' }.size
|
173
|
-
=> 21
|
174
|
-
|
175
|
-
== Other Enumerables
|
176
|
-
|
177
|
-
These methods perform COUNT() operations rather than loading your array into memory. They're all
|
178
|
-
kickers.
|
179
|
-
|
180
|
-
User.any? { |m| m.name == 'jon' }
|
181
|
-
User.all? { |m| m.name == 'jon' }
|
182
|
-
User.select { |m| m.name == 'jon' }.empty?
|
183
|
-
|
184
|
-
== More Sugar
|
185
|
-
|
186
|
-
The +downcase+ and +upcase+ methods will map to LOWER() and UPPER(), respectively.
|
187
|
-
|
188
|
-
>> User.select { |m| m.name.downcase =~ 'jon%' }.to_sql
|
189
|
-
=> "SELECT * FROM users WHERE LOWER(users.name) LIKE 'jon%'"
|
190
|
-
|
191
|
-
== Quoting
|
192
|
-
|
193
|
-
Columns and values will be quoted using ActiveRecord's quote_column_name and quote methods, if
|
194
|
-
possible.
|
195
|
-
|
196
|
-
== SELECT * FROM bugs
|
197
|
-
|
198
|
-
Found a bug? Sweet. Add it at the Lighthouse:
|
199
|
-
http://err.lighthouseapp.com/projects/466-plugins/tickets/new
|
200
|
-
|
201
|
-
Feature requests are welcome.
|
202
|
-
|
203
|
-
And hey, join our mailing list!
|
204
|
-
|
205
|
-
http://groups.google.com/group/ambition-rb
|
206
|
-
|
207
|
-
* Chris Wanstrath [ chris@ozmm.org ]
|
9
|
+
Chris Wanstrath
|
10
|
+
chris@ozmm.org
|
data/ambition.gemspec
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
|
2
|
+
# Gem::Specification for Ambition-0.5.0
|
3
|
+
# Originally generated by Echoe
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{ambition}
|
7
|
+
s.version = "0.5.0"
|
8
|
+
s.date = %q{2008-01-29}
|
9
|
+
s.summary = %q{Ambition builds yer API calls from plain jane Ruby.}
|
10
|
+
s.email = %q{chris@ozmm.org}
|
11
|
+
s.homepage = %q{http://errtheblog.com/}
|
12
|
+
s.rubyforge_project = %q{err}
|
13
|
+
s.description = %q{Ambition builds yer API calls from plain jane Ruby.}
|
14
|
+
s.default_executable = %q{ambition_adapter}
|
15
|
+
s.has_rdoc = true
|
16
|
+
s.required_ruby_version = Gem::Version::Requirement.new(">= 1.8.6")
|
17
|
+
s.authors = ["Chris Wanstrath"]
|
18
|
+
s.files = ["app_generators/ambition_adapter/ambition_adapter_generator.rb", "app_generators/ambition_adapter/templates/lib/base.rb.erb", "app_generators/ambition_adapter/templates/lib/init.rb.erb", "app_generators/ambition_adapter/templates/lib/query.rb.erb", "app_generators/ambition_adapter/templates/lib/select.rb.erb", "app_generators/ambition_adapter/templates/lib/slice.rb.erb", "app_generators/ambition_adapter/templates/lib/sort.rb.erb", "app_generators/ambition_adapter/templates/LICENSE", "app_generators/ambition_adapter/templates/Rakefile", "app_generators/ambition_adapter/templates/README", "app_generators/ambition_adapter/templates/test/helper.rb.erb", "app_generators/ambition_adapter/templates/test/select_test.rb.erb", "app_generators/ambition_adapter/templates/test/slice_test.rb.erb", "app_generators/ambition_adapter/templates/test/sort_test.rb.erb", "app_generators/ambition_adapter/USAGE", "bin/ambition_adapter", "lib/ambition/api.rb", "lib/ambition/context.rb", "lib/ambition/core_ext.rb", "lib/ambition/enumerable.rb", "lib/ambition/processors/base.rb", "lib/ambition/processors/ruby.rb", "lib/ambition/processors/select.rb", "lib/ambition/processors/slice.rb", "lib/ambition/processors/sort.rb", "lib/ambition.rb", "LICENSE", "Manifest", "README", "test/adapters/exemplar/association_test.rb", "test/adapters/exemplar/count_test.rb", "test/adapters/exemplar/detect_test.rb", "test/adapters/exemplar/enumerable_test.rb", "test/adapters/exemplar/helper.rb", "test/adapters/exemplar/index_operator.rb", "test/adapters/exemplar/reject_test.rb", "test/adapters/exemplar/select_test.rb", "test/adapters/exemplar/slice_test.rb", "test/adapters/exemplar/sort_test.rb", "test/debug", "test/helper.rb", "ambition.gemspec"]
|
19
|
+
s.executables = ["ambition_adapter"]
|
20
|
+
s.add_dependency(%q<ParseTree>, ["= 2.0.1"])
|
21
|
+
s.add_dependency(%q<ruby2ruby>, ["= 1.1.7"])
|
22
|
+
s.add_dependency(%q<rubigen>, ["= 1.1.1"])
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
# # Original Rakefile source (requires the Echoe gem):
|
27
|
+
#
|
28
|
+
# require 'rake'
|
29
|
+
# require 'rake/testtask'
|
30
|
+
# require 'rake/rdoctask'
|
31
|
+
#
|
32
|
+
# Version = '0.5.0'
|
33
|
+
#
|
34
|
+
# module Rake::TaskManager
|
35
|
+
# def delete_task(task_class, *args, &block)
|
36
|
+
# task_name, deps = resolve_args(args)
|
37
|
+
# @tasks.delete(task_class.scope_name(@scope, task_name).to_s)
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
# class Rake::Task
|
41
|
+
# def self.delete_task(args, &block) Rake.application.delete_task(self, args, &block) end
|
42
|
+
# end
|
43
|
+
# def delete_task(args, &block) Rake::Task.delete_task(args, &block) end
|
44
|
+
#
|
45
|
+
# begin
|
46
|
+
# require 'rubygems'
|
47
|
+
# gem 'echoe', '>=2.7'
|
48
|
+
# ENV['RUBY_FLAGS'] = ""
|
49
|
+
# require 'echoe'
|
50
|
+
#
|
51
|
+
# Echoe.new('ambition', Version) do |p|
|
52
|
+
# p.project = 'err'
|
53
|
+
# p.summary = "Ambition builds yer API calls from plain jane Ruby."
|
54
|
+
# p.description = "Ambition builds yer API calls from plain jane Ruby."
|
55
|
+
# p.url = "http://errtheblog.com/"
|
56
|
+
# p.author = 'Chris Wanstrath'
|
57
|
+
# p.email = "chris@ozmm.org"
|
58
|
+
# p.ruby_version = '>= 1.8.6'
|
59
|
+
# p.ignore_pattern = /^(\.git|site|adapters).+/
|
60
|
+
# p.test_pattern = 'test/*_test.rb'
|
61
|
+
# p.dependencies << 'ParseTree =2.0.1'
|
62
|
+
# p.dependencies << 'ruby2ruby =1.1.7'
|
63
|
+
# p.dependencies << 'rubigen =1.1.1'
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# rescue LoadError
|
67
|
+
# puts "Not doing any of the Echoe gemmy stuff, because you don't have the specified gem versions"
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# delete_task :test
|
71
|
+
# delete_task :install_gem
|
72
|
+
#
|
73
|
+
# Rake::TestTask.new('test') do |t|
|
74
|
+
# t.pattern = 'test/*_test.rb'
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# Rake::TestTask.new('test:adapters') do |t|
|
78
|
+
# t.pattern = 'adapters/*/test/*_test.rb'
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# Dir['adapters/*'].each do |adapter|
|
82
|
+
# adapter = adapter.split('/').last
|
83
|
+
# Rake::TestTask.new("test:adapters:#{adapter.sub('ambitious_','')}") do |t|
|
84
|
+
# t.pattern = "adapters/#{adapter}/test/*_test.rb"
|
85
|
+
# end
|
86
|
+
# end
|
87
|
+
#
|
88
|
+
# desc 'Default: run unit tests.'
|
89
|
+
# task :default => :test
|
90
|
+
#
|
91
|
+
# desc 'Generate RDoc documentation'
|
92
|
+
# Rake::RDocTask.new(:rdoc) do |rdoc|
|
93
|
+
# files = ['README', 'LICENSE', 'lib/**/*.rb']
|
94
|
+
# rdoc.rdoc_files.add(files)
|
95
|
+
# rdoc.main = "README"
|
96
|
+
# rdoc.title = "ambition"
|
97
|
+
# rdoc.template = File.exists?(t="/Users/chris/ruby/projects/err/rock/template.rb") ? t : "/var/www/rock/template.rb"
|
98
|
+
# rdoc.rdoc_dir = 'doc'
|
99
|
+
# rdoc.options << '--inline-source'
|
100
|
+
# end
|
101
|
+
#
|
102
|
+
# desc 'Generate coverage reports'
|
103
|
+
# task :rcov do
|
104
|
+
# `rcov -e gems test/*_test.rb`
|
105
|
+
# puts 'Generated coverage reports.'
|
106
|
+
# end
|
107
|
+
#
|
108
|
+
# desc 'Install as a gem'
|
109
|
+
# task :install_gem do
|
110
|
+
# puts `rake manifest package && gem install pkg/ambition-#{Version}.gem`
|
111
|
+
# end
|
@@ -0,0 +1 @@
|
|
1
|
+
o.
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class AmbitionAdapterGenerator < RubiGen::Base
|
2
|
+
# DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
|
3
|
+
# default_options :author => nil
|
4
|
+
|
5
|
+
attr_reader :adapter_name, :adapter_module
|
6
|
+
|
7
|
+
def initialize(runtime_args, runtime_options = {})
|
8
|
+
super
|
9
|
+
usage if args.empty?
|
10
|
+
@destination_root = File.expand_path(args.shift)
|
11
|
+
base_name = self.base_name.sub(/ambitious(-|_)/,'')
|
12
|
+
@adapter_name = base_name
|
13
|
+
@adapter_module = base_name.split('_').map { |part| part[0] = part[0...1].upcase; part }.join
|
14
|
+
extract_options
|
15
|
+
end
|
16
|
+
|
17
|
+
def manifest
|
18
|
+
record do |m|
|
19
|
+
# Ensure appropriate folder(s) exists
|
20
|
+
m.directory ''
|
21
|
+
dirs = %W(
|
22
|
+
lib/ambition/adapters/#{adapter_name}
|
23
|
+
test
|
24
|
+
)
|
25
|
+
dirs.each { |path| m.directory path }
|
26
|
+
|
27
|
+
##
|
28
|
+
# Translator / Query stubs
|
29
|
+
adapter_path = "lib/ambition/adapters/#{adapter_name}"
|
30
|
+
|
31
|
+
%w( base query select slice sort ).each do |file|
|
32
|
+
m.template "lib/#{file}.rb.erb", "#{adapter_path}/#{file}.rb"
|
33
|
+
end
|
34
|
+
|
35
|
+
m.template 'lib/init.rb.erb', "#{adapter_path}.rb"
|
36
|
+
|
37
|
+
##
|
38
|
+
# Test stubs
|
39
|
+
Dir[File.dirname(__FILE__) + '/templates/test/*.rb.erb'].each do |file|
|
40
|
+
file = File.basename(file, '.*')
|
41
|
+
m.template "test/#{file}.erb", "test/#{file}"
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Normal files
|
46
|
+
files = %w( LICENSE README Rakefile )
|
47
|
+
files.each do |file|
|
48
|
+
m.template file, file
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
protected
|
54
|
+
def banner
|
55
|
+
"Coming soon"
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_options!(opts)
|
59
|
+
opts.separator ''
|
60
|
+
opts.separator 'Options:'
|
61
|
+
opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
62
|
+
opts.separator ''
|
63
|
+
end
|
64
|
+
|
65
|
+
def extract_options; end
|
66
|
+
end
|