rabl 0.13.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (303) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +35 -0
  3. data/CONTRIBUTING.md +2 -2
  4. data/README.md +16 -11
  5. data/lib/rabl/builder.rb +29 -17
  6. data/lib/rabl/cache_engine.rb +30 -1
  7. data/lib/rabl/configuration.rb +3 -1
  8. data/lib/rabl/digestor/rails3.rb +12 -0
  9. data/lib/rabl/digestor/rails41.rb +12 -0
  10. data/lib/rabl/digestor/rails5.rb +6 -0
  11. data/lib/rabl/digestor.rb +5 -37
  12. data/lib/rabl/engine.rb +30 -11
  13. data/lib/rabl/helpers.rb +7 -3
  14. data/lib/rabl/railtie.rb +18 -1
  15. data/lib/rabl/template.rb +21 -1
  16. data/lib/rabl/version.rb +1 -1
  17. data/lib/rabl.rb +5 -5
  18. metadata +15 -298
  19. data/.gitignore +0 -8
  20. data/.travis.yml +0 -15
  21. data/Gemfile +0 -27
  22. data/Rakefile +0 -54
  23. data/examples/base.json.rabl +0 -8
  24. data/examples/demo.json.rabl +0 -42
  25. data/examples/inherited.json.rabl +0 -11
  26. data/fixtures/ashared/NOTES +0 -44
  27. data/fixtures/ashared/README +0 -39
  28. data/fixtures/ashared/migrate/20111002092016_create_users.rb +0 -15
  29. data/fixtures/ashared/migrate/20111002092019_create_posts.rb +0 -14
  30. data/fixtures/ashared/migrate/20111002092024_create_phone_numbers.rb +0 -16
  31. data/fixtures/ashared/models/phone_number.rb +0 -7
  32. data/fixtures/ashared/models/post.rb +0 -3
  33. data/fixtures/ashared/models/user.rb +0 -3
  34. data/fixtures/ashared/views/layouts/application.html.erb +0 -9
  35. data/fixtures/ashared/views/posts/_show_footer_script.js.erb +0 -1
  36. data/fixtures/ashared/views/posts/date.rabl +0 -3
  37. data/fixtures/ashared/views/posts/index.rabl +0 -12
  38. data/fixtures/ashared/views/posts/show.rabl +0 -17
  39. data/fixtures/ashared/views/users/index.json.rabl +0 -3
  40. data/fixtures/ashared/views/users/phone_number.json.rabl +0 -6
  41. data/fixtures/ashared/views/users/show.json.rabl +0 -16
  42. data/fixtures/ashared/views_rails_3/layouts/application.html.erb +0 -13
  43. data/fixtures/ashared/views_rails_3/posts/_show_footer_script.js.erb +0 -1
  44. data/fixtures/ashared/views_rails_3/posts/date.rabl +0 -3
  45. data/fixtures/ashared/views_rails_3/posts/index.html.erb +0 -3
  46. data/fixtures/ashared/views_rails_3/posts/index.rabl +0 -12
  47. data/fixtures/ashared/views_rails_3/posts/renderer.rabl +0 -8
  48. data/fixtures/ashared/views_rails_3/posts/renderer_partial.rabl +0 -4
  49. data/fixtures/ashared/views_rails_3/posts/show.html.erb +0 -3
  50. data/fixtures/ashared/views_rails_3/posts/show.rabl +0 -25
  51. data/fixtures/ashared/views_rails_3/posts/show.rabl_test_v1.rabl +0 -7
  52. data/fixtures/ashared/views_rails_3/users/index.json.rabl +0 -3
  53. data/fixtures/ashared/views_rails_3/users/phone_number.json.rabl +0 -8
  54. data/fixtures/ashared/views_rails_3/users/phone_number.xml.rabl +0 -8
  55. data/fixtures/ashared/views_rails_3/users/show.json.rabl +0 -16
  56. data/fixtures/ashared/views_rails_3/users/show.rabl_test_v1.rabl +0 -3
  57. data/fixtures/padrino_test/.components +0 -7
  58. data/fixtures/padrino_test/.gitignore +0 -7
  59. data/fixtures/padrino_test/Gemfile +0 -17
  60. data/fixtures/padrino_test/Rakefile +0 -3
  61. data/fixtures/padrino_test/app/app.rb +0 -31
  62. data/fixtures/padrino_test/app/controllers/posts.rb +0 -11
  63. data/fixtures/padrino_test/app/controllers/users.rb +0 -11
  64. data/fixtures/padrino_test/app/helpers/posts_helper.rb +0 -7
  65. data/fixtures/padrino_test/app/helpers/users_helper.rb +0 -7
  66. data/fixtures/padrino_test/config/apps.rb +0 -34
  67. data/fixtures/padrino_test/config/boot.rb +0 -29
  68. data/fixtures/padrino_test/config/database.rb +0 -43
  69. data/fixtures/padrino_test/config.ru +0 -9
  70. data/fixtures/padrino_test/db/schema.rb +0 -42
  71. data/fixtures/padrino_test/public/favicon.ico +0 -0
  72. data/fixtures/padrino_test/test/app/controllers/posts_controller_test.rb +0 -108
  73. data/fixtures/padrino_test/test/app/controllers/users_controller_test.rb +0 -87
  74. data/fixtures/padrino_test/test/test.rake +0 -18
  75. data/fixtures/padrino_test/test/test_config.rb +0 -18
  76. data/fixtures/rails2/.gitignore +0 -1
  77. data/fixtures/rails2/Gemfile +0 -10
  78. data/fixtures/rails2/Rakefile +0 -14
  79. data/fixtures/rails2/app/controllers/application_controller.rb +0 -10
  80. data/fixtures/rails2/app/controllers/posts_controller.rb +0 -15
  81. data/fixtures/rails2/app/controllers/users_controller.rb +0 -15
  82. data/fixtures/rails2/app/helpers/application_helper.rb +0 -2
  83. data/fixtures/rails2/app/helpers/posts_helper.rb +0 -2
  84. data/fixtures/rails2/app/helpers/users_helper.rb +0 -2
  85. data/fixtures/rails2/config/boot.rb +0 -129
  86. data/fixtures/rails2/config/database.yml +0 -16
  87. data/fixtures/rails2/config/environment.rb +0 -64
  88. data/fixtures/rails2/config/environments/development.rb +0 -17
  89. data/fixtures/rails2/config/environments/production.rb +0 -28
  90. data/fixtures/rails2/config/environments/test.rb +0 -28
  91. data/fixtures/rails2/config/initializers/backtrace_silencers.rb +0 -7
  92. data/fixtures/rails2/config/initializers/cookie_verification_secret.rb +0 -7
  93. data/fixtures/rails2/config/initializers/inflections.rb +0 -10
  94. data/fixtures/rails2/config/initializers/mime_types.rb +0 -5
  95. data/fixtures/rails2/config/initializers/new_rails_defaults.rb +0 -21
  96. data/fixtures/rails2/config/initializers/session_store.rb +0 -15
  97. data/fixtures/rails2/config/locales/en.yml +0 -5
  98. data/fixtures/rails2/config/preinitializer.rb +0 -20
  99. data/fixtures/rails2/config/routes.rb +0 -45
  100. data/fixtures/rails2/db/schema.rb +0 -40
  101. data/fixtures/rails2/db/seeds.rb +0 -7
  102. data/fixtures/rails2/public/404.html +0 -30
  103. data/fixtures/rails2/public/422.html +0 -30
  104. data/fixtures/rails2/public/500.html +0 -30
  105. data/fixtures/rails2/public/favicon.ico +0 -0
  106. data/fixtures/rails2/public/images/rails.png +0 -0
  107. data/fixtures/rails2/public/index.html +0 -275
  108. data/fixtures/rails2/public/robots.txt +0 -5
  109. data/fixtures/rails2/script/about +0 -4
  110. data/fixtures/rails2/script/console +0 -3
  111. data/fixtures/rails2/script/dbconsole +0 -3
  112. data/fixtures/rails2/script/destroy +0 -3
  113. data/fixtures/rails2/script/generate +0 -3
  114. data/fixtures/rails2/script/performance/benchmarker +0 -3
  115. data/fixtures/rails2/script/performance/profiler +0 -3
  116. data/fixtures/rails2/script/plugin +0 -3
  117. data/fixtures/rails2/script/runner +0 -3
  118. data/fixtures/rails2/script/server +0 -3
  119. data/fixtures/rails2/test/functionals/posts_controller_test.rb +0 -108
  120. data/fixtures/rails2/test/functionals/users_controller_test.rb +0 -87
  121. data/fixtures/rails2/test/test_helper.rb +0 -33
  122. data/fixtures/rails3/.gitignore +0 -4
  123. data/fixtures/rails3/Gemfile +0 -37
  124. data/fixtures/rails3/Rakefile +0 -12
  125. data/fixtures/rails3/app/controllers/application_controller.rb +0 -14
  126. data/fixtures/rails3/app/controllers/posts_controller.rb +0 -11
  127. data/fixtures/rails3/app/controllers/users_controller.rb +0 -11
  128. data/fixtures/rails3/config/application.rb +0 -42
  129. data/fixtures/rails3/config/boot.rb +0 -6
  130. data/fixtures/rails3/config/database.yml +0 -22
  131. data/fixtures/rails3/config/environment.rb +0 -5
  132. data/fixtures/rails3/config/environments/development.rb +0 -26
  133. data/fixtures/rails3/config/environments/production.rb +0 -49
  134. data/fixtures/rails3/config/environments/test.rb +0 -35
  135. data/fixtures/rails3/config/initializers/backtrace_silencers.rb +0 -7
  136. data/fixtures/rails3/config/initializers/inflections.rb +0 -10
  137. data/fixtures/rails3/config/initializers/mime_types.rb +0 -5
  138. data/fixtures/rails3/config/initializers/secret_token.rb +0 -7
  139. data/fixtures/rails3/config/initializers/session_store.rb +0 -8
  140. data/fixtures/rails3/config/locales/en.yml +0 -5
  141. data/fixtures/rails3/config/routes.rb +0 -61
  142. data/fixtures/rails3/config.ru +0 -4
  143. data/fixtures/rails3/db/seeds.rb +0 -7
  144. data/fixtures/rails3/lib/tasks/.gitkeep +0 -0
  145. data/fixtures/rails3/public/404.html +0 -26
  146. data/fixtures/rails3/public/422.html +0 -26
  147. data/fixtures/rails3/public/500.html +0 -26
  148. data/fixtures/rails3/public/favicon.ico +0 -0
  149. data/fixtures/rails3/public/images/rails.png +0 -0
  150. data/fixtures/rails3/public/index.html +0 -239
  151. data/fixtures/rails3/public/robots.txt +0 -5
  152. data/fixtures/rails3/public/stylesheets/.gitkeep +0 -0
  153. data/fixtures/rails3/script/rails +0 -6
  154. data/fixtures/rails3/test/functional/posts_controller_test.rb +0 -108
  155. data/fixtures/rails3/test/functional/users_controller_test.rb +0 -87
  156. data/fixtures/rails3/test/test_helper.rb +0 -26
  157. data/fixtures/rails3_2/.gitignore +0 -15
  158. data/fixtures/rails3_2/Gemfile +0 -40
  159. data/fixtures/rails3_2/README.rdoc +0 -261
  160. data/fixtures/rails3_2/Rakefile +0 -12
  161. data/fixtures/rails3_2/app/assets/images/rails.png +0 -0
  162. data/fixtures/rails3_2/app/assets/javascripts/application.js +0 -15
  163. data/fixtures/rails3_2/app/assets/javascripts/posts.js.coffee +0 -3
  164. data/fixtures/rails3_2/app/assets/javascripts/users.js.coffee +0 -3
  165. data/fixtures/rails3_2/app/assets/stylesheets/application.css +0 -13
  166. data/fixtures/rails3_2/app/assets/stylesheets/posts.css.scss +0 -3
  167. data/fixtures/rails3_2/app/assets/stylesheets/users.css.scss +0 -3
  168. data/fixtures/rails3_2/app/controllers/application_controller.rb +0 -14
  169. data/fixtures/rails3_2/app/controllers/posts_controller.rb +0 -16
  170. data/fixtures/rails3_2/app/controllers/users_controller.rb +0 -11
  171. data/fixtures/rails3_2/app/helpers/application_helper.rb +0 -5
  172. data/fixtures/rails3_2/app/helpers/posts_helper.rb +0 -2
  173. data/fixtures/rails3_2/app/helpers/users_helper.rb +0 -2
  174. data/fixtures/rails3_2/app/mailers/.gitkeep +0 -0
  175. data/fixtures/rails3_2/config/application.rb +0 -59
  176. data/fixtures/rails3_2/config/boot.rb +0 -6
  177. data/fixtures/rails3_2/config/database.yml +0 -25
  178. data/fixtures/rails3_2/config/environment.rb +0 -5
  179. data/fixtures/rails3_2/config/environments/development.rb +0 -37
  180. data/fixtures/rails3_2/config/environments/production.rb +0 -67
  181. data/fixtures/rails3_2/config/environments/test.rb +0 -37
  182. data/fixtures/rails3_2/config/initializers/backtrace_silencers.rb +0 -7
  183. data/fixtures/rails3_2/config/initializers/inflections.rb +0 -15
  184. data/fixtures/rails3_2/config/initializers/mime_types.rb +0 -7
  185. data/fixtures/rails3_2/config/initializers/secret_token.rb +0 -7
  186. data/fixtures/rails3_2/config/initializers/session_store.rb +0 -8
  187. data/fixtures/rails3_2/config/initializers/wrap_parameters.rb +0 -14
  188. data/fixtures/rails3_2/config/locales/en.yml +0 -5
  189. data/fixtures/rails3_2/config/routes.rb +0 -64
  190. data/fixtures/rails3_2/config.ru +0 -4
  191. data/fixtures/rails3_2/db/schema.rb +0 -42
  192. data/fixtures/rails3_2/db/seeds.rb +0 -7
  193. data/fixtures/rails3_2/doc/README_FOR_APP +0 -2
  194. data/fixtures/rails3_2/lib/assets/.gitkeep +0 -0
  195. data/fixtures/rails3_2/lib/tasks/.gitkeep +0 -0
  196. data/fixtures/rails3_2/log/.gitkeep +0 -0
  197. data/fixtures/rails3_2/public/404.html +0 -26
  198. data/fixtures/rails3_2/public/422.html +0 -26
  199. data/fixtures/rails3_2/public/500.html +0 -25
  200. data/fixtures/rails3_2/public/favicon.ico +0 -0
  201. data/fixtures/rails3_2/public/index.html +0 -241
  202. data/fixtures/rails3_2/public/robots.txt +0 -5
  203. data/fixtures/rails3_2/script/rails +0 -6
  204. data/fixtures/rails3_2/test/fixtures/phone_numbers.yml +0 -11
  205. data/fixtures/rails3_2/test/fixtures/posts.yml +0 -11
  206. data/fixtures/rails3_2/test/fixtures/users.yml +0 -11
  207. data/fixtures/rails3_2/test/functional/posts_controller_test.rb +0 -263
  208. data/fixtures/rails3_2/test/functional/users_controller_test.rb +0 -87
  209. data/fixtures/rails3_2/test/integration/.gitkeep +0 -0
  210. data/fixtures/rails3_2/test/performance/browsing_test.rb +0 -12
  211. data/fixtures/rails3_2/test/test_helper.rb +0 -26
  212. data/fixtures/rails3_2/test/unit/helpers/posts_helper_test.rb +0 -4
  213. data/fixtures/rails3_2/test/unit/helpers/users_helper_test.rb +0 -4
  214. data/fixtures/rails3_2/test/unit/phone_number_test.rb +0 -7
  215. data/fixtures/rails3_2/test/unit/post_test.rb +0 -7
  216. data/fixtures/rails3_2/test/unit/user_test.rb +0 -7
  217. data/fixtures/rails3_2/vendor/assets/javascripts/.gitkeep +0 -0
  218. data/fixtures/rails3_2/vendor/assets/stylesheets/.gitkeep +0 -0
  219. data/fixtures/rails3_2/vendor/plugins/.gitkeep +0 -0
  220. data/fixtures/rails4/.gitignore +0 -16
  221. data/fixtures/rails4/Gemfile +0 -49
  222. data/fixtures/rails4/README.rdoc +0 -28
  223. data/fixtures/rails4/Rakefile +0 -11
  224. data/fixtures/rails4/app/assets/javascripts/application.js +0 -16
  225. data/fixtures/rails4/app/assets/stylesheets/application.css +0 -13
  226. data/fixtures/rails4/app/controllers/application_controller.rb +0 -5
  227. data/fixtures/rails4/app/controllers/concerns/.keep +0 -0
  228. data/fixtures/rails4/app/controllers/posts_controller.rb +0 -16
  229. data/fixtures/rails4/app/controllers/users_controller.rb +0 -11
  230. data/fixtures/rails4/app/helpers/application_helper.rb +0 -5
  231. data/fixtures/rails4/app/mailers/.keep +0 -0
  232. data/fixtures/rails4/bin/bundle +0 -3
  233. data/fixtures/rails4/bin/rails +0 -4
  234. data/fixtures/rails4/bin/rake +0 -4
  235. data/fixtures/rails4/config/application.rb +0 -23
  236. data/fixtures/rails4/config/boot.rb +0 -4
  237. data/fixtures/rails4/config/database.yml +0 -25
  238. data/fixtures/rails4/config/environment.rb +0 -5
  239. data/fixtures/rails4/config/environments/development.rb +0 -29
  240. data/fixtures/rails4/config/environments/production.rb +0 -80
  241. data/fixtures/rails4/config/environments/test.rb +0 -36
  242. data/fixtures/rails4/config/initializers/backtrace_silencers.rb +0 -7
  243. data/fixtures/rails4/config/initializers/filter_parameter_logging.rb +0 -4
  244. data/fixtures/rails4/config/initializers/inflections.rb +0 -16
  245. data/fixtures/rails4/config/initializers/mime_types.rb +0 -7
  246. data/fixtures/rails4/config/initializers/secret_token.rb +0 -12
  247. data/fixtures/rails4/config/initializers/session_store.rb +0 -3
  248. data/fixtures/rails4/config/initializers/wrap_parameters.rb +0 -14
  249. data/fixtures/rails4/config/locales/en.yml +0 -23
  250. data/fixtures/rails4/config/routes.rb +0 -55
  251. data/fixtures/rails4/config.ru +0 -4
  252. data/fixtures/rails4/db/seeds.rb +0 -7
  253. data/fixtures/rails4/lib/assets/.keep +0 -0
  254. data/fixtures/rails4/lib/tasks/.keep +0 -0
  255. data/fixtures/rails4/log/.keep +0 -0
  256. data/fixtures/rails4/public/404.html +0 -58
  257. data/fixtures/rails4/public/422.html +0 -58
  258. data/fixtures/rails4/public/500.html +0 -57
  259. data/fixtures/rails4/public/favicon.ico +0 -0
  260. data/fixtures/rails4/public/robots.txt +0 -5
  261. data/fixtures/rails4/test/controllers/.keep +0 -0
  262. data/fixtures/rails4/test/fixtures/.keep +0 -0
  263. data/fixtures/rails4/test/functional/posts_controller_test.rb +0 -248
  264. data/fixtures/rails4/test/functional/users_controller_test.rb +0 -87
  265. data/fixtures/rails4/test/helpers/.keep +0 -0
  266. data/fixtures/rails4/test/integration/.keep +0 -0
  267. data/fixtures/rails4/test/mailers/.keep +0 -0
  268. data/fixtures/rails4/test/models/.keep +0 -0
  269. data/fixtures/rails4/test/test_helper.rb +0 -26
  270. data/fixtures/rails4/vendor/assets/javascripts/.keep +0 -0
  271. data/fixtures/rails4/vendor/assets/stylesheets/.keep +0 -0
  272. data/fixtures/sinatra_test/Gemfile +0 -13
  273. data/fixtures/sinatra_test/Rakefile +0 -6
  274. data/fixtures/sinatra_test/app.rb +0 -55
  275. data/fixtures/sinatra_test/config.ru +0 -7
  276. data/fixtures/sinatra_test/test/functional/posts_controller_test.rb +0 -108
  277. data/fixtures/sinatra_test/test/functional/users_controller_test.rb +0 -87
  278. data/fixtures/sinatra_test/test/test_helper.rb +0 -19
  279. data/rabl.gemspec +0 -36
  280. data/test/bson_engine_test.rb +0 -310
  281. data/test/builder_test.rb +0 -362
  282. data/test/configuration_test.rb +0 -91
  283. data/test/engine_test.rb +0 -835
  284. data/test/helpers_test.rb +0 -136
  285. data/test/integration/posts_controller_test.rb +0 -108
  286. data/test/integration/rails3_2/posts_controller_test.rb +0 -263
  287. data/test/integration/rails3_2/users_controller_test.rb +0 -87
  288. data/test/integration/rails4/posts_controller_test.rb +0 -248
  289. data/test/integration/rails4/users_controller_test.rb +0 -87
  290. data/test/integration/test_init.rb +0 -36
  291. data/test/integration/users_controller_test.rb +0 -87
  292. data/test/models/ormless.rb +0 -3
  293. data/test/models/user.rb +0 -34
  294. data/test/msgpack_engine_test.rb +0 -312
  295. data/test/multi_builder_test.rb +0 -69
  296. data/test/partials_test.rb +0 -205
  297. data/test/plist_engine_test.rb +0 -308
  298. data/test/renderer_test.rb +0 -390
  299. data/test/silence.rb +0 -21
  300. data/test/template_test.rb +0 -63
  301. data/test/teststrap.rb +0 -37
  302. data/test/xml_test.rb +0 -297
  303. data/test.watchr +0 -47
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9181c1a232aab327e58bd686eb3cf14403e6aac9
4
- data.tar.gz: 3e2f0d536f6752cb575e5843709be0b40f8bd09a
2
+ SHA256:
3
+ metadata.gz: 0fb8310726d92ea377d5be433f173207997ea6cc7e3a4a3faefe71b7de5b5df2
4
+ data.tar.gz: e75ceb99863c03bff3093983da87c83e79a02c8f1d74cc2ca6dd6c4755fd8404
5
5
  SHA512:
