my_enginery 0.2.8

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.
Files changed (118) hide show
  1. data/.gitignore +18 -0
  2. data/.travis.yml +9 -0
  3. data/CHANGELOG.md +14 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE +19 -0
  6. data/README.md +957 -0
  7. data/Rakefile +48 -0
  8. data/app/base/.pryrc +1 -0
  9. data/app/base/Gemfile +25 -0
  10. data/app/base/Rakefile +4 -0
  11. data/app/base/app.rb +8 -0
  12. data/app/base/base/boot.rb +45 -0
  13. data/app/base/base/config.rb +127 -0
  14. data/app/base/base/controllers/rear-controllers/.gitkeep +0 -0
  15. data/app/base/base/database.rb +3 -0
  16. data/app/base/base/helpers/application_helpers.rb +3 -0
  17. data/app/base/base/migrations/.gitkeep +0 -0
  18. data/app/base/base/models/.gitkeep +0 -0
  19. data/app/base/base/specs/.gitkeep +0 -0
  20. data/app/base/base/views/.gitkeep +0 -0
  21. data/app/base/config.ru +4 -0
  22. data/app/base/config/config.yml +17 -0
  23. data/app/base/public/assets/Enginery.png +0 -0
  24. data/app/base/public/assets/Espresso.png +0 -0
  25. data/app/base/public/assets/application.css +13 -0
  26. data/app/base/public/assets/application.js +2 -0
  27. data/app/base/public/assets/bootstrap/css/bootstrap-responsive.min.css +9 -0
  28. data/app/base/public/assets/bootstrap/css/bootstrap.min.css +9 -0
  29. data/app/base/public/assets/bootstrap/img/glyphicons-halflings-white.png +0 -0
  30. data/app/base/public/assets/bootstrap/img/glyphicons-halflings.png +0 -0
  31. data/app/base/public/assets/bootstrap/js/bootstrap.min.js +6 -0
  32. data/app/base/public/assets/jquery.js +6 -0
  33. data/app/base/var/db/.gitkeep +0 -0
  34. data/app/base/var/log/.gitkeep +0 -0
  35. data/app/base/var/pid/.gitkeep +0 -0
  36. data/app/database/ActiveRecord.rb +11 -0
  37. data/app/database/DataMapper.rb +11 -0
  38. data/app/database/Sequel.rb +11 -0
  39. data/app/database/mysql.yml +24 -0
  40. data/app/database/postgres.yml +24 -0
  41. data/app/database/sqlite.yml +24 -0
  42. data/app/gemfiles/ActiveRecord.rb +1 -0
  43. data/app/gemfiles/BlueCloth.rb +1 -0
  44. data/app/gemfiles/DataMapper.rb +1 -0
  45. data/app/gemfiles/FastCGI.rb +1 -0
  46. data/app/gemfiles/Puma.rb +1 -0
  47. data/app/gemfiles/RDiscount.rb +1 -0
  48. data/app/gemfiles/RDoc.rb +1 -0
  49. data/app/gemfiles/RedCloth.rb +1 -0
  50. data/app/gemfiles/WEBrick.rb +1 -0
  51. data/app/gemfiles/WikiCloth.rb +1 -0
  52. data/app/gemfiles/mysql/ActiveRecord.rb +1 -0
  53. data/app/gemfiles/mysql/DataMapper.rb +1 -0
  54. data/app/gemfiles/mysql/Sequel.rb +1 -0
  55. data/app/gemfiles/postgres/ActiveRecord.rb +1 -0
  56. data/app/gemfiles/postgres/DataMapper.rb +1 -0
  57. data/app/gemfiles/postgres/Sequel.rb +1 -0
  58. data/app/gemfiles/sqlite/ActiveRecord.rb +1 -0
  59. data/app/gemfiles/sqlite/DataMapper.rb +1 -0
  60. data/app/gemfiles/sqlite/Sequel.rb +1 -0
  61. data/app/layouts/ERB/layout.erb +56 -0
  62. data/app/layouts/Erubis/layout.erb +56 -0
  63. data/app/layouts/Haml/layout.haml +38 -0
  64. data/app/layouts/Slim/layout.slim +38 -0
  65. data/app/migrations/ActiveRecord.erb +51 -0
  66. data/app/migrations/DataMapper.erb +61 -0
  67. data/app/migrations/Sequel.erb +54 -0
  68. data/app/migrations/tracking_table/ActiveRecord.rb +19 -0
  69. data/app/migrations/tracking_table/DataMapper.rb +26 -0
  70. data/app/migrations/tracking_table/Sequel.rb +18 -0
  71. data/app/rakefiles/ActiveRecord.rb +0 -0
  72. data/app/rakefiles/DataMapper.rb +1 -0
  73. data/app/rakefiles/Sequel.rb +0 -0
  74. data/app/rakefiles/Specular.rb +1 -0
  75. data/app/specfiles/Specular.erb +7 -0
  76. data/bin/my_enginery +235 -0
  77. data/lib/enginery.rb +23 -0
  78. data/lib/enginery/cli.rb +44 -0
  79. data/lib/enginery/configurator.rb +139 -0
  80. data/lib/enginery/delete.rb +116 -0
  81. data/lib/enginery/enginery.rb +41 -0
  82. data/lib/enginery/generator.rb +325 -0
  83. data/lib/enginery/helpers/app.rb +83 -0
  84. data/lib/enginery/helpers/generic.rb +145 -0
  85. data/lib/enginery/helpers/input.rb +123 -0
  86. data/lib/enginery/helpers/orm.rb +86 -0
  87. data/lib/enginery/helpers/validations.rb +101 -0
  88. data/lib/enginery/migrator.rb +371 -0
  89. data/lib/enginery/rake-tasks/data_mapper.rb +49 -0
  90. data/lib/enginery/rake-tasks/specular.rb +41 -0
  91. data/lib/enginery/registry.rb +101 -0
  92. data/lib/enginery/usage.rb +66 -0
  93. data/lib/enginery/version.rb +7 -0
  94. data/logo.png +0 -0
  95. data/my_enginery.gemspec +37 -0
  96. data/test/delete/test__admin.rb +49 -0
  97. data/test/delete/test__controller.rb +37 -0
  98. data/test/delete/test__helper.rb +49 -0
  99. data/test/delete/test__migration.rb +27 -0
  100. data/test/delete/test__model.rb +35 -0
  101. data/test/delete/test__route.rb +35 -0
  102. data/test/delete/test__spec.rb +59 -0
  103. data/test/delete/test__view.rb +51 -0
  104. data/test/generator/test__admin.rb +39 -0
  105. data/test/generator/test__controller.rb +123 -0
  106. data/test/generator/test__helper.rb +56 -0
  107. data/test/generator/test__model.rb +206 -0
  108. data/test/generator/test__project.rb +81 -0
  109. data/test/generator/test__route.rb +110 -0
  110. data/test/generator/test__spec.rb +56 -0
  111. data/test/generator/test__view.rb +85 -0
  112. data/test/migrator/test__auto_generation.rb +41 -0
  113. data/test/migrator/test__manual_generation.rb +59 -0
  114. data/test/migrator/test__migrations.rb +139 -0
  115. data/test/sandbox/.gitkeep +0 -0
  116. data/test/setup.rb +29 -0
  117. data/test/support/spec_helpers.rb +151 -0
  118. metadata +392 -0
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ before_script:
6
+ - mysql -u root -e "CREATE USER 'dev'@'localhost';"
7
+ - mysql -u root -e "GRANT USAGE ON * . * TO 'dev'@'localhost' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;"
8
+ - mysql -u root -e 'GRANT ALL PRIVILEGES ON `dev\_%` . * TO dev@localhost;'
9
+ - mysql -u root -e 'CREATE DATABASE dev__enginery;'
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+
2
+ + 0.0.8 [May 25, 2013]
3
+ - Automatically generate Rear controllers for new models.
4
+ - Allow defining associations for new models - [5286c59](https://github.com/espresso/enginery/commit/5286c59)
5
+ - Ability to delete any generated unit.
6
+ - Default layout for `ERB`, `ERubis`, `Haml` and `Slim` engines.
7
+ - Automatically generate and include helpers for new controllers.
8
+ - Migrator - DataMapper - auto-update model file when performing migrations.
9
+ - Migrator - keep tracks in database so it is usable on environments with readonly filesystem - [52360b5](https://github.com/espresso/enginery/commit/52360b5)
10
+ - Migrator - when available, use `ENV['DATABASE_URL']` instead of config/database.yml - [bbb41618](https://github.com/espresso/enginery/commit/bbb41618)
11
+ - Migrator - run all outstanding migrations when no steps provided [93bef48](https://github.com/espresso/enginery/commit/93bef48)
12
+ - Verbosify auto_migrate/upgrade rake tasks on DataMapper [782e76e](https://github.com/espresso/enginery/commit/782e76e)
13
+
14
+ <hr>
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'e', :git => 'git://github.com/wokibe/espresso'
4
+ gem 'el', :git => 'git://github.com/wokibe/espresso-lungo'
5
+ gem 'rear', :git => 'git://github.com/wokibe/rear'
6
+
7
+ group :development do
8
+ gem 'specular', :git => 'git://github.com/wokibe/specular'
9
+ gem 'sonar', :git => 'git://github.com/wokibe/sonar'
10
+ end
11
+
12
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+
2
+ Copyright (c) 2013 Walter Smith <waltee.smith@gmail.com>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"),
6
+ to deal in the Software without restriction, including without limitation
7
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ and/or sell copies of the Software, and to permit persons to whom the Software
9
+ is furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,957 @@
1
+
2
+ <img src="https://raw.github.com/espresso/enginery/master/logo.png" align="right">
3
+
4
+ <br>
5
+ <p>
6
+ <a href="https://travis-ci.org/espresso/enginery">
7
+ <img src="https://travis-ci.org/espresso/enginery.png"></a>
8
+ </p>
9
+
10
+ # Enginery
11
+
12
+ ### Stuff Builder for [Espresso Framework](https://github.com/espresso/espresso)
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ $ gem install enginery
18
+ ```
19
+
20
+ \+ `$ rbenv rehash` if you are using `rbenv`
21
+
22
+ ## Quick start
23
+
24
+ Create a new application in `./App/` folder:
25
+
26
+ ```bash
27
+ $ enginery g App
28
+ ```
29
+
30
+ Create a new application in current folder:
31
+
32
+ ```bash
33
+ $ enginery g
34
+ ```
35
+
36
+ Generate Controllers:
37
+
38
+ ```bash
39
+ $ enginery g:c Foo
40
+ # generate multiple controllers at once ...
41
+ $ enginery g:c Foo Bar Baz
42
+ ```
43
+
44
+ Generate Routes for `Foo` controller:
45
+
46
+ ```bash
47
+ $ enginery g:r Foo a
48
+ # generate multiple routes at once ...
49
+ $ enginery g:r Foo a b c
50
+ ```
51
+
52
+ Generate Models:
53
+
54
+ ```bash
55
+ $ enginery g:m Foo
56
+ # generate multiple models at once ...
57
+ $ enginery g:m Foo Bar Baz
58
+ ```
59
+
60
+ Generate Specs:
61
+
62
+ ```bash
63
+ $ enginery g:s SomeController some_action
64
+ ```
65
+
66
+ Generate Migrations:
67
+
68
+ ```bash
69
+ $ enginery m migrationName model:ModelName column:some_column
70
+ ```
71
+
72
+ List Migrations:
73
+
74
+ ```bash
75
+ $ enginery m:l
76
+ ```
77
+
78
+ Run Migrations:
79
+
80
+ ```bash
81
+ $ enginery m:up migrationID
82
+ $ enginery m:down migrationID
83
+ ```
84
+
85
+ ## Application structure
86
+
87
+ ```bash
88
+ - base/
89
+ | - models/
90
+ | - views/
91
+ | - controllers/
92
+ ` - rear-controllers/
93
+ | - helpers/
94
+ | - specs/
95
+ | - migrations/
96
+ | - boot.rb
97
+ | - config.rb
98
+ ` - database.rb
99
+
100
+ - config/
101
+ | - config.yml
102
+ ` - database.yml
103
+
104
+ - public/
105
+ | - assets/
106
+ | - app.css
107
+ ` - app.js
108
+
109
+ - tmp/
110
+
111
+ - var/
112
+ | - db/
113
+ | - log/
114
+ ` - pid/
115
+
116
+ - Rakefile
117
+ - Gemfile
118
+ - app.rb
119
+ - config.ru
120
+ ```
121
+
122
+
123
+ # Tutorial
124
+
125
+ [Projects](https://github.com/espresso/enginery#projects) |
126
+ [Controllers](https://github.com/espresso/enginery#controllers) |
127
+ [Routes](https://github.com/espresso/enginery#routes) |
128
+ [Specs](https://github.com/espresso/enginery#specs) |
129
+ [Views](https://github.com/espresso/enginery#views) |
130
+ [Models](https://github.com/espresso/enginery#models) |
131
+ [Migrations](https://github.com/espresso/enginery#migrations) |
132
+ [Admin Interface](https://github.com/espresso/enginery#admin-interface)
133
+
134
+ ## Projects
135
+
136
+ To generate a project simply type:
137
+
138
+ ```bash
139
+ $ enginery g App
140
+ ```
141
+
142
+ This will create `./App` folder with a ready-to-use application inside.
143
+
144
+ To generate a new application in current folder simply omit application name:
145
+
146
+ ```bash
147
+ $ enginery g
148
+ ```
149
+
150
+ ### Engine
151
+
152
+ Generated application will use `ERB` engine by default.
153
+
154
+ To generate a project that will use a custom engine, use `engine` option followed by a semicolon and the full, case sensitive, name of desired engine:
155
+
156
+ ```bash
157
+ $ enginery g engine:Slim
158
+ ```
159
+
160
+ This will update your `Gemfile` by adding `slim` gem and will also update `config.yml` by adding `engine: :Slim`.
161
+
162
+
163
+ Option name can be shortened down to first letter:
164
+
165
+ ```bash
166
+ $ enginery g e:Slim
167
+ ```
168
+
169
+ ### ORM
170
+
171
+ If your project will use any `ORM`, use `orm` option followed by a semicolon and the name of desired `ORM`:
172
+
173
+ ```bash
174
+ $ enginery g orm:ActiveRecord
175
+ ```
176
+
177
+ **Worth to note** - `ORM` name are case insensitive and can be shortened to first letter(s):
178
+
179
+ project using ActiveRecord:
180
+ ```bash
181
+ $ enginery g orm:ar
182
+ # or just
183
+ $ enginery g o:ar
184
+ ```
185
+
186
+ project using DataMapper:
187
+ ```bash
188
+ $ enginery g orm:dm
189
+ # or just
190
+ $ enginery g o:dm
191
+ ```
192
+
193
+ project using Sequel:
194
+ ```bash
195
+ $ enginery g orm:sequel
196
+ # or just
197
+ $ enginery g o:sq
198
+ ```
199
+
200
+ ### Database
201
+
202
+ It is also possible to set database connection info. Accepted options:
203
+
204
+ - db_type (or dbtype)
205
+ - db_host (or dbhost)
206
+ - db_port (or dbport)
207
+ - db_name (or dbname)
208
+ - db_user (or dbuser)
209
+ - db_pass (or dbpass)
210
+
211
+
212
+ project using MySQL:
213
+ ```bash
214
+ $ enginery g dbtype:MySQL
215
+ # or
216
+ $ enginery g dbtype:mysql
217
+ # or just
218
+ $ enginery g dbtype:m
219
+ ```
220
+
221
+ project using PostgreSQL:
222
+ ```bash
223
+ $ enginery g dbtype:postgres
224
+ # or just
225
+ $ enginery g dbtype:p
226
+ ```
227
+
228
+ project using Sqlite:
229
+ ```bash
230
+ $ enginery g dbtype:sqlite
231
+ # or just
232
+ $ enginery g dbtype:s
233
+ ```
234
+
235
+ ### Server/Port/Host
236
+
237
+ Applications generated by Enginery will use Thin web server by default.
238
+
239
+ To use another server set `server` option.
240
+
241
+ Server name should be provided in full and is case sensitive:
242
+
243
+ ```ruby
244
+ enginery g server:Puma
245
+ # or just
246
+ enginery g s:Puma
247
+ ```
248
+
249
+ Generated application will listen on 5252 port by default.
250
+
251
+ To use another port, set `port` option:
252
+
253
+ ```ruby
254
+ enginery g server:Unicorn port:2000
255
+ # or just
256
+ enginery g s:Unicorn p:2000
257
+ ```
258
+
259
+ To make application to listen on another host than "localhost", use `host` option:
260
+
261
+ ```ruby
262
+ enginery g server:Unicorn port:2000 host:192.168.2.5
263
+ # or just
264
+ enginery g s:Unicorn p:2000 h:192.168.2.5
265
+ ```
266
+
267
+
268
+ ### Format
269
+
270
+ Enginery also allow to specify [format](https://github.com/espresso/espresso/blob/master/docs/Routing.md#format) to be used by all controllers / actions.
271
+
272
+ Ex: to make all actions to serve URLs ending in `.html`, use `format:html`:
273
+
274
+ ```bash
275
+ $ enginery g format:html
276
+ ```
277
+
278
+ And of course as per other options, `format` can be shortened to first letter too:
279
+
280
+ ```bash
281
+ $ enginery g f:html
282
+ ```
283
+
284
+ And of course you can pass multiple options:
285
+
286
+ ```bash
287
+ $ enginery g o:ar e:Slim f:html
288
+ ```
289
+
290
+
291
+ **[ [contents &uarr;](https://github.com/espresso/enginery#tutorial) ]**
292
+
293
+
294
+ ## Controllers
295
+
296
+ As simple as:
297
+
298
+ ```bash
299
+ $ enginery g:c Foo
300
+ ```
301
+
302
+ This will create "base/controllers/foo/" folder and "base/controllers/foo_controller.rb" file.
303
+
304
+ The file will contain controller's setups and the folder will contain controller's actions.
305
+
306
+ ### Map
307
+
308
+ By default the controller will be mapped to its underscored name, that's it:
309
+
310
+ ```
311
+ Foo to /foo
312
+ FooBar to /foo_bar
313
+ Foo::Bar to /foo/bar
314
+ etc.
315
+ ```
316
+
317
+ To generate a controller mapped to a custom location, use the `route` option:
318
+
319
+ ```bash
320
+ $ enginery g:c Foo route:bar
321
+ # or just
322
+ $ enginery g:c Foo r:bar
323
+ ```
324
+
325
+ ### Setups
326
+
327
+ When generating a controller without any setups, it will use project-wide ones(passed at project generation), if any.
328
+
329
+ To generate a controller with custom setups, pass them as options:
330
+
331
+ ```bash
332
+ $ enginery g:c Foo e:Haml
333
+ ```
334
+
335
+ This will create a controller that will use `Haml` engine.
336
+
337
+ Another option is [format](https://github.com/espresso/espresso/blob/master/docs/Routing.md#format):
338
+
339
+ ```bash
340
+ $ enginery g:c Foo f:html
341
+ ```
342
+
343
+ ### Multiple
344
+
345
+ When you need to generate multiple controllers at once just pass their names separated by a space:
346
+
347
+ ```bash
348
+ $ enginery g:c A B C
349
+ ```
350
+
351
+ This will generate 3 controllers without any setups.
352
+
353
+ Any passed setups will apply to all generated controllers:
354
+
355
+ ```bash
356
+ $ enginery g:c A B C e:Haml
357
+ ```
358
+
359
+ ### Namespaces
360
+
361
+ When you need a namespaced controller, pass its name as is:
362
+
363
+ ```bash
364
+ $ enginery g:c Foo::Bar
365
+ ```
366
+
367
+ This will generate `Foo` module with `Bar` controller inside:
368
+
369
+ ```ruby
370
+ module Foo
371
+ class Bar < E
372
+ # ...
373
+ end
374
+ end
375
+ ```
376
+
377
+ **Worth to note** that `Bar` controller will be mapped to "/foo/bar" URL.<br>
378
+ To map it to another location, use `route` option as shown above.
379
+
380
+
381
+ ### Including modules
382
+
383
+ If your controller needs extra modules included, use `include:` option:
384
+
385
+ ```bash
386
+ $ enginery g:c Foo include:Bar
387
+ # or just
388
+ $ enginery g:c Foo i:Bar
389
+ ```
390
+
391
+ This will generate `Foo` controller with `Bar` included:
392
+
393
+ ```ruby
394
+ module Foo < E
395
+ include Bar
396
+ # ...
397
+ end
398
+ ```
399
+
400
+ ### Deleting Controllers
401
+
402
+ As easy as:
403
+
404
+ ```bash
405
+ $ enginery delete:c ControllerName
406
+ ```
407
+
408
+ This will remove all controller routes, views, specs and helpers, so use with care.
409
+
410
+
411
+ **[ [contents &uarr;](https://github.com/espresso/enginery#tutorial) ]**
412
+
413
+
414
+ ## Routes
415
+
416
+ As simple as:
417
+
418
+ ```bash
419
+ $ enginery g:route Foo bar
420
+ # or just
421
+ $ enginery g:r Foo bar
422
+ ```
423
+
424
+ where `Foo` is the controller name and `bar` is the route.
425
+
426
+ This will create "base/controllers/foo/bar.rb" and "base/views/foo/bar.erb" files.
427
+
428
+ ### Mapping
429
+
430
+ You can provide the URL rather than the action name - it will be automatically converted into action name according to effective [path rules](https://github.com/espresso/espresso/blob/master/docs/Routing.md#action-mapping):
431
+
432
+ ```bash
433
+ $ enginery g:r Forum posts/latest
434
+ ```
435
+
436
+ This will create "base/controllers/forum/posts__latest.rb" file with `posts__latest` action inside and the "base/views/forum/posts__latest.erb" template file.
437
+
438
+ See [more details on actions mapping](https://github.com/espresso/espresso/blob/master/docs/Routing.md#action-mapping).
439
+
440
+ ### Setups
441
+
442
+ Setups provided at route generation will be effective only on generated route:
443
+
444
+ ```bash
445
+ # generate Foo controller
446
+ $ enginery g:c Foo e:Haml
447
+
448
+ # generate Foo#bar route
449
+ $ enginery g:r Foo bar
450
+
451
+ # generate Foo#baz route
452
+ $ enginery g:r Foo baz e:Slim
453
+ ```
454
+
455
+ `Foo#bar` action will use `Haml` engine, as per controller setup.<br>
456
+ `Foo#baz` action will use `Slim` engine instead, as per route setup.
457
+
458
+
459
+ ### Multiple
460
+
461
+ To generate multiple routes at once just pass their names separated by spaces:
462
+
463
+ ```bash
464
+ $ enginery g:r Foo a b c
465
+ ```
466
+
467
+ this will create 3 routes and 3 views.
468
+
469
+ **Worth to note** that any provided setups will apply on all and only generated actions.
470
+
471
+ ### Deleting Routes
472
+
473
+ As easy as:
474
+
475
+ ```bash
476
+ $ enginery delete:r ControllerName route_name
477
+ ```
478
+
479
+ This will remove all route files, views and specs, so use with care.
480
+
481
+ **[ [contents &uarr;](https://github.com/espresso/enginery#tutorial) ]**
482
+
483
+
484
+ ## Specs
485
+
486
+ Specs are generated simultaneously with routes.
487
+
488
+ It makes sense to generate a spec manually only if it was accidentally lost/damaged.
489
+
490
+ **Note** - Enginery uses [Specular](https://github.com/waltee/specular) to build/run specs. Feel free to contribute by adding support for other testing frameworks.
491
+
492
+ To generate a spec use `spec`(or just `s`) notation followed by controller name and the route to be tested:
493
+
494
+ ```bash
495
+ $ enginery g:s Foo bar
496
+ # where Foo is the controller and bar is the route.
497
+ ```
498
+ This will create `base/specs/foo/` with `bar_spec.rb` file inside.
499
+
500
+ To generate multiple specs pass route names separated by a space:
501
+
502
+ ```bash
503
+ $ enginery g:s Foo a b c
504
+ ```
505
+ This will generate `specs/foo/a_spec.rb`, `specs/foo/b_spec.rb` and `specs/foo/c_spec.rb` files.
506
+
507
+ To run a spec use `$ rake test:Foo#bar`, where `Foo` is the controller name and `bar` is the tested route.
508
+
509
+ To run all specs for `Foo` controller use `$ rake test:Foo`
510
+
511
+ To run all specs for all controllers use `$ rake test` or just `$ rake`
512
+
513
+
514
+ If the controller is under some namespace, pass the full name, do not worry about `::`, `rake` will take care:
515
+
516
+ ```bash
517
+ $ rake test:Forum::Posts
518
+ $ rake test:Forum::Posts#read
519
+ ```
520
+
521
+ To see all available specs use `$ rake -D`
522
+
523
+ **[ [contents &uarr;](https://github.com/espresso/enginery#tutorial) ]**
524
+
525
+
526
+ ## Views
527
+
528
+ View generator are triggered every time you generate a route, so it make sense to use it only to create a template that was accidentally damaged/lost.
529
+
530
+ Invocation:
531
+
532
+ ```bash
533
+ $ enginery g:v Foo bar
534
+ ```
535
+ where `Foo` is the controller name and `bar` is the action to generate view for.
536
+
537
+ This will create "base/views/foo/bar.[ext]" template, if it does not exists.
538
+
539
+ [ext] depending on effective template engine.
540
+
541
+ If template already exists, the generator will simply touch it, without modifying the name/content in any way.
542
+
543
+
544
+ **[ [contents &uarr;](https://github.com/espresso/enginery#tutorial) ]**
545
+
546
+
547
+ ## Models
548
+
549
+ Supported ORMs: `ActiveRecord`, `DataMapper`, `Sequel`
550
+
551
+ ```bash
552
+ $ enginery g:model Foo
553
+ # or just
554
+ $ enginery g:m Foo
555
+ ```
556
+ this will create "base/models/foo.rb" file.
557
+
558
+ File content will depend on setups passed at project generation:
559
+
560
+ If we generate a project like this:
561
+ ```bash
562
+ $ enginery g orm:ActiveRecord
563
+ ```
564
+
565
+ the:
566
+ ```bash
567
+ $ enginery g:m Foo
568
+ ```
569
+
570
+ will result in:
571
+
572
+ ```ruby
573
+ class Foo < ActiveRecord::Base
574
+
575
+ end
576
+ ```
577
+
578
+ And if the project are generated like this:
579
+ ```bash
580
+ $ enginery g orm:DataMapper
581
+ ```
582
+
583
+ the:
584
+ ```bash
585
+ $ enginery g:m Foo
586
+ ```
587
+
588
+ will result in:
589
+
590
+ ```ruby
591
+ class Foo
592
+ include DataMapper::Resource
593
+
594
+ property :id, Serial
595
+ end
596
+ ```
597
+
598
+ To generate a model on a project without default `ORM`, use `orm` option at model generation:
599
+
600
+
601
+ ```bash
602
+ $ enginery g:m Foo orm:ActiveRecord
603
+ # or just
604
+ $ enginery g:m Foo orm:ar
605
+ # or even
606
+ $ enginery g:m Foo o:ar
607
+ ```
608
+
609
+ will result in:
610
+
611
+ ```ruby
612
+ class Foo < ActiveRecord::Base
613
+
614
+ end
615
+ ```
616
+ and will update your Gemfile by adding corresponding gems, unless they are already there.
617
+
618
+ ### Associations
619
+
620
+ With Enginery you can specify a list of associations at model generation.
621
+
622
+ Supported associations:
623
+
624
+ - belongs_to
625
+ - has_one
626
+ - has_many
627
+ - has_and_belongs_to_many
628
+
629
+ Though associations are passed in ActiveRecord way, they will be automatically adjusted if another ORM used.
630
+
631
+ ```bash
632
+ enginery g:m State has_many:cities
633
+ enginery g:m City belongs_to:state
634
+ ```
635
+
636
+ If you need a `through` association simply use `:through` option:
637
+
638
+ ```bash
639
+ enginery g:m Photo has_many:tags:through:tagging
640
+ enginery g:m Tag has_many:photos:through:tagging
641
+ ```
642
+
643
+
644
+ ### Multiple
645
+
646
+ Generating multiple models at once:
647
+
648
+ ```bash
649
+ $ enginery g:m A B C
650
+ # or just for readability
651
+ $ enginery g:models A B C
652
+ ```
653
+
654
+
655
+ ### Including modules
656
+
657
+ If your model needs extra modules included, use `include:` option:
658
+
659
+ ```bash
660
+ $ enginery g:m Foo include:Bar
661
+ # or just
662
+ $ enginery g:m Foo i:Bar
663
+ ```
664
+
665
+ This will generate `Foo` model with `Bar` included:
666
+
667
+ ```ruby
668
+ module Foo < ActiveRecord::Base
669
+ include Bar
670
+ # ...
671
+ end
672
+ ```
673
+
674
+ ### Deleting Models
675
+
676
+ As easy as:
677
+
678
+ ```bash
679
+ $ enginery delete:m ModelName
680
+ ```
681
+
682
+
683
+ **[ [contents &uarr;](https://github.com/espresso/enginery#tutorial) ]**
684
+
685
+
686
+ ## Migrations
687
+
688
+ Supported ORMs: `ActiveRecord`, `DataMapper`, `Sequel`
689
+
690
+ Initial migration for any model are auto-generated alongside with model:
691
+
692
+ ```bash
693
+ $ enginery g:m Page
694
+ ```
695
+ this will generate `Page` model as well a migration that will create model's table when performed up and drop it when performed down.
696
+
697
+ Migrations will reside in `base/migrations/` folder. The file for `Page` model created above will be named **1.[timestamp].initializing-Page-model.rb**
698
+
699
+ Now you can edit it by adding columns you need created alongside with table. You should add them inside `up` method or block, depending on used ORM.
700
+
701
+ If you do not want to edit the file manually, you can automatize this step as well by providing columns at model generation:
702
+
703
+ ```bash
704
+ $ enginery g:m Page column:name column:about:text
705
+ ```
706
+ now the "up" section will contain instructions to create the table and 2 columns.<br>
707
+ Note: if type omitted, String will be used.
708
+
709
+ When your migration are ready, run it using its serial number.
710
+
711
+ Serial number usually are printed when migration are generated.
712
+
713
+ You can also find it by listing available migrations:
714
+
715
+ ```bash
716
+ $ enginery m:list
717
+ # or just
718
+ $ enginery m:l
719
+ ```
720
+ this will display something like:
721
+
722
+ ```bash
723
+ ---=---
724
+ 1 : initializing-Page-model
725
+ created at : [timestamp]
726
+ last performed : [none|timestamp]
727
+ ---=---
728
+ ```
729
+ where "1" is the serial number and "initializing-Page-model" is the name.
730
+
731
+ Run migration up:
732
+
733
+ ```bash
734
+ enginery m:up 1
735
+ ```
736
+
737
+ Run migration down:
738
+
739
+ ```bash
740
+ enginery m:down 1
741
+ ```
742
+
743
+ ### Adding columns
744
+
745
+ To add some column to an existing model simply add new migration that will do this.
746
+
747
+ To generate a migration use the `m` notation followed by migration name, model and column(s):
748
+
749
+ ```bash
750
+ $ enginery m add-email model:Person column:email
751
+ ```
752
+ this will output something like:
753
+
754
+ ```bash
755
+ --- Person model - generating "add-email" migration ---
756
+
757
+ Serial Number: 2
758
+ ```
759
+
760
+ Run migration up:
761
+
762
+ ```bash
763
+ enginery m:up 2
764
+ ```
765
+ this will alter table by adding "email" column of "string" type.
766
+
767
+
768
+ Run migration down:
769
+
770
+ ```bash
771
+ enginery m:down 2
772
+ ```
773
+ this will drop "email" column.
774
+
775
+
776
+ ### Updating Columns
777
+
778
+ To modify some column type use `update_column` option followed by column name and new type:
779
+
780
+ ```bash
781
+ enginery m update-email model:Person update_column:email:text
782
+ ```
783
+ this will output something like:
784
+
785
+ ```bash
786
+ --- Person model - generating "update-email" migration ---
787
+
788
+ Serial Number: 3
789
+ ```
790
+
791
+ Run migration up:
792
+
793
+ ```bash
794
+ enginery m:up 3
795
+ ```
796
+ this will alter table by setting "email" type to "text".
797
+
798
+ Run migration down:
799
+
800
+ ```bash
801
+ enginery m:down 3
802
+ ```
803
+ this will alter table by reverting "email" type to "string".
804
+
805
+
806
+ ### Renaming Columns
807
+
808
+ To rename some column type use `rename_column` option followed by current column name and new name:
809
+
810
+ ```bash
811
+ enginery m rename-name model:Person rename_column:name:first_name
812
+ ```
813
+ this will output something like:
814
+
815
+ ```bash
816
+ --- Person model - generating "update-name" migration ---
817
+
818
+ Serial Number: 4
819
+ ```
820
+
821
+ Running migration up will rename "name" column to "first_name":
822
+ ```bash
823
+ enginery m:up 4
824
+ ```
825
+
826
+ Running migration down will rename "first_name" back to "name":
827
+ ```bash
828
+ enginery m:down 4
829
+ ```
830
+
831
+
832
+ ### Running Migrations
833
+
834
+ With Enginery you are free to choose what migration(s) to run in multiple ways.
835
+
836
+ Most obvious one is to provide the serial number of a single migration:
837
+
838
+ ```bash
839
+ $ enginery m:[up|down] 1
840
+ ```
841
+
842
+ When you need to run multiple migrations pass serial numbers separated by spaces:
843
+
844
+ ```bash
845
+ $ enginery m:[up|down] 1 4 6
846
+ ```
847
+ this will run 1st, 4th and 6th migrations.
848
+
849
+ When you need to run N to M migrations, use N-M notation:
850
+
851
+ ```bash
852
+ $ enginery m:[up|down] 2-6
853
+ ```
854
+ this will run 2nd to 6th migrations inclusive.
855
+
856
+
857
+ **Important Note:** `Enginery` will automatically set the running order depending on performed direction - ascending on "up" and descending on "down".
858
+
859
+ ```bash
860
+ $ enginery m:up 4 2 6
861
+ ```
862
+ performing order: 2 4 6
863
+
864
+
865
+ ```bash
866
+ $ enginery m:down 4 2 6
867
+ ```
868
+ performing order: 6 4 2
869
+
870
+
871
+ ```bash
872
+ $ enginery m:up 1-4
873
+ ```
874
+ performing order: 1 2 3 4
875
+
876
+
877
+ ```bash
878
+ $ enginery m:down 1-4
879
+ ```
880
+ performing order: 4 3 2 1
881
+
882
+
883
+ To **run all outstanding migrations** just do not pass any steps.
884
+
885
+ Perform UP all outstanding migrations:
886
+ ```bash
887
+ $ enginery m:up
888
+ ```
889
+
890
+ Perform DOWN all outstanding migrations:
891
+ ```bash
892
+ $ enginery m:down
893
+ ```
894
+
895
+
896
+ To list available migrations use `$ enginery m:list` or just `$ enginery m:l`
897
+
898
+
899
+ ### Force Running
900
+
901
+ `Enginery` will keep track of migrations already performed and wont run same migration twice.
902
+
903
+ However, sometimes you may need to run it anyway due to manual schema modification etc.
904
+
905
+ In such non-standard cases you can use `force` option:
906
+
907
+ ```bash
908
+ $ enginery m:up:force 1
909
+ ```
910
+
911
+ ### DataMapper Notes
912
+
913
+ With DataMapper ORM you have extra `rake` tasks "for free", like `dm:auto_migrate`, `dm:auto_upgrade`, `dm:auto_migrate:ModelName`, `dm:auto_upgrade:ModelName`
914
+
915
+ Use `$ rake -D` to list all tasks.
916
+
917
+ **Note on renaming columns:** as of 'dm-migrations' 1.2.0 renaming columns are broken for MySQL adapter. Master branch have it [fixed](https://github.com/datamapper/dm-migrations/blob/8bfcec08286a12ceee1bc3e5a01da3b5b7d4a74d/lib/dm-migrations/sql/table_modifier.rb#L35) but not yet released.
918
+
919
+ **[ [contents &uarr;](https://github.com/espresso/enginery#tutorial) ]**
920
+
921
+
922
+ ## Admin Interface
923
+
924
+ `Enginery` is using [`Rear`](https://github.com/espresso/rear) to build a admin interface for generated models.
925
+
926
+ Admin interface will be automatically mounted at `/admin`.
927
+
928
+ To mount it elsewhere, edit `config/config.yml` by updating `:admin_url` setting.
929
+
930
+ To disable admin interface simply remove `:admin_url` setting from `config/config.yml`.
931
+
932
+ **[ [contents &uarr;](https://github.com/espresso/enginery#tutorial) ]**
933
+
934
+
935
+ ## Contributing
936
+
937
+ - Fork Enginery repository
938
+ - optionally create a new branch
939
+ - make your changes
940
+ - submit a pull request
941
+
942
+ <hr>
943
+
944
+ <p>
945
+ Issues/Bugs:
946
+ <a href="https://github.com/espresso/enginery/issues">
947
+ github.com/espresso/enginery/issues</a>
948
+ </p>
949
+ <p>
950
+ Mailing List: <a href="https://groups.google.com/forum/?fromgroups#!forum/espresso-framework">
951
+ groups.google.com/.../espresso-framework</a>
952
+ </p>
953
+ <p>
954
+ IRC channel: #espressorb on irc.freenode.net
955
+ </p>
956
+
957
+ ### Author - [Walter Smith](https://github.com/waltee). License - [MIT](https://github.com/espresso/espresso/blob/master/LICENSE).