rabl 0.3.0 → 0.5.0
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/.gitignore +2 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +34 -0
- data/Gemfile +14 -1
- data/README.md +53 -4
- data/Rakefile +26 -1
- data/fixtures/ashared/NOTES +35 -0
- data/fixtures/ashared/README +35 -0
- data/fixtures/ashared/migrate/20111002092016_create_users.rb +15 -0
- data/fixtures/ashared/migrate/20111002092019_create_posts.rb +14 -0
- data/fixtures/ashared/migrate/20111002092024_create_phone_numbers.rb +16 -0
- data/fixtures/ashared/models/phone_number.rb +7 -0
- data/fixtures/ashared/models/post.rb +3 -0
- data/fixtures/ashared/models/user.rb +3 -0
- data/fixtures/ashared/views/layouts/application.html.erb +6 -0
- data/fixtures/ashared/views/posts/date.json.rabl +3 -0
- data/fixtures/ashared/views/posts/index.json.rabl +11 -0
- data/fixtures/ashared/views/posts/show.json.rabl +16 -0
- data/fixtures/ashared/views/users/index.rabl +3 -0
- data/fixtures/ashared/views/users/phone_number.rabl +6 -0
- data/fixtures/ashared/views/users/show.rabl +16 -0
- data/fixtures/padrino_test/.components +7 -0
- data/fixtures/padrino_test/.gitignore +7 -0
- data/fixtures/padrino_test/Gemfile +17 -0
- data/fixtures/padrino_test/Rakefile +3 -0
- data/fixtures/padrino_test/app/app.rb +59 -0
- data/fixtures/padrino_test/app/controllers/posts.rb +11 -0
- data/fixtures/padrino_test/app/controllers/users.rb +11 -0
- data/fixtures/padrino_test/app/helpers/posts_helper.rb +7 -0
- data/fixtures/padrino_test/app/helpers/users_helper.rb +7 -0
- data/fixtures/padrino_test/config.ru +9 -0
- data/fixtures/padrino_test/config/apps.rb +34 -0
- data/fixtures/padrino_test/config/boot.rb +29 -0
- data/fixtures/padrino_test/config/database.rb +43 -0
- data/fixtures/padrino_test/db/schema.rb +42 -0
- data/fixtures/padrino_test/public/favicon.ico +0 -0
- data/fixtures/padrino_test/test/app/controllers/posts_controller_test.rb +108 -0
- data/fixtures/padrino_test/test/app/controllers/users_controller_test.rb +87 -0
- data/fixtures/padrino_test/test/test.rake +18 -0
- data/fixtures/padrino_test/test/test_config.rb +18 -0
- data/fixtures/rails2/.gitignore +1 -0
- data/fixtures/rails2/Gemfile +8 -0
- data/fixtures/rails2/Rakefile +14 -0
- data/fixtures/rails2/app/controllers/application_controller.rb +10 -0
- data/fixtures/rails2/app/controllers/posts_controller.rb +15 -0
- data/fixtures/rails2/app/controllers/users_controller.rb +15 -0
- data/fixtures/rails2/config/boot.rb +129 -0
- data/fixtures/rails2/config/database.yml +16 -0
- data/fixtures/rails2/config/environment.rb +42 -0
- data/fixtures/rails2/config/environments/development.rb +17 -0
- data/fixtures/rails2/config/environments/production.rb +28 -0
- data/fixtures/rails2/config/environments/test.rb +28 -0
- data/fixtures/rails2/config/initializers/backtrace_silencers.rb +7 -0
- data/fixtures/rails2/config/initializers/cookie_verification_secret.rb +7 -0
- data/fixtures/rails2/config/initializers/inflections.rb +10 -0
- data/fixtures/rails2/config/initializers/mime_types.rb +5 -0
- data/fixtures/rails2/config/initializers/new_rails_defaults.rb +21 -0
- data/fixtures/rails2/config/initializers/session_store.rb +15 -0
- data/fixtures/rails2/config/locales/en.yml +5 -0
- data/fixtures/rails2/config/preinitializer.rb +20 -0
- data/fixtures/rails2/config/routes.rb +45 -0
- data/fixtures/rails2/db/schema.rb +40 -0
- data/fixtures/rails2/db/seeds.rb +7 -0
- data/fixtures/rails2/public/404.html +30 -0
- data/fixtures/rails2/public/422.html +30 -0
- data/fixtures/rails2/public/500.html +30 -0
- data/fixtures/rails2/public/favicon.ico +0 -0
- data/fixtures/rails2/public/images/rails.png +0 -0
- data/fixtures/rails2/public/index.html +275 -0
- data/fixtures/rails2/public/robots.txt +5 -0
- data/fixtures/rails2/script/about +4 -0
- data/fixtures/rails2/script/console +3 -0
- data/fixtures/rails2/script/dbconsole +3 -0
- data/fixtures/rails2/script/destroy +3 -0
- data/fixtures/rails2/script/generate +3 -0
- data/fixtures/rails2/script/performance/benchmarker +3 -0
- data/fixtures/rails2/script/performance/profiler +3 -0
- data/fixtures/rails2/script/plugin +3 -0
- data/fixtures/rails2/script/runner +3 -0
- data/fixtures/rails2/script/server +3 -0
- data/fixtures/rails2/test/functionals/posts_controller_test.rb +108 -0
- data/fixtures/rails2/test/functionals/users_controller_test.rb +87 -0
- data/fixtures/rails2/test/test_helper.rb +33 -0
- data/fixtures/rails3/.gitignore +4 -0
- data/fixtures/rails3/Gemfile +37 -0
- data/fixtures/rails3/Rakefile +12 -0
- data/fixtures/rails3/app/controllers/application_controller.rb +14 -0
- data/fixtures/rails3/app/controllers/posts_controller.rb +11 -0
- data/fixtures/rails3/app/controllers/users_controller.rb +11 -0
- data/fixtures/rails3/config.ru +4 -0
- data/fixtures/rails3/config/application.rb +42 -0
- data/fixtures/rails3/config/boot.rb +6 -0
- data/fixtures/rails3/config/database.yml +22 -0
- data/fixtures/rails3/config/environment.rb +5 -0
- data/fixtures/rails3/config/environments/development.rb +26 -0
- data/fixtures/rails3/config/environments/production.rb +49 -0
- data/fixtures/rails3/config/environments/test.rb +35 -0
- data/fixtures/rails3/config/initializers/backtrace_silencers.rb +7 -0
- data/fixtures/rails3/config/initializers/inflections.rb +10 -0
- data/fixtures/rails3/config/initializers/mime_types.rb +5 -0
- data/fixtures/rails3/config/initializers/secret_token.rb +7 -0
- data/fixtures/rails3/config/initializers/session_store.rb +8 -0
- data/fixtures/rails3/config/locales/en.yml +5 -0
- data/fixtures/rails3/config/routes.rb +61 -0
- data/fixtures/rails3/db/seeds.rb +7 -0
- data/fixtures/rails3/lib/tasks/.gitkeep +0 -0
- data/fixtures/rails3/public/404.html +26 -0
- data/fixtures/rails3/public/422.html +26 -0
- data/fixtures/rails3/public/500.html +26 -0
- data/fixtures/rails3/public/favicon.ico +0 -0
- data/fixtures/rails3/public/images/rails.png +0 -0
- data/fixtures/rails3/public/index.html +239 -0
- data/fixtures/rails3/public/robots.txt +5 -0
- data/fixtures/rails3/public/stylesheets/.gitkeep +0 -0
- data/fixtures/rails3/script/rails +6 -0
- data/fixtures/rails3/test/functional/posts_controller_test.rb +108 -0
- data/fixtures/rails3/test/functional/users_controller_test.rb +87 -0
- data/fixtures/rails3/test/test_helper.rb +26 -0
- data/fixtures/sinatra_test/Gemfile +13 -0
- data/fixtures/sinatra_test/Rakefile +6 -0
- data/fixtures/sinatra_test/app.rb +44 -0
- data/fixtures/sinatra_test/config.ru +7 -0
- data/fixtures/sinatra_test/test/functional/posts_controller_test.rb +108 -0
- data/fixtures/sinatra_test/test/functional/users_controller_test.rb +87 -0
- data/fixtures/sinatra_test/test/test_helper.rb +19 -0
- data/lib/rabl.rb +13 -1
- data/lib/rabl/builder.rb +14 -7
- data/lib/rabl/configuration.rb +41 -1
- data/lib/rabl/engine.rb +29 -19
- data/lib/rabl/helpers.rb +45 -18
- data/lib/rabl/template.rb +1 -1
- data/lib/rabl/version.rb +1 -1
- data/rabl.gemspec +6 -5
- data/test/builder_test.rb +4 -4
- data/test/configuration_test.rb +7 -22
- data/test/engine_test.rb +63 -44
- data/test/helpers_test.rb +68 -0
- data/test/integration/posts_controller_test.rb +108 -0
- data/test/integration/test_init.rb +35 -0
- data/test/integration/users_controller_test.rb +87 -0
- data/test/models/ormless.rb +2 -0
- data/test/models/user.rb +17 -6
- data/test/msgpack_engine_test.rb +332 -0
- data/test/silence.rb +21 -0
- data/test/teststrap.rb +22 -6
- metadata +160 -14
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
## 0.5.1 (Unreleased)
|
|
4
|
+
|
|
5
|
+
## 0.5.0
|
|
6
|
+
|
|
7
|
+
* Adds comprehensive fixture suite (padrino,rails2,rails3,sinatra)
|
|
8
|
+
* Travis CI Integration Testing
|
|
9
|
+
* Cleanup json configuration and related tests (Thanks mschulkind)
|
|
10
|
+
* Adds CHANGELOG to track changes
|
|
11
|
+
* Adds optional MessagePack format support (thanks byu)
|
|
12
|
+
* Explicit requires for ActiveSupport now in gemspec and lib
|
|
13
|
+
* Adds template support for regular (non-ORM) ruby objects (thanks plukevdh)
|
|
14
|
+
* Fixes bug with the child root not properly appearing in all cases
|
|
15
|
+
* Better stack traces by tracking source location in instance_eval (thanks skade)
|
|
16
|
+
* Fix issue with controller object detection failing in namespaces (thanks alunny)
|
|
17
|
+
* Fix ruby -w warnings (thanks achiu)
|
|
18
|
+
* Better partial implementation which passes options
|
|
19
|
+
* Better fetch_source implementation for Padrino (thanks skade)
|
|
20
|
+
* Better fetch_source implementation for Rails
|
|
21
|
+
* Added fetch_source implementation for Sinatra
|
|
22
|
+
* Lots of test refactorings / cleanup / improvement
|
|
23
|
+
* Code block name is now optional [Thanks brentmurphy]
|
|
24
|
+
|
|
25
|
+
## 0.3.0
|
|
26
|
+
|
|
27
|
+
* Use multi_json to handle JSON encoding (Thanks kossnocorp)
|
|
28
|
+
* Fixes unit tests with hash order on 1.8.7
|
|
29
|
+
|
|
30
|
+
## 0.2.8
|
|
31
|
+
|
|
32
|
+
* Fixes Rails 3.1 Compatibility (Thanks skyeagle)
|
|
33
|
+
* Fixes Ruby 1.8.6 Compatibility (Thanks Don)
|
|
34
|
+
* Adds much better riot unit testing (Thanks Achiu)
|
data/Gemfile
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
source
|
|
1
|
+
source :rubygems
|
|
2
2
|
|
|
3
3
|
# Specify your gem's dependencies in rabl.gemspec
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
|
+
gem "rake"
|
|
7
|
+
gem "i18n", '~> 0.6'
|
|
8
|
+
|
|
6
9
|
platforms :mri_18 do
|
|
7
10
|
gem 'SystemTimer'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# FIXTURES
|
|
14
|
+
group :test do
|
|
15
|
+
gem 'rack-test', :require => "rack/test"
|
|
16
|
+
gem 'activerecord', :require => "active_record"
|
|
17
|
+
gem 'sqlite3'
|
|
18
|
+
gem 'padrino', '>= 0.10.2'
|
|
19
|
+
gem 'sinatra', '>= 1.2.0'
|
|
20
|
+
gem 'rails', '>= 2.3.0'
|
|
8
21
|
end
|
data/README.md
CHANGED
|
@@ -26,6 +26,8 @@ or add to your Gemfile:
|
|
|
26
26
|
```ruby
|
|
27
27
|
# Gemfile
|
|
28
28
|
gem 'rabl'
|
|
29
|
+
# Also add either `json` or `yajl-ruby` as the JSON parser
|
|
30
|
+
gem 'yajl-ruby'
|
|
29
31
|
```
|
|
30
32
|
|
|
31
33
|
and run `bundle install` to install the dependency.
|
|
@@ -87,7 +89,9 @@ RABL is intended to require little to no configuration to get working. This is t
|
|
|
87
89
|
Rabl.configure do |config|
|
|
88
90
|
# Commented as these are the defaults
|
|
89
91
|
# config.json_engine = nil # Any multi\_json engines
|
|
92
|
+
# config.msgpack_engine = nil # Defaults to ::MessagePack
|
|
90
93
|
# config.include_json_root = true
|
|
94
|
+
# config.include_msgpack_root = true
|
|
91
95
|
# config.include_xml_root = false
|
|
92
96
|
# config.enable_json_callbacks = false
|
|
93
97
|
# config.xml_options = { :dasherize => true, :skip_types => false }
|
|
@@ -105,6 +109,32 @@ gem 'yajl-ruby', :require => "yajl"
|
|
|
105
109
|
|
|
106
110
|
and RABL will automatically start using that engine for encoding your JSON responses!
|
|
107
111
|
|
|
112
|
+
### Message Pack ###
|
|
113
|
+
|
|
114
|
+
Rabl also includes optional support for [Message Pack](http://www.msgpack.org/) serialization format using the [msgpack gem](https://rubygems.org/gems/msgpack).
|
|
115
|
+
To enable, include the msgpack gem in your project's Gemfile. Then use Rabl as normal with the `msgpack` format (akin to json and xml formats).
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
# Gemfile
|
|
119
|
+
gem 'msgpack', '~> 0.4.5'
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
One can additionally use a custom Message Pack implementation by setting the Rabl `msgpack_engine` configuration attribute. This custom message pack engine must conform to the MessagePack#pack method signature.
|
|
123
|
+
|
|
124
|
+
```ruby
|
|
125
|
+
class CustomEncodeEngine
|
|
126
|
+
def self.pack string
|
|
127
|
+
# Custom Encoding by your own engine.
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
Rabl.configure do |config|
|
|
132
|
+
config.msgpack_engine = CustomEncodeEngine
|
|
133
|
+
end
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
*NOTE*: Attempting to render the msgpack format without either including the msgpack gem or setting a `msgpack_engine` will cause an exception to be raised.
|
|
137
|
+
|
|
108
138
|
## Usage ##
|
|
109
139
|
|
|
110
140
|
### Object Assignment ###
|
|
@@ -234,6 +264,15 @@ code(:foo, :if => lambda { |m| m.has_foo? }) do |m|
|
|
|
234
264
|
end
|
|
235
265
|
```
|
|
236
266
|
|
|
267
|
+
or don't pass a name and have the code block merged into the response:
|
|
268
|
+
|
|
269
|
+
```ruby
|
|
270
|
+
code do |u|
|
|
271
|
+
{ :full_name => u.first_name + " " + u.last_name }
|
|
272
|
+
# => { full_name : "Bob Johnson" }
|
|
273
|
+
end
|
|
274
|
+
```
|
|
275
|
+
|
|
237
276
|
You can use custom "code" nodes to create flexible representations of a value utilizing all the data from the model.
|
|
238
277
|
|
|
239
278
|
### Partials ###
|
|
@@ -327,6 +366,12 @@ Check out the [Issues](https://github.com/nesquena/rabl/issues) tab for a full l
|
|
|
327
366
|
* Better Tilt template support (precompiling templates)
|
|
328
367
|
* Benchmarks and performance optimizations
|
|
329
368
|
|
|
369
|
+
## Continuous Integration
|
|
370
|
+
|
|
371
|
+
[](http://travis-ci.org/nesquena/rabl)
|
|
372
|
+
|
|
373
|
+
CI is hosted by [travis-ci.org](http://travis-ci.org).
|
|
374
|
+
|
|
330
375
|
## Authors and Contributors ##
|
|
331
376
|
|
|
332
377
|
Thanks to [Miso](http://gomiso.com) for allowing me to create this for our applications and release this project!
|
|
@@ -334,12 +379,16 @@ Thanks to [Miso](http://gomiso.com) for allowing me to create this for our appli
|
|
|
334
379
|
* [Nathan Esquenazi](https://github.com/nesquena) - Creator of the project
|
|
335
380
|
* [Arthur Chiu](https://github.com/achiu) - Core Maintainer, Riot Testing Guru
|
|
336
381
|
* [Tim Lee](https://github.com/timothy1ee) - RABL is an awesome name and was chosen by the Miso CTO.
|
|
337
|
-
* [Rick Thomas](https://github.com/rickthomasjr) - Added options
|
|
338
|
-
* [Marjun](https://github.com/mpagalan) - Added xml option configurations
|
|
382
|
+
* [Rick Thomas](https://github.com/rickthomasjr) - Added options for extends and Sinatra testing
|
|
339
383
|
* [Chris Kimpton](https://github.com/kimptoc) - Helping with documentation and wiki
|
|
384
|
+
* [Marjun](https://github.com/mpagalan) - Added xml option configurations
|
|
385
|
+
* [Anton Orel](https://github.com/skyeagle) - Added Rails 3.1 compatibility
|
|
340
386
|
* [Sasha Koss](https://github.com/kossnocorp) - Added multi_json support
|
|
387
|
+
* [Matthew Schulkind](https://github.com/mschulkind) - Cleanup of configuration and tests
|
|
388
|
+
* [Luke van der Hoeven](https://github.com/plukevdh) - Support non-ORM objects in templates
|
|
341
389
|
|
|
342
|
-
|
|
390
|
+
and many more contributors listed in the [CHANGELOG](https://github.com/nesquena/rabl/blob/master/CHANGELOG.md).
|
|
391
|
+
Please fork and contribute, any help in making this project better is appreciated!
|
|
343
392
|
|
|
344
393
|
## Inspirations ##
|
|
345
394
|
|
|
@@ -357,4 +406,4 @@ See the [examples](https://github.com/nesquena/rabl/tree/master/examples) direct
|
|
|
357
406
|
|
|
358
407
|
## Copyright
|
|
359
408
|
|
|
360
|
-
Copyright © 2011 Nathan Esquenazi. See [MIT-LICENSE](https://github.com/nesquena/rabl/blob/master/MIT-LICENSE) for details.
|
|
409
|
+
Copyright © 2011 Nathan Esquenazi. See [MIT-LICENSE](https://github.com/nesquena/rabl/blob/master/MIT-LICENSE) for details.
|
data/Rakefile
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
|
+
include Rake::DSL
|
|
2
|
+
|
|
1
3
|
require 'bundler'
|
|
2
4
|
Bundler::GemHelper.install_tasks
|
|
3
5
|
|
|
4
6
|
require 'rake/testtask'
|
|
5
7
|
Rake::TestTask.new(:test) do |test|
|
|
6
8
|
test.libs << 'lib' << 'test'
|
|
7
|
-
test.pattern = 'test
|
|
9
|
+
test.pattern = 'test/*_test.rb'
|
|
10
|
+
test.warning = true
|
|
8
11
|
test.verbose = true
|
|
9
12
|
test.ruby_opts = ['-rubygems']
|
|
10
13
|
end
|
|
14
|
+
|
|
15
|
+
desc "Prepares the fixtures for being tested by installing dependencies"
|
|
16
|
+
task "test:setup" do
|
|
17
|
+
Dir[File.dirname(__FILE__) + "/fixtures/{padrino_test,sinatra_test,rails2,rails3}"].each do |fixture|
|
|
18
|
+
puts "\n*** Setting up for #{File.basename(fixture)} tests ***\n"
|
|
19
|
+
`export BUNDLE_GEMFILE=#{fixture}/Gemfile` if ENV['TRAVIS']
|
|
20
|
+
puts `cd #{fixture}; bundle install;`
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
desc "Executes the fixture tests"
|
|
25
|
+
task "test:fixtures" do
|
|
26
|
+
Dir[File.dirname(__FILE__) + "/fixtures/{padrino_test,sinatra_test,rails2,rails3}"].each do |fixture|
|
|
27
|
+
puts "\n*** Running tests for #{File.basename(fixture)}... ***\n"
|
|
28
|
+
puts `cd #{fixture}; bundle check; bundle exec rake test:rabl`
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
task "test:full" => [:test, "test:fixtures"]
|
|
33
|
+
|
|
34
|
+
desc "Run tests for rabl"
|
|
35
|
+
task :default => :test
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Padrino
|
|
2
|
+
|
|
3
|
+
cd fixtures/padrino_test
|
|
4
|
+
ln -s "../ashared/models" models
|
|
5
|
+
ln -s "../../ashared/views/" app/views
|
|
6
|
+
ln -s "../../ashared/migrate" db/migrate
|
|
7
|
+
ln ../../test/integration/posts_controller_test.rb test/app/controllers/posts_controller_test.rb
|
|
8
|
+
ln ../../test/integration/users_controller_test.rb test/app/controllers/users_controller_test.rb
|
|
9
|
+
|
|
10
|
+
# Rails 2
|
|
11
|
+
|
|
12
|
+
cd fixtures/rails2
|
|
13
|
+
ln -s "../../ashared/models" app/models
|
|
14
|
+
ln -s "../../ashared/views/" app/views
|
|
15
|
+
ln -s "../../ashared/migrate" db/migrate
|
|
16
|
+
ln ../../test/integration/posts_controller_test.rb test/functionals/posts_controller_test.rb
|
|
17
|
+
ln ../../test/integration/users_controller_test.rb test/functionals/users_controller_test.rb
|
|
18
|
+
|
|
19
|
+
# Rails 3
|
|
20
|
+
|
|
21
|
+
cd fixtures/rails3
|
|
22
|
+
ln -s "../../ashared/models" app/models
|
|
23
|
+
ln -s "../../ashared/views/" app/views
|
|
24
|
+
ln -s "../../ashared/migrate" db/migrate
|
|
25
|
+
ln ../../test/integration/posts_controller_test.rb test/functional/posts_controller_test.rb
|
|
26
|
+
ln ../../test/integration/users_controller_test.rb test/functional/users_controller_test.rb
|
|
27
|
+
|
|
28
|
+
# Sinatra
|
|
29
|
+
|
|
30
|
+
cd fixtures/sinatra_test
|
|
31
|
+
ln -s "../ashared/models" models
|
|
32
|
+
ln -s "../ashared/views/" views
|
|
33
|
+
ln -s "../../ashared/migrate" db/migrate
|
|
34
|
+
ln ../../test/integration/posts_controller_test.rb test/functional/posts_controller_test.rb
|
|
35
|
+
ln ../../test/integration/users_controller_test.rb test/functional/users_controller_test.rb
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Fixtures to test RABL:
|
|
2
|
+
|
|
3
|
+
models:
|
|
4
|
+
|
|
5
|
+
user
|
|
6
|
+
t.string :username
|
|
7
|
+
t.string :email
|
|
8
|
+
t.string :location
|
|
9
|
+
t.boolean :is_admin
|
|
10
|
+
t.timestamps
|
|
11
|
+
posts
|
|
12
|
+
t.integer :user_id
|
|
13
|
+
t.string :title
|
|
14
|
+
t.text :body
|
|
15
|
+
t.timestamps
|
|
16
|
+
phone_number
|
|
17
|
+
t.integer :user_id
|
|
18
|
+
t.boolean :is_primary
|
|
19
|
+
t.string :area_code
|
|
20
|
+
t.string :prefix
|
|
21
|
+
t.string :suffix
|
|
22
|
+
t.string :name
|
|
23
|
+
|
|
24
|
+
controllers:
|
|
25
|
+
|
|
26
|
+
users
|
|
27
|
+
posts
|
|
28
|
+
|
|
29
|
+
layouts:
|
|
30
|
+
|
|
31
|
+
application.html.haml
|
|
32
|
+
|
|
33
|
+
views:
|
|
34
|
+
posts (index, show, date)
|
|
35
|
+
users (index, show)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class CreateUsers < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table :users do |t|
|
|
4
|
+
t.string :username
|
|
5
|
+
t.string :email
|
|
6
|
+
t.string :location
|
|
7
|
+
t.boolean :is_admin
|
|
8
|
+
t.timestamps
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.down
|
|
13
|
+
drop_table :users
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class CreatePhoneNumbers < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table :phone_numbers do |t|
|
|
4
|
+
t.integer :user_id
|
|
5
|
+
t.boolean :is_primary
|
|
6
|
+
t.string :area_code
|
|
7
|
+
t.string :prefix
|
|
8
|
+
t.string :suffix
|
|
9
|
+
t.string :name
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.down
|
|
14
|
+
drop_table :phone_numbers
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
object @post
|
|
2
|
+
|
|
3
|
+
attributes :title, :body
|
|
4
|
+
attributes :created_at => :posted_at
|
|
5
|
+
|
|
6
|
+
child :user do
|
|
7
|
+
extends "users/show"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
glue :user do
|
|
11
|
+
attributes :username => :author_name
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
code(:created_date) do |p|
|
|
15
|
+
partial("posts/date", :object => p.created_at)
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
object @user => :person
|
|
2
|
+
|
|
3
|
+
attributes :username, :email, :location
|
|
4
|
+
attributes :created_at => :registered_at
|
|
5
|
+
|
|
6
|
+
node :role do |user|
|
|
7
|
+
user.is_admin ? 'admin' : 'normal'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
child :phone_numbers => :pnumbers do
|
|
11
|
+
extends "users/phone_number"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
node :node_numbers do |u|
|
|
15
|
+
partial("users/phone_number", :object => u.phone_numbers)
|
|
16
|
+
end
|