presenter_object 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -0
- data/lib/presenter_object/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 132924c09476de5872f7c0df625965de02230dea
|
4
|
+
data.tar.gz: e9e43a18c353b8fcb204bf2c9abf748bd790c00d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdf446baa6982dba695dbf5eb8a49c768dd82c8ea02a259e5b695a1f1fb1348c5615223e42b662925fa5c16939f02d442ffe44dcb63fe0eac1579dc1d1215192
|
7
|
+
data.tar.gz: aec48caee7e13737f71acd9128e943fb6deb1dac74cfff7c91d5b237780f57521c5b62acc43d9d088c02a85d79081b016a479ea40bcc4086f12bfeb1e2734122
|
data/README.md
CHANGED
@@ -54,6 +54,29 @@ The `@user` presenter object can be used as if it were the model object. Then, j
|
|
54
54
|
@user.formatted_phone_number # => "(555) 444-3322"
|
55
55
|
```
|
56
56
|
|
57
|
+
### Collection Presenter
|
58
|
+
|
59
|
+
You can also wrap whole collections of objects at once. Create a collection presenter:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
class UserCollectionPresenter < PresenterObject::Collection
|
63
|
+
def render_table
|
64
|
+
each do |object|
|
65
|
+
# object is now wrapped in its presenter
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
Instantiate the collection presenter by passing in an object collection and an optional view_context:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
@user_collection = UserCollectionPresenter.new User.all, view_context
|
75
|
+
@user_collection.render_table
|
76
|
+
```
|
77
|
+
|
78
|
+
The `@user_collection` instance is an `Enumerable` and will lazily wrap each object when you iterate over the collection.
|
79
|
+
|
57
80
|
## Development
|
58
81
|
|
59
82
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|