strong_presenter 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -2
  3. data/.rspec +2 -0
  4. data/.travis.yml +18 -0
  5. data/.yardopts +1 -0
  6. data/CHANGELOG.md +31 -0
  7. data/Gemfile +22 -2
  8. data/Guardfile +26 -0
  9. data/README.md +210 -52
  10. data/Rakefile +77 -1
  11. data/gemfiles/3.0.gemfile +2 -0
  12. data/gemfiles/3.1.gemfile +2 -0
  13. data/gemfiles/3.2.gemfile +2 -0
  14. data/gemfiles/4.0.gemfile +2 -0
  15. data/gemfiles/4.1.gemfile +2 -0
  16. data/lib/generators/controller_override.rb +15 -0
  17. data/lib/generators/mini_test/presenter_generator.rb +20 -0
  18. data/lib/generators/mini_test/templates/presenter_spec.rb +4 -0
  19. data/lib/generators/mini_test/templates/presenter_test.rb +4 -0
  20. data/lib/generators/rails/presenter_generator.rb +36 -0
  21. data/lib/generators/rails/templates/presenter.rb +19 -0
  22. data/lib/generators/rspec/presenter_generator.rb +9 -0
  23. data/lib/generators/rspec/templates/presenter_spec.rb +4 -0
  24. data/lib/generators/test_unit/presenter_generator.rb +9 -0
  25. data/lib/generators/test_unit/templates/presenter_test.rb +4 -0
  26. data/lib/strong_presenter/associable.rb +78 -0
  27. data/lib/strong_presenter/collection_presenter.rb +90 -0
  28. data/lib/strong_presenter/controller_additions.rb +50 -0
  29. data/lib/strong_presenter/delegation.rb +18 -0
  30. data/lib/strong_presenter/factory.rb +74 -0
  31. data/lib/strong_presenter/helper_proxy.rb +29 -11
  32. data/lib/strong_presenter/inferrer.rb +54 -0
  33. data/lib/strong_presenter/permissible.rb +73 -0
  34. data/lib/strong_presenter/permissions.rb +138 -0
  35. data/lib/strong_presenter/presenter.rb +191 -0
  36. data/lib/strong_presenter/presenter_association.rb +29 -0
  37. data/lib/strong_presenter/presenter_helper_constructor.rb +60 -0
  38. data/lib/strong_presenter/railtie.rb +27 -3
  39. data/lib/strong_presenter/tasks/test.rake +22 -0
  40. data/lib/strong_presenter/test/devise_helper.rb +30 -0
  41. data/lib/strong_presenter/test/minitest_integration.rb +6 -0
  42. data/lib/strong_presenter/test/rspec_integration.rb +16 -0
  43. data/lib/strong_presenter/test_case.rb +53 -0
  44. data/lib/strong_presenter/version.rb +1 -1
  45. data/lib/strong_presenter/view_context/build_strategy.rb +48 -0
  46. data/lib/strong_presenter/view_context.rb +84 -0
  47. data/lib/strong_presenter/view_helpers.rb +39 -0
  48. data/lib/strong_presenter.rb +64 -2
  49. data/spec/dummy/.rspec +2 -0
  50. data/spec/dummy/Rakefile +7 -0
  51. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  52. data/spec/dummy/app/controllers/localized_urls.rb +5 -0
  53. data/spec/dummy/app/controllers/posts_controller.rb +25 -0
  54. data/spec/dummy/app/helpers/application_helper.rb +5 -0
  55. data/spec/dummy/app/mailers/application_mailer.rb +3 -0
  56. data/spec/dummy/app/mailers/post_mailer.rb +19 -0
  57. data/spec/dummy/app/models/admin.rb +5 -0
  58. data/spec/dummy/app/models/post.rb +3 -0
  59. data/spec/dummy/app/models/user.rb +5 -0
  60. data/spec/dummy/app/presenters/post_presenter.rb +69 -0
  61. data/spec/dummy/app/presenters/special_post_presenter.rb +5 -0
  62. data/spec/dummy/app/presenters/special_posts_presenter.rb +5 -0
  63. data/spec/dummy/app/views/layouts/application.html.erb +11 -0
  64. data/spec/dummy/app/views/post_mailer/presented_email.html.erb +1 -0
  65. data/spec/dummy/app/views/posts/_post.html.erb +50 -0
  66. data/spec/dummy/app/views/posts/show.html.erb +1 -0
  67. data/spec/dummy/bin/rails +4 -0
  68. data/spec/dummy/config/application.rb +70 -0
  69. data/spec/dummy/config/boot.rb +5 -0
  70. data/spec/dummy/config/database.yml +25 -0
  71. data/spec/dummy/config/environment.rb +5 -0
  72. data/spec/dummy/config/environments/development.rb +33 -0
  73. data/spec/dummy/config/environments/production.rb +57 -0
  74. data/spec/dummy/config/environments/test.rb +31 -0
  75. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  76. data/spec/dummy/config/initializers/inflections.rb +15 -0
  77. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  78. data/spec/dummy/config/initializers/secret_token.rb +8 -0
  79. data/spec/dummy/config/initializers/session_store.rb +8 -0
  80. data/spec/dummy/config/locales/en.yml +5 -0
  81. data/spec/dummy/config/routes.rb +9 -0
  82. data/spec/dummy/config.ru +4 -0
  83. data/spec/dummy/db/migrate/20121019115657_create_posts.rb +8 -0
  84. data/spec/dummy/db/schema.rb +21 -0
  85. data/spec/dummy/db/seeds.rb +2 -0
  86. data/spec/dummy/fast_spec/post_presenter_spec.rb +37 -0
  87. data/spec/dummy/lib/tasks/test.rake +16 -0
  88. data/spec/dummy/log/.gitkeep +0 -0
  89. data/spec/dummy/public/404.html +26 -0
  90. data/spec/dummy/public/422.html +26 -0
  91. data/spec/dummy/public/500.html +25 -0
  92. data/spec/dummy/public/favicon.ico +0 -0
  93. data/spec/dummy/script/rails +6 -0
  94. data/spec/dummy/spec/fast_spec_helper.rb +13 -0
  95. data/spec/dummy/spec/mailers/post_mailer_spec.rb +33 -0
  96. data/spec/dummy/spec/models/post_spec.rb +4 -0
  97. data/spec/dummy/spec/presenters/active_model_serializers_spec.rb +11 -0
  98. data/spec/dummy/spec/presenters/devise_spec.rb +64 -0
  99. data/spec/dummy/spec/presenters/helpers_spec.rb +21 -0
  100. data/spec/dummy/spec/presenters/post_presenter_spec.rb +66 -0
  101. data/spec/dummy/spec/presenters/spec_type_spec.rb +7 -0
  102. data/spec/dummy/spec/presenters/special_post_presenter_spec.rb +11 -0
  103. data/spec/dummy/spec/presenters/view_context_spec.rb +22 -0
  104. data/spec/dummy/spec/spec_helper.rb +19 -0
  105. data/spec/dummy/test/minitest_helper.rb +2 -0
  106. data/spec/dummy/test/presenters/minitest/devise_test.rb +64 -0
  107. data/spec/dummy/test/presenters/minitest/helpers_test.rb +21 -0
  108. data/spec/dummy/test/presenters/minitest/spec_type_test.rb +52 -0
  109. data/spec/dummy/test/presenters/minitest/view_context_test.rb +24 -0
  110. data/spec/dummy/test/presenters/test_unit/devise_test.rb +64 -0
  111. data/spec/dummy/test/presenters/test_unit/helpers_test.rb +21 -0
  112. data/spec/dummy/test/presenters/test_unit/view_context_test.rb +24 -0
  113. data/spec/dummy/test/test_helper.rb +13 -0
  114. data/spec/generators/presenters/presenter_generator_spec.rb +131 -0
  115. data/spec/generators/simplecov_spec.rb +5 -0
  116. data/spec/integration/integration_spec.rb +81 -0
  117. data/spec/integration/simplecov_spec.rb +4 -0
  118. data/spec/spec_helper.rb +47 -0
  119. data/spec/strong_presenter/associable_spec.rb +122 -0
  120. data/spec/strong_presenter/collection_presenter_spec.rb +34 -0
  121. data/spec/strong_presenter/delegation_spec.rb +20 -0
  122. data/spec/strong_presenter/permissible_spec.rb +24 -0
  123. data/spec/strong_presenter/permissions_spec.rb +188 -0
  124. data/spec/strong_presenter/presenter_spec.rb +43 -0
  125. data/spec/strong_presenter/simplecov_spec.rb +4 -0
  126. data/spec/support/dummy_app.rb +85 -0
  127. data/spec/support/matchers/have_text.rb +50 -0
  128. data/spec/support/models.rb +14 -0
  129. data/spec/support/schema.rb +12 -0
  130. data/strong_presenter.gemspec +15 -0
  131. metadata +392 -13
  132. data/lib/strong_presenter/base.rb +0 -217