6
- metadata.gz: 8ea05c8211d750c882c4b0fa6e29a20b56e4ebfcff23e12a2af18e0f50302b191be374a76eace11ed46a787ae702cb7ff5eb7ef659a6d7096db2823451c5b6d1
7
- data.tar.gz: c8634ea3cfbbc11e131b484e598326888c81f15f2a304caf06ec786f8a3ab5d72cfb77f88fc47b4fd34d1dc595c3468ef5c460d44effc949c352dd6ca23d7398
6
+ metadata.gz: 2fc9988668325cc4dd12e75a774d14f6be984a83d2ed043712536d3753d6ae70b71d09d6784120f82b2c75809ed8d446c1965e56fcac1ddbc9c4bace259fc342
7
+ data.tar.gz: 58a0105a9fdf9e016ddee845ca3a4fde7fb0944a1792230f878ce380d2b9778e8d82da3722ba89d1702442e3d539c4db071ff56e201f596625d12f9ffaa90585
data/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.15.0 (December 30, 2021)
4
+
5
+ * Support for Rails 7 (@tagliala)
6
+ * Improvements to unit testing
7
+ * Miscellanious other bug fixes
8
+
9
+ ## 0.14.5 (May 29th, 2021)
10
+
11
+ * Restrict and validate the `to_***` methods available within engine (Brian McFadden)
12
+
13
+ ## 0.14.4 (April 1st, 2021)
14
+
15
+ * Test against latest Ruby versions
16
+ * Exclude yarn lock
17
+ * Remove non-required files from the .gem
18
+
19
+ ## 0.14.3 (April 22nd, 2020)
20
+
21
+ * Fix regression on Rails 4.2 (@tagliala)
22
+
23
+ ## 0.14.2 (September 10th, 2019)
24
+
25
+ * Made Rails 6 compatible (@jpawlyn)
26
+ * Drop EOL'd property from gemspec (@olleolleolle)
27
+
28
+ ## 0.14.1 (April 28th, 2019)
29
+
30
+ * Many adjustments and various non-breaking fixes
31
+ * Improvements to caching (@zenspider)
32
+ * Fix tests for Rails 5 (@robertoz)
33
+
34
+ ## 0.13.1 (October 21st, 2016)
35
+
36
+ * Further compatibility with Rails 5
37
+
3
38
  ## 0.13.0 (July 15th, 2016)