metadata CHANGED
@@ -1,16 +1,197 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strong_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ronald Chan
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-10-10 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2013-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: request_store
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: activemodel
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ammeter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.9.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.9.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '2.12'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '2.12'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-mocks
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 2.12.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: 2.12.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec-rails
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '2.12'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: '2.12'
139
+ - !ruby/object:Gem::Dependency
140
+ name: minitest-rails
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: '0.2'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: '0.2'
153
+ - !ruby/object:Gem::Dependency
154
+ name: capybara
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: active_model_serializers
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: activerecord
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '3.0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '3.0'
14
195
  description: strong_presenter lets you add presenters to your application, along with
15
196
  strong_parameters-inspired permit logic to handle mass presentations, where each
16
197
  user may have permision to view different fields
@@ -21,41 +202,239 @@ extensions: []
21
202
  extra_rdoc_files: []
22
203
  files:
23
204
  - .gitignore
205
+ - .rspec
206
+ - .travis.yml
207
+ - .yardopts
208
+ - CHANGELOG.md
24
209
  - Gemfile
210
+ - Guardfile
25
211
  - LICENSE
26
212
  - README.md
27
213
  - Rakefile
214
+ - gemfiles/3.0.gemfile
215
+ - gemfiles/3.1.gemfile
216
+ - gemfiles/3.2.gemfile
217
+ - gemfiles/4.0.gemfile
218
+ - gemfiles/4.1.gemfile
219
+ - lib/generators/controller_override.rb
220
+ - lib/generators/mini_test/presenter_generator.rb
221
+ - lib/generators/mini_test/templates/presenter_spec.rb
222
+ - lib/generators/mini_test/templates/presenter_test.rb
223
+ - lib/generators/rails/presenter_generator.rb
224
+ - lib/generators/rails/templates/presenter.rb
225
+ - lib/generators/rspec/presenter_generator.rb
226
+ - lib/generators/rspec/templates/presenter_spec.rb
227
+ - lib/generators/test_unit/presenter_generator.rb
228
+ - lib/generators/test_unit/templates/presenter_test.rb
28
229
  - lib/strong_presenter.rb
29
- - lib/strong_presenter/base.rb
230
+ - lib/strong_presenter/associable.rb
231
+ - lib/strong_presenter/collection_presenter.rb
232
+ - lib/strong_presenter/controller_additions.rb
233
+ - lib/strong_presenter/delegation.rb
234
+ - lib/strong_presenter/factory.rb
30
235
  - lib/strong_presenter/helper_proxy.rb
236
+ - lib/strong_presenter/inferrer.rb
237
+ - lib/strong_presenter/permissible.rb
238
+ - lib/strong_presenter/permissions.rb
239
+ - lib/strong_presenter/presenter.rb
240
+ - lib/strong_presenter/presenter_association.rb
241
+ - lib/strong_presenter/presenter_helper_constructor.rb
31
242
  - lib/strong_presenter/railtie.rb
243
+ - lib/strong_presenter/tasks/test.rake
244
+ - lib/strong_presenter/test/devise_helper.rb
245
+ - lib/strong_presenter/test/minitest_integration.rb
246
+ - lib/strong_presenter/test/rspec_integration.rb
247
+ - lib/strong_presenter/test_case.rb
32
248
  - lib/strong_presenter/version.rb
249
+ - lib/strong_presenter/view_context.rb
250
+ - lib/strong_presenter/view_context/build_strategy.rb
251
+ - lib/strong_presenter/view_helpers.rb
252
+ - spec/dummy/.rspec
253
+ - spec/dummy/Rakefile
254
+ - spec/dummy/app/controllers/application_controller.rb
255
+ - spec/dummy/app/controllers/localized_urls.rb
256
+ - spec/dummy/app/controllers/posts_controller.rb
257
+ - spec/dummy/app/helpers/application_helper.rb
258
+ - spec/dummy/app/mailers/application_mailer.rb
259
+ - spec/dummy/app/mailers/post_mailer.rb
260
+ - spec/dummy/app/models/admin.rb
261
+ - spec/dummy/app/models/post.rb
262
+ - spec/dummy/app/models/user.rb
263
+ - spec/dummy/app/presenters/post_presenter.rb
264
+ - spec/dummy/app/presenters/special_post_presenter.rb
265
+ - spec/dummy/app/presenters/special_posts_presenter.rb
266
+ - spec/dummy/app/views/layouts/application.html.erb
267
+ - spec/dummy/app/views/post_mailer/presented_email.html.erb
268
+ - spec/dummy/app/views/posts/_post.html.erb
269
+ - spec/dummy/app/views/posts/show.html.erb
270
+ - spec/dummy/bin/rails
271
+ - spec/dummy/config.ru
272
+ - spec/dummy/config/application.rb
273
+ - spec/dummy/config/boot.rb
274
+ - spec/dummy/config/database.yml
275
+ - spec/dummy/config/environment.rb
276
+ - spec/dummy/config/environments/development.rb
277
+ - spec/dummy/config/environments/production.rb
278
+ - spec/dummy/config/environments/test.rb
279
+ - spec/dummy/config/initializers/backtrace_silencers.rb
280
+ - spec/dummy/config/initializers/inflections.rb
281
+ - spec/dummy/config/initializers/mime_types.rb
282
+ - spec/dummy/config/initializers/secret_token.rb
283
+ - spec/dummy/config/initializers/session_store.rb
284
+ - spec/dummy/config/locales/en.yml
285
+ - spec/dummy/config/routes.rb
286
+ - spec/dummy/db/migrate/20121019115657_create_posts.rb
287
+ - spec/dummy/db/schema.rb
288
+ - spec/dummy/db/seeds.rb
289
+ - spec/dummy/fast_spec/post_presenter_spec.rb
290
+ - spec/dummy/lib/tasks/test.rake
291
+ - spec/dummy/log/.gitkeep
292
+ - spec/dummy/public/404.html
293
+ - spec/dummy/public/422.html
294
+ - spec/dummy/public/500.html
295
+ - spec/dummy/public/favicon.ico
296
+ - spec/dummy/script/rails
297
+ - spec/dummy/spec/fast_spec_helper.rb
298
+ - spec/dummy/spec/mailers/post_mailer_spec.rb
299
+ - spec/dummy/spec/models/post_spec.rb
300
+ - spec/dummy/spec/presenters/active_model_serializers_spec.rb
301
+ - spec/dummy/spec/presenters/devise_spec.rb
302
+ - spec/dummy/spec/presenters/helpers_spec.rb
303
+ - spec/dummy/spec/presenters/post_presenter_spec.rb
304
+ - spec/dummy/spec/presenters/spec_type_spec.rb
305
+ - spec/dummy/spec/presenters/special_post_presenter_spec.rb
306
+ - spec/dummy/spec/presenters/view_context_spec.rb
307
+ - spec/dummy/spec/spec_helper.rb
308
+ - spec/dummy/test/minitest_helper.rb
309
+ - spec/dummy/test/presenters/minitest/devise_test.rb
310
+ - spec/dummy/test/presenters/minitest/helpers_test.rb
311
+ - spec/dummy/test/presenters/minitest/spec_type_test.rb
312
+ - spec/dummy/test/presenters/minitest/view_context_test.rb
313
+ - spec/dummy/test/presenters/test_unit/devise_test.rb
314
+ - spec/dummy/test/presenters/test_unit/helpers_test.rb
315
+ - spec/dummy/test/presenters/test_unit/view_context_test.rb
316
+ - spec/dummy/test/test_helper.rb
317
+ - spec/generators/presenters/presenter_generator_spec.rb
318
+ - spec/generators/simplecov_spec.rb
319
+ - spec/integration/integration_spec.rb
320
+ - spec/integration/simplecov_spec.rb
321
+ - spec/spec_helper.rb
322
+ - spec/strong_presenter/associable_spec.rb
323
+ - spec/strong_presenter/collection_presenter_spec.rb
324
+ - spec/strong_presenter/delegation_spec.rb
325
+ - spec/strong_presenter/permissible_spec.rb
326
+ - spec/strong_presenter/permissions_spec.rb
327
+ - spec/strong_presenter/presenter_spec.rb
328
+ - spec/strong_presenter/simplecov_spec.rb
329
+ - spec/support/dummy_app.rb
330
+ - spec/support/matchers/have_text.rb
331
+ - spec/support/models.rb
332
+ - spec/support/schema.rb
33
333
  - strong_presenter.gemspec