4
39
 
5
40
  * Compatibility with Rails 5
data/CONTRIBUTING.md CHANGED
@@ -3,7 +3,7 @@ We love pull requests. Here's a quick guide:
3
3
  1. Fork the repo.
4
4
 
5
5
  2. Run the tests. We only take pull requests with passing tests, and it's great
6
- to know that you have a clean slate: `bundle && rake test`
6
+ to know that you have a clean slate: `bundle && bundle exec rake test`
7
7
 
8
8
  3. Add a test for your change. Only refactoring and documentation changes
9
9
  require no new tests. If you are adding functionality or fixing a bug, we need
@@ -34,4 +34,4 @@ Syntax:
34
34
 
35
35
  And in case we didn't emphasize it enough: we love tests!
36
36
 
37
- NOTE: Adapted from https://raw.github.com/thoughtbot/factory_girl_rails/master/CONTRIBUTING.md
37
+ NOTE: Adapted from https://raw.githubusercontent.com/thoughtbot/factory_bot_rails/main/CONTRIBUTING.md
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # RABL #
2
2
 
3
- [![Continuous Integration status](https://secure.travis-ci.org/nesquena/rabl.png)](http://travis-ci.org/nesquena/rabl)
4
- [![Dependency Status](https://gemnasium.com/nesquena/rabl.png)](https://gemnasium.com/nesquena/rabl)
5
- [![Code Climate](https://codeclimate.com/github/nesquena/rabl.png)](https://codeclimate.com/github/nesquena/rabl)
3
+ [![Continuous Integration status](https://github.com/nesquena/rabl/actions/workflows/ci.yml/badge.svg)](https://github.com/nesquena/rabl/actions)
4
+ [![Code Climate](https://codeclimate.com/github/nesquena/rabl.svg)](https://codeclimate.com/github/nesquena/rabl)
6
5
 
7
6
  RABL (Ruby API Builder Language) is a Rails and [Padrino](http://padrinorb.com) ruby templating system for generating JSON, XML, MessagePack, PList and BSON.
8
7
  When using the ActiveRecord 'to_json' method, I find myself wanting a more expressive and powerful solution for generating APIs.
@@ -146,6 +145,7 @@ Rabl.configure do |config|
146
145
  # config.replace_empty_string_values_with_nil_values = true # Defaults to false
147
146
  # config.exclude_nil_values = true # Defaults to false
148
147
  # config.exclude_empty_values_in_collections = true # Defaults to false
148
+ # config.camelize_keys = :upper # Defaults to false
149
149
  end
150
150
  ```
151
151
 
@@ -184,7 +184,9 @@ If `replace_nil_values_with_empty_strings` is set to `true`, all values that are
184
184
 
185
185
  If `exclude_nil_values` is set to `true`, all values that are `nil` and would normally be displayed as `null` in the response are not included in the response.
186
186
 
187
- if `exclude_empty_values_in_collections` is set to `true`, all vaules in a collection that are `{}` and would normally be displayed as `{}` in the response are not included in the response.
187
+ if `exclude_empty_values_in_collections` is set to `true`, all values in a collection that are `{}` and would normally be displayed as `{}` in the response are not included in the response.
188
+
189
+ If `camelize_keys` is set to `true`, all object keys will be converted to camel case. By default the first character will be lower case. The value can be set to `:upper` to set the first character to upper case.
188
190
 
189
191
  If you wish to use [oj](https://github.com/ohler55/oj) as
190
192
  the primary JSON encoding engine simply add that to your Gemfile:
@@ -300,6 +302,13 @@ Named and aliased attributes can not be combined on the same line. This currentl
300
302
  attributes :foo, :bar => :baz # throws exception
301
303
  ```
302
304
 
305
+ in such cases, you need to specify attributes twice.
306
+
307
+ ```ruby
308
+ attributes :foo
309
+ attributes :bar => :baz
310
+ ```
311
+
303
312
  ### Child Nodes ###
304
313
 
305
314
  Often a response requires including nested information from data associated with the parent model:
@@ -580,11 +589,11 @@ You can also pass in other instance variables to be used in your template as:
580
589
  Rabl::Renderer.new('posts/show', @post, :locals => { :custom_title => "Hello world!" })
581
590
  ````
582
591
 
583
- Then, in your template, you can use `@custom_title` as:
592
+ Then, in your template, you can use `locals[:custom_title]` as:
584
593
 
585
- ```
594
+ ```ruby
586
595
  attribute :content
587
- node(:title) { @custom_title }
596
+ node(:title) { locals[:custom_title] }
588
597
  ```
589
598
 
590
599
  ### Content Type Headers ###
@@ -624,13 +633,9 @@ Tutorials can always be helpful when first getting started:
624
633
 
625
634
  * [Railscasts #322](http://railscasts.com/episodes/322-rabl) - Ryan Bates explains RABL
626
635
  * [BackboneRails](http://www.backbonerails.com/) - Great screencasts by Brian Mann
627
- * [Creating an API with RABL and Padrino](http://blog.crowdint.com/2012/10/22/rabl-with-padrino.html)
628
636
  * http://blog.joshsoftware.com/2011/12/23/designing-rails-api-using-rabl-and-devise/
629
- * http://engineering.gomiso.com/2011/06/27/building-a-platform-api-on-rails/
630
- * http://blog.lawrencenorton.com/better-json-requests-with-rabl
631
637
  * http://tech.favoritemedium.com/2011/06/using-rabl-in-rails-json-web-api.html
632
638
  * http://seesparkbox.com/foundry/better_rails_apis_with_rabl
633
- * http://blog.dcxn.com/2011/06/22/rails-json-templates-through-rabl
634
639
  * http://teohm.github.com/blog/2011/05/31/using-rabl-in-rails-json-web-api
635
640
 
636
641
  Let me know if there's any other useful resources not listed here.
data/lib/rabl/builder.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'active_support/inflector' # for the sake of camelcasing keys
2
+
1
3
  module Rabl
2
4
  class Builder
3
5
  include Helpers
@@ -135,10 +137,13 @@ module Rabl
135
137
  # attribute :foo, :as => "bar"
136
138
  # attribute :foo, :as => "bar", :if => lambda { |m| m.foo }
137
139
  def attribute(name, options = {})
138
- return unless @_object && attribute_present?(name) && resolve_condition(options)
140
+ return unless
141
+ @_object &&
142
+ attribute_present?(name) &&
143
+ resolve_condition(options)
139
144
 
140
145
  attribute = data_object_attribute(name)
141
- name = (options[:as] || name).to_sym
146
+ name = create_key(options[:as] || name)
142
147
  @_result[name] = attribute
143
148
  end
144
149
  alias_method :attributes, :attribute
@@ -151,7 +156,7 @@ module Rabl
151
156
 
152
157
  result = block.call(@_object)
153
158
  if name.present?
154
- @_result[name.to_sym] = result
159
+ @_result[create_key(name)] = result
155
160
  elsif result.is_a?(Hash) # merge hash into root hash
156
161
  @_result.merge!(result)
157
162
  end
@@ -174,7 +179,7 @@ module Rabl
174
179
 
175
180
  object = { object => name } if data.is_a?(Hash) && object # child :users => :people
176
181
 
177
- engines << { name.to_sym => object_to_engine(object, engine_options, &block) }
182
+ engines << { create_key(name) => object_to_engine(object, engine_options, &block) }
178
183
  end
179
184
 
180
185
  # Glues data from a child node to the json_output
@@ -198,10 +203,11 @@ module Rabl
198
203
 
199
204
  # Evaluate conditions given a symbol/proc/lambda/variable to evaluate
200
205
  def call_condition_proc(condition, object)
201
- # This will evaluate lambda, proc & symbol and call it with 1 argument
202
- return condition.to_proc.call(object) if condition.is_a?(Proc) || condition.is_a?(Symbol)
203
- # Else we send directly the object
204
- condition
206
+ case condition
207
+ when Proc then condition.call(object)
208
+ when Symbol then condition.to_proc.call(object)
209
+ else condition
210
+ end
205
211
  end
206
212
 
207
213
  # resolve_condition(:if => true) => true
@@ -211,8 +217,10 @@ module Rabl
211
217
  # resolve_condition(:unless => lambda { |m| false }, :if => proc { true}) => true
212
218
  def resolve_condition(options)
213
219
  result = true
214
- result &&= call_condition_proc(options[:if], @_object) if options.key?(:if)
215
- result &&= !call_condition_proc(options[:unless], @_object) if options.key?(:unless)
220
+ result &&= call_condition_proc(options[:if], @_object) if
221
+ options.key?(:if)
222
+ result &&= !call_condition_proc(options[:unless], @_object) if
223
+ options.key?(:unless)
216
224
  result
217
225
  end
218
226
 
@@ -220,13 +228,9 @@ module Rabl
220
228
  # Checks if an attribute is present. If not, check if the configuration specifies that this is an error
221
229
  # attribute_present?(created_at) => true
222
230
  def attribute_present?(name)
223
- if @_object.respond_to?(name)
224
- true
225
- elsif Rabl.configuration.raise_on_missing_attribute
226
- raise "Failed to render missing attribute #{name}"
227
- else
228
- false
229
- end
231
+ @_object.respond_to?(name) ||
232
+ (Rabl.configuration.raise_on_missing_attribute &&
233
+ raise("Failed to render missing attribute #{name}"))
230
234
  end
231
235
 
232
236
  # Returns a guess at the format in this context_scope
@@ -248,5 +252,13 @@ module Rabl
248
252
  yield
249
253
  end
250
254
  end
255
+
256
+ def create_key(name)
257
+ if Rabl.configuration.camelize_keys
258
+ name.to_s.camelize(Rabl.configuration.camelize_keys == :upper ? :upper : :lower).to_sym
259
+ else
260
+ name.to_sym
261
+ end
262
+ end
251
263
  end
252
264
  end
@@ -5,8 +5,35 @@
5
5
  # config.cache_engine = AdvancedCacheEngine.new
6
6
  #
7
7
 
8
+ class LRU < Hash
9
+ attr_accessor :max_size
10
+
11
+ def initialize
12
+ super
13
+ self.max_size = 100_000
14
+ end
15
+
16
+ def []= k,v
17
+ r = super
18
+ limit_size
19
+ r
20
+ end
21
+
22
+ def limit_size
23
+ if size > max_size then
24
+ delete keys.shift while size > max_size
25
+ end
26
+ end
27
+ end
28
+
8
29
  module Rabl
9
30
  class CacheEngine
31
+ def initialize
32
+ unless defined?(Rails)
33
+ @cache = LRU.new
34
+ end
35
+ end
36
+
10
37
 
11
38
  # Fetch given a key and options and a fallback block attempts to find the key in the cache
12
39
  # and stores the block result in there if no key is found.
@@ -17,13 +44,15 @@ module Rabl
17
44
  if defined?(Rails)
18
45
  Rails.cache.fetch(key, cache_options, &block)
19
46
  else
20
- yield
47
+ @cache[key] ||= yield
21
48
  end
22
49
  end
23
50
 
24
51
  def write(key, value, options = {})
25
52
  if defined?(Rails)
26
53
  Rails.cache.write(key, value, options)
54
+ else
55
+ @cache[key] = yield
27
56
  end
28
57
  end
29
58
 
@@ -7,7 +7,7 @@ end
7
7
  # We load the bson library if it is available.
8
8
  begin
9
9
  require 'bson'
10
- rescue LoadError
10
+ rescue LoadError
11
11
  end
12
12
 
13
13
  # We load the plist library if it is available.
@@ -52,6 +52,7 @@ module Rabl
52
52
  attr_accessor :replace_empty_string_values_with_nil_values
53
53
  attr_accessor :exclude_nil_values
54
54
  attr_accessor :exclude_empty_values_in_collections
55
+ attr_accessor :camelize_keys
55
56
 
56
57
  DEFAULT_XML_OPTIONS = { :dasherize => true, :skip_types => false }
57
58
 
@@ -81,6 +82,7 @@ module Rabl
81
82
  @replace_empty_string_values_with_nil_values = false
82
83
  @exclude_nil_values = false
83
84
  @exclude_empty_values_in_collections = false
85
+ @camelize_keys = false
84
86
  end
85
87
 
86
88
  # @return The JSON engine used to encode Rabl templates into JSON
@@ -0,0 +1,12 @@
1
+ require 'action_view'
2
+
3
+ module Rabl
4
+ class Digestor < ActionView::Digestor
5
+ def self.digest(name, format, finder, options = {})
6
+ cache_key = [name, format] + Array.wrap(options[:dependencies])
7
+ @@cache[cache_key.join('.')] ||= begin
8
+ Digestor.new(name, format, finder, options).digest
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'action_view'
2
+
3
+ module Rabl
4
+ class Digestor < ActionView::Digestor
5
+ def self.digest(options = {})
6
+ cache_key = [options[:name]] + Array.wrap(options[:dependencies])
7
+ @@cache[cache_key.join('.')] ||= begin
8
+ Digestor.new({ :name => options[:name], :finder => options[:finder] }.merge!(options)).digest
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ require 'action_view'
2
+
3
+ module Rabl
4
+ class Digestor < ActionView::Digestor
5
+ end
6
+ end
data/lib/rabl/digestor.rb CHANGED
@@ -1,47 +1,15 @@
1
+ require 'action_view'
2
+
1
3
  module Rabl
2
4
  class Digestor < ActionView::Digestor
3
5
  # Override the original digest function to ignore partial which
4
6
  # rabl doesn't use the Rails conventional _ symbol.
5
7
  if Gem::Version.new(Rails.version) >= Gem::Version.new('5.0.0.beta1')
6
- def self.digest(name:, finder:, **options)
7
-
8
- options.assert_valid_keys(:dependencies, :partial)
9
-
10
- cache_key = ([ name ].compact + Array.wrap(options[:dependencies])).join('.')
11
-
12
- # this is a correctly done double-checked locking idiom
13
- # (Concurrent::Map's lookups have volatile semantics)
14
- finder.digest_cache[cache_key] || @@digest_monitor.synchronize do
15
- finder.digest_cache.fetch(cache_key) do # re-check under lock
16
- begin
17
- # Prevent re-entry or else recursive templates will blow the stack.
18
- # There is no need to worry about other threads seeing the +false+ value,
19
- # as they will then have to wait for this thread to let go of the @@digest_monitor lock.
20
-
21
- pre_stored = finder.digest_cache.put_if_absent(cache_key, false).nil? # put_if_absent returns nil on insertion
22
-
23
- finder.digest_cache[cache_key] = stored_digest = Digestor.new(name, finder, options).digest
24
- ensure
25
- # something went wrong or ActionView::Resolver.caching? is false, make sure not to corrupt the @@cache
26
- finder.digest_cache.delete_pair(cache_key, false) if pre_stored && !stored_digest
27
- end
28
- end
29
- end
30
- end
8
+ require 'rabl/digestor/rails5'
31
9
  elsif Gem::Version.new(Rails.version) >= Gem::Version.new('4.1')
32
- def self.digest(options = {})
33
- cache_key = [options[:name]] + Array.wrap(options[:dependencies])
34
- @@cache[cache_key.join('.')] ||= begin
35
- Digestor.new({ :name => options[:name], :finder => options[:finder] }.merge!(options)).digest
36
- end
37
- end
10
+ require 'rabl/digestor/rails41'
38
11
  else
39
- def self.digest(name, format, finder, options = {})
40
- cache_key = [name, format] + Array.wrap(options[:dependencies])
41
- @@cache[cache_key.join('.')] ||= begin
42
- Digestor.new(name, format, finder, options).digest
43
- end
44
- end
12
+ require 'rabl/digestor/rails3'
45
13
  end
46
14
 
47
15
  private
data/lib/rabl/engine.rb CHANGED
@@ -6,6 +6,7 @@ module Rabl
6
6
 
7
7
  # List of supported rendering formats
8
8
  FORMATS = [:json, :xml, :plist, :bson, :msgpack]
9
+ SAFE_FORMATS = FORMATS + [:mpac, :dumpable, :hash]
9
10
 
10
11
  # Constructs a new ejs engine based on given vars, handler and declarations
11
12
  # Rabl::Engine.new("...source...", { :format => "xml", :root => true, :view_path => "/path/to/views" })
@@ -27,6 +28,8 @@ module Rabl
27
28
  # Renders the representation based on source, object, context_scope and locals
28
29
  # Rabl::Engine.new("...source...", { :format => "xml" }).apply(context_scope, { :foo => "bar", :object => @user })
29
30
  def apply(context_scope, locals, &block)
31
+ locals = locals.dup unless locals.nil?
32
+
30
33
  set_instance_variables!(context_scope, locals)
31
34
 
32
35
  reset_settings!
@@ -58,8 +61,10 @@ module Rabl
58
61
  if digestor_available? && respond_to?(:lookup_context) && lookup_context
59
62
  template = @_options[:template] || @virtual_path
60
63
 
61
- digest = \
62
- if Gem::Version.new(Rails.version) >= Gem::Version.new('4.1')
64
+ digest =
65
+ if Rails.version.to_s =~ /^[67]/
66
+ Digestor.digest(name: template, finder: lookup_context, format: :rabl)
67
+ elsif Gem::Version.new(Rails.version) >= Gem::Version.new('4.1')
63
68
  Digestor.digest(:name => template, :finder => lookup_context)
64
69
  else
65
70
  Digestor.digest(template, :rabl, lookup_context)
@@ -81,7 +86,7 @@ module Rabl
81
86
 
82
87
  options[:root_name] = determine_object_root(data, root_name, options[:root])
83
88
 
84
- result = \
89
+ result =
85
90
  if is_object?(data) || !data # object @user
86
91
  Builder.new(data, @_settings, options).to_hash
87
92
  elsif is_collection?(data) # collection @users
@@ -165,6 +170,7 @@ module Rabl
165
170
  @_root_name_data = @_root_name_data.values.first if @_root_name_data.is_a?(Hash)
166
171
 
167
172
  # If we turn this around, `@_root_name_date ==` may trigger data to be loaded unnecessarily.
173
+ # TODO: is nil a different semantic? otherwise don't use `false ==`, use !
168
174
  if false == @_root_name_data
169
175
  @_object_root_name = false
170
176
  @_collection_name = false
@@ -387,7 +393,11 @@ module Rabl
387
393
  end
388
394
 
389
395
  def digestor_available?
390
- defined?(Rails) && Rails.version =~ /^[45]/
396
+ defined?(Rails) && Rails.version =~ /^[4567]/
397
+ end
398
+
399
+ def valid_format?(format)
400
+ SAFE_FORMATS.include?(format.to_sym) && respond_to?("to_#{format}")
391
401
  end
392
402
 
393
403
  def set_instance_variables!(context_scope, locals)
@@ -398,6 +408,9 @@ module Rabl
398
408
 
399
409
  @_options[:format] ||= request_format
400
410
 
411
+ # Prevent calls to inherited methods `to_yaml`, `to_enum`, etc.
412
+ @_options[:format] = 'json' unless valid_format?(@_options[:format])
413
+
401
414
  set_locals(@_locals)
402
415
  end
403
416
 
@@ -407,15 +420,21 @@ module Rabl
407
420
  end
408
421
 
409
422
  def eval_source(locals, &block)
410
- # Note: locals and block may be used by the eval'ed source
411
-
412
423
  return unless @_source.present?
413
424
 
414
- if @_options[:source_location]
415
- instance_eval(@_source, @_options[:source_location])
416
- else
417
- instance_eval(@_source)
425
+ msg = "cached_source_#{@_source.hash.abs}"
426
+
427
+ unless self.respond_to? msg then
428
+ src = "def #{msg} locals, &block\n#{@_source}\nend"
429
+
430
+ if @_options[:source_location]
431
+ self.class.class_eval(src, @_options[:source_location])
432
+ else
433
+ self.class.class_eval(src)
434
+ end
418
435
  end
436
+
437
+ send msg, locals, &block
419
438
  end
420
- end
439
+ end
421
440
  end
data/lib/rabl/helpers.rb CHANGED
@@ -14,7 +14,9 @@ module Rabl
14
14
  # data_object_attribute(data) => @_object.send(data)
15
15
  def data_object_attribute(data)
16
16
  attribute = @_object.__send__(data)
17
- attribute = attribute.as_json if is_collection?(attribute, false) && attribute.respond_to?(:as_json)
17
+ attribute = attribute.as_json if
18
+ is_collection?(attribute, false) &&
19
+ attribute.respond_to?(:as_json)
18
20
  attribute
19
21
  end
20
22
 
@@ -81,8 +83,10 @@ module Rabl
81
83
  # is_collection?([]) => true
82
84
  def is_collection?(obj, follow_symbols = true)
83
85
  data_obj = follow_symbols ? data_object(obj) : obj
84
- data_obj && data_obj.respond_to?(:map) && data_obj.respond_to?(:each) &&
85
- !(data_obj.is_a?(Struct) || defined?(Hashie::Mash) && data_obj.is_a?(Hashie::Mash))
86
+ data_obj &&
87
+ data_obj.respond_to?(:map) && data_obj.respond_to?(:each) &&
88
+ !(data_obj.is_a?(Struct) ||
89
+ defined?(Hashie::Mash) && data_obj.is_a?(Hashie::Mash))
86
90
  end
87
91
 
88
92
  # Returns the context_scope wrapping this engine, used for retrieving data, invoking methods, etc
data/lib/rabl/railtie.rb CHANGED
@@ -1,11 +1,28 @@
1
1
  module Rabl
2
2
  class Railtie < Rails::Railtie
3
3
  initializer "rabl.initialize" do |app|
4
+ # Force Rails to load view templates even in API mode
5
+ # Stolen shamelessly from jbuilder: https://github.com/rails/jbuilder/blob/master/lib/jbuilder/railtie.rb
6
+ if Rails::VERSION::MAJOR >= 5
7
+ module ::ActionController
8
+ module ApiRendering
9
+ include ActionView::Rendering
10
+ end
11
+ end
12
+
13
+ ActiveSupport.on_load :action_controller do
14
+ if self == ActionController::API
15
+ include ActionController::Helpers
16
+ include ActionController::ImplicitRender
17
+ end
18
+ end
19
+ end
20
+
4
21
  ActiveSupport.on_load(:action_view) do
5
22
  Rabl.register!
6
23
 
7
24
  # Inject dependency tracker for :rabl
8
- if Rails.version =~ /^[45]/
25
+ if Rails.version =~ /^[4567]/
9
26
  require 'action_view/dependency_tracker'
10
27
  ActionView::DependencyTracker.register_tracker :rabl, Rabl::Tracker
11
28
  end
data/lib/rabl/template.rb CHANGED
@@ -40,7 +40,7 @@ if defined?(ActionView) && defined?(Rails) && Rails.respond_to?(:version) && Rai
40
40
  ActionView::Template.register_template_handler :rabl, ActionView::TemplateHandlers::RablHandler
41
41
  end
42
42
 
43
- # Rails 3.X / 4.X Template
43
+ # Rails 3.X / 4.X / 5.X Template
44
44
  if defined?(ActionView) && defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_s =~ /^[345]/
45
45
  module ActionView
46
46
  module Template::Handlers
@@ -61,3 +61,23 @@ if defined?(ActionView) && defined?(Rails) && Rails.respond_to?(:version) && Rai
61
61
 
62
62
  ActionView::Template.register_template_handler :rabl, ActionView::Template::Handlers::Rabl
63
63
  end
64
+
65
+ # Rails 6.X / 7.X Template
66
+ if defined?(ActionView) && defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_s =~ /^[67]/
67
+ module ActionView
68
+ module Template::Handlers
69
+ class Rabl
70
+ class_attribute :default_format
71
+ self.default_format = :json
72
+
73
+ def self.call(template, source)
74
+ %{ ::Rabl::Engine.new(#{source.inspect}).
75
+ apply(self, assigns.merge(local_assigns)).
76
+ render }
77
+ end # call
78
+ end # rabl class
79
+ end # handlers
80
+ end
81
+
82
+ ActionView::Template.register_template_handler :rabl, ActionView::Template::Handlers::Rabl
83
+ end
data/lib/rabl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rabl
2
- VERSION = "0.13.0"
2
+ VERSION = "0.15.0"
3
3
  end
data/lib/rabl.rb CHANGED
@@ -16,10 +16,10 @@ require 'rabl/configuration'
16
16
  require 'rabl/renderer'
17
17
  require 'rabl/cache_engine'
18
18
 
19
- if defined?(Rails)
20
- require 'rabl/tracker' if Rails.version =~ /^[45]/
21
- require 'rabl/digestor' if Rails.version =~ /^[45]/
22
- require 'rabl/railtie' if Rails.version =~ /^[345]/
19
+ if defined?(Rails) && Rails.respond_to?(:version)
20
+ require 'rabl/tracker' if Rails.version =~ /^[4567]/
21
+ require 'rabl/digestor' if Rails.version =~ /^[4567]/
22
+ require 'rabl/railtie' if Rails.version =~ /^[34567]/
23
23
  end
24
24
 
25
25
  # Rabl.register!
@@ -83,6 +83,6 @@ end
83
83
  if defined?(Padrino)
84
84
  require 'padrino-core'
85
85
  Padrino.after_load { Rabl.register! }
86
- elsif defined?(Rails) && Rails.version =~ /^2/
86
+ elsif defined?(Rails.version) && Rails.version =~ /^2/
87
87
  Rabl.register!
88
88
  end