34
334
  homepage: https://github.com/ronalchn/strong_presenter
35
335
  licenses: []
336
+ metadata: {}
36
337
  post_install_message:
37
338
  rdoc_options: []
38
339
  require_paths:
39
340
  - lib
40
341
  required_ruby_version: !ruby/object:Gem::Requirement
41
- none: false
42
342
  requirements:
43
- - - ! '>='
343
+ - - '>='
44
344
  - !ruby/object:Gem::Version
45
345
  version: '0'
46
346
  required_rubygems_version: !ruby/object:Gem::Requirement
47
- none: false
48
347
  requirements:
49
- - - ! '>='
348
+ - - '>='
50
349
  - !ruby/object:Gem::Version
51
350
  version: '0'
52
351
  requirements: []
53
352
  rubyforge_project:
54
- rubygems_version: 1.8.17
353
+ rubygems_version: 2.0.3
55
354
  signing_key:
56
- specification_version: 3
355
+ specification_version: 4
57
356
  summary: strong_presenter lets you add presenters to your application, along with
58
357
  strong_parameters-inspired permit logic to handle mass presentations, where each
59
358
  user may have permision to view different fields
60
- test_files: []
61
- has_rdoc:
359
+ test_files:
360
+ - spec/dummy/.rspec
361
+ - spec/dummy/Rakefile
362
+ - spec/dummy/app/controllers/application_controller.rb
363
+ - spec/dummy/app/controllers/localized_urls.rb
364
+ - spec/dummy/app/controllers/posts_controller.rb
365
+ - spec/dummy/app/helpers/application_helper.rb
366
+ - spec/dummy/app/mailers/application_mailer.rb
367
+ - spec/dummy/app/mailers/post_mailer.rb
368
+ - spec/dummy/app/models/admin.rb
369
+ - spec/dummy/app/models/post.rb
370
+ - spec/dummy/app/models/user.rb
371
+ - spec/dummy/app/presenters/post_presenter.rb
372
+ - spec/dummy/app/presenters/special_post_presenter.rb
373
+ - spec/dummy/app/presenters/special_posts_presenter.rb
374
+ - spec/dummy/app/views/layouts/application.html.erb
375
+ - spec/dummy/app/views/post_mailer/presented_email.html.erb
376
+ - spec/dummy/app/views/posts/_post.html.erb
377
+ - spec/dummy/app/views/posts/show.html.erb
378
+ - spec/dummy/bin/rails
379
+ - spec/dummy/config.ru
380
+ - spec/dummy/config/application.rb
381
+ - spec/dummy/config/boot.rb
382
+ - spec/dummy/config/database.yml
383
+ - spec/dummy/config/environment.rb
384
+ - spec/dummy/config/environments/development.rb
385
+ - spec/dummy/config/environments/production.rb
386
+ - spec/dummy/config/environments/test.rb
387
+ - spec/dummy/config/initializers/backtrace_silencers.rb
388
+ - spec/dummy/config/initializers/inflections.rb
389
+ - spec/dummy/config/initializers/mime_types.rb
390
+ - spec/dummy/config/initializers/secret_token.rb
391
+ - spec/dummy/config/initializers/session_store.rb
392
+ - spec/dummy/config/locales/en.yml
393
+ - spec/dummy/config/routes.rb
394
+ - spec/dummy/db/migrate/20121019115657_create_posts.rb
395
+ - spec/dummy/db/schema.rb
396
+ - spec/dummy/db/seeds.rb
397
+ - spec/dummy/fast_spec/post_presenter_spec.rb
398
+ - spec/dummy/lib/tasks/test.rake
399
+ - spec/dummy/log/.gitkeep
400
+ - spec/dummy/public/404.html
401
+ - spec/dummy/public/422.html
402
+ - spec/dummy/public/500.html
403
+ - spec/dummy/public/favicon.ico
404
+ - spec/dummy/script/rails
405
+ - spec/dummy/spec/fast_spec_helper.rb
406
+ - spec/dummy/spec/mailers/post_mailer_spec.rb
407
+ - spec/dummy/spec/models/post_spec.rb
408
+ - spec/dummy/spec/presenters/active_model_serializers_spec.rb
409
+ - spec/dummy/spec/presenters/devise_spec.rb
410
+ - spec/dummy/spec/presenters/helpers_spec.rb
411
+ - spec/dummy/spec/presenters/post_presenter_spec.rb
412
+ - spec/dummy/spec/presenters/spec_type_spec.rb
413
+ - spec/dummy/spec/presenters/special_post_presenter_spec.rb
414
+ - spec/dummy/spec/presenters/view_context_spec.rb
415
+ - spec/dummy/spec/spec_helper.rb
416
+ - spec/dummy/test/minitest_helper.rb
417
+ - spec/dummy/test/presenters/minitest/devise_test.rb
418
+ - spec/dummy/test/presenters/minitest/helpers_test.rb
419
+ - spec/dummy/test/presenters/minitest/spec_type_test.rb
420
+ - spec/dummy/test/presenters/minitest/view_context_test.rb
421
+ - spec/dummy/test/presenters/test_unit/devise_test.rb
422
+ - spec/dummy/test/presenters/test_unit/helpers_test.rb
423
+ - spec/dummy/test/presenters/test_unit/view_context_test.rb
424
+ - spec/dummy/test/test_helper.rb
425
+ - spec/generators/presenters/presenter_generator_spec.rb
426
+ - spec/generators/simplecov_spec.rb
427
+ - spec/integration/integration_spec.rb
428
+ - spec/integration/simplecov_spec.rb
429
+ - spec/spec_helper.rb
430
+ - spec/strong_presenter/associable_spec.rb
431
+ - spec/strong_presenter/collection_presenter_spec.rb
432
+ - spec/strong_presenter/delegation_spec.rb
433
+ - spec/strong_presenter/permissible_spec.rb
434
+ - spec/strong_presenter/permissions_spec.rb
435
+ - spec/strong_presenter/presenter_spec.rb
436
+ - spec/strong_presenter/simplecov_spec.rb
437
+ - spec/support/dummy_app.rb
438
+ - spec/support/matchers/have_text.rb
439
+ - spec/support/models.rb
440
+ - spec/support/schema.rb
@@ -1,217 +0,0 @@
1
- # Copyright (c) 2013 Ronald Ping Man Chan
2
- #
3
- # This Source Code Form is subject to the terms of the Mozilla Public
4
- # License, v. 2.0. If a copy of the MPL was not distributed with this
5
- # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
-
7
- module StrongPresenter
8
- module CollectionHelper
9
- # Enumerates collection to call permit on each presenter
10
- def permit *fields
11
- self.each { |presenter| presenter.permit *fields }
12
- self
13
- end
14
-
15
- # Enumerates collection to call permit! on each presenter
16
- def permit!
17
- self.each { |presenter| presenter.permit! }
18
- self
19
- end
20
-
21
- # Checks if fields are visible on first presenter in collection
22
- def filter *args
23
- self.first.filter *args
24
- end
25
- end
26
-
27
- class Base
28
- # Constructs the presenter, taking 1 argument for the object being wrapped
29
- def initialize(object)
30
- @object = object
31
- end
32
-
33
- # Wraps a model using a new instance of the presenter, and returns the instance. For example:
34
- #
35
- # user_presenter = UserPresenter.wrap :user
36
- #
37
- # A block can also be passed to use the presenter. For example:
38
- #
39
- # <% UserPresenter.wrap @user do |user_presenter| %>
40
- # Username: <%= user_presenter.username %>
41
- # <% end %>
42
- #
43
- def self.wrap *objects
44
- presenter = self.new *objects
45
- yield presenter if block_given?
46
- presenter
47
- end
48
-
49
- # Wraps each model in a collection with the presenter. A block can also be
50
- # passed to use each presenter immediately. For example:
51
- #
52
- # <ul>
53
- # <% UserPresenter.wrap_each @users do |user_presenter| %>
54
- # <li><%= user_presenter.username %></li>
55
- # <% end %>
56
- # </ul>
57
- #
58
- def self.wrap_each collection
59
- collection.map! do |object|
60
- self.wrap object do |presenter|
61
- yield presenter if block_given?
62
- end
63
- end
64
- collection.send :extend, StrongPresenter::CollectionHelper
65
- collection
66
- end
67
-
68
- # Performs mass presentation - if it is allowed, subject to `permit`. To permit all without checking, call `permit!` first.
69
- #
70
- # Presents and returns the result of each field in the argument list. If a block is given, then each result
71
- # is passed to the block. Each field is presented by calling the method on the presenter.
72
- #
73
- # user_presenter.presents :username, :email # returns [user_presenter.username, user_presenter.email]
74
- #
75
- # Or with two arguments, the name of the field is passed first:
76
- #
77
- # <ul>
78
- # <% user_presenter.presents :username, :email, :address do |field, value| %>
79
- # <li><%= field.capitalize %>: <% value %></li>
80
- # <% end %>
81
- # </ul>
82
- #
83
- # If only the presented value is desired, use `each`:
84
- #
85
- # <% user_presenter.presents(:username, :email).each do |value| %>
86
- # <td><%= value %></td>
87
- # <% end %>
88
- #
89
- # A field can have arguments in an array:
90
- #
91
- # user_presenter.presents :username, [:notifications, :unread] # returns [user_presenter.username, user_presenter.notifications(:unread)]
92
- #
93
- # Notice that this interface allows you to concisely put authorization logic in the controller, with a dumb view layer:
94
- #
95
- # # app/controllers/users_controller.rb
96
- # class UsersController < ApplicationController
97
- # def visible_params
98
- # @visible_params ||= begin
99
- # field = [:username]
100
- # field << :email if can? :read_email, @user
101
- # field << :edit_link if can? :edit, @user
102
- # end
103
- # end
104
- # def show
105
- # @users_presenter = UserPresenter.wrap_each(User.all).permit!
106
- # end
107
- # end
108
- #
109
- # # app/views/users/show.html.erb
110
- # <table>
111
- # <tr>
112
- # <% visible_params.each do |field| %>
113
- # <th><%= field %></th>
114
- # <% end %>
115
- # </tr>
116
- # <% @users_presenter.each do |user_presenter| %>
117
- # <tr>
118
- # <% user_presenter.presents(*visible_params).each do |value| %>
119
- # <td><%= value %></td>
120
- # <% end %>
121
- # </tr>
122
- # <% end %>
123
- # </table>
124
- #
125
- def presents *fields, &block
126
- process_fields(fields).map do |args|
127
- value = self.public_send *args
128
- yield args[0], value if block_given?
129
- value
130
- end
131
- end
132
-
133
- # Checks which fields are visible according to what is permitted. An array is returned.
134
- # The array can be converted to labels using `to_labels`
135
- #
136
- def filter *fields
137
- fields = process_fields(fields).map(&:first)
138
- presenter_class = self.class
139
- (class << fields; self; end).class_eval do
140
- define_method :to_labels do
141
- presenter_class.label fields
142
- end
143
- end
144
- fields
145
- end
146
-
147
- # Pass a hash to set field labels { field => label}
148
- # Pass an array to retrieve labels for field symbols. If no label is set, the return
149
- # value is the humanized field by default.
150
- #
151
- def self.label fields
152
- @labels ||= {}
153
- if fields.class == Hash
154
- @labels.merge!(fields)
155
- else
156
- labels = Array(fields).map { |field| @labels[field] || field.to_s.humanize }
157
- return labels if fields.respond_to? :map
158
- labels.first
159
- end
160
- end
161
-
162
- # Sets fields which will be permitted. May be invoked multiple times.
163
- #
164
- def permit *fields
165
- self.permitted_attributes.merge fields if permitted_attributes != :all
166
- self
167
- end
168
-
169
- # Permits all fields
170
- #
171
- def permit!
172
- @permitted_attributes = :all
173
- self
174
- end
175
-
176
- protected
177
- def permitted_attributes
178
- @permitted_attributes ||= Set.new
179
- end
180
-
181
- private
182
- def process_fields fields
183
- fields.map! do |field|
184
- field = Array(field)
185
- field[0] = field[0].to_sym
186
- field
187
- end
188
- fields.select! { |field| permitted_attributes.include? field[0] } if permitted_attributes != :all
189
- fields
190
- end
191
-
192
- # Sets the model presented by the class
193
- #
194
- def self.presents name
195
- define_method name do
196
- @object
197
- end
198
- end
199
-
200
- # Permits all fields in the presenter for mass presentation
201
- #
202
- def self.permit!
203
- define_method(:permitted_attributes){:all}
204
- end
205
-
206
- def object
207
- @object
208
- end
209
-
210
- # Access to view helpers
211
- #
212
- def h
213
- @helper ||= StrongPresenter::HelperProxy.new
214
- end
215
-
216
- end
217
- end