easy_presenter 1.0.0 → 1.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f55e09c891f829eb8db5291671fcae84347b2701
4
- data.tar.gz: 55030a1f38b0ae43c7bf7f7febdfdd834f2bf601
3
+ metadata.gz: b0a86beeb7a5bcf06f9eba3edf7a1def8cfd4269
4
+ data.tar.gz: 7c8a99589f8221df2e7d1f6f3723eb691d94f491
5
5
  SHA512:
6
- metadata.gz: f934578a6067f482cca8a5e21bbc8325ad0f5fb2134d441692171784e9c0ababce61d16c50f6ca2a131f5a7dac0424527ba6731dceedfbb66db2599bc42051df
7
- data.tar.gz: d1af8a7912d2e3279ddedafcbf4b864b91fcffc47f6bd889011ceef281adb4fe6cb0f9bb63bcf14a6d262230b8a00b6f4e8d66b38b78a90a7a352f66c0344cea
6
+ metadata.gz: d7ada92812250dd0e5824e473ab18dd001136d568fd9ab6bd2075a09c3445bc7a635bc88fcc94a19516a687fea2bea295c8209f34e401464513156454c23bc0e
7
+ data.tar.gz: 2fea4d3703aaade50bbfd077d79c9d9b64a48de757b728a9459e9bcdcdf0c874bddc9507c91dd47a22e99305c35174599899de31f118e188c03397f0779abe88
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # EasyPresenter
2
2
 
3
- Access view methods from the context of your model.
3
+ Access view methods from the context of your `Ruby on Rails` model.
4
4
 
5
5
  ## Usage
6
6
  ### Easy
@@ -55,11 +55,49 @@ end
55
55
  `ActiveRecord`, `Mongoid`, you may add support to an ORM at the bottom of `lib/easy_presenter.rb` and send in a pull request if you wish.
56
56
 
57
57
  ### Advanced
58
- You may use the following modules to add EasyPresenter to other classes.
58
+ You may `include` the following modules to add EasyPresenter to other classes.
59
59
 
60
+ * `easy_presenter_subclass` - for handling subclasses
60
61
  * `EasyPresenter::Base` - add access to view methods
61
62
  * `EasyPresenter` - `EasyPresenter::Base` and if `method_missing?`, give access to the `ClassNamePresenter` class
62
63
 
64
+
65
+ To add access to view methods to all instances or subclasses (such as an ORM).
66
+ ```ruby
67
+ # config/initializers/add_presenter_to_orm.rb
68
+ # Find the base or shared class, for `ActiveRecord` it's `ActiveRecord::Base` and `Mongoid` it's `Mongoid::Document`
69
+ Orm::BaseClass.send :include, EasyPresenter
70
+ ```
71
+
72
+ For all instances of a basic class.
73
+ ```ruby
74
+ # app/models/non_database_model.rb
75
+ class NonDatabaseModel
76
+ include EasyPresenter
77
+ end
78
+
79
+ # app/presenters/non_database_model_presenter.rb
80
+ module NonDatabaseModelPresenter
81
+ ...
82
+
83
+ module ClassMethods
84
+ ...
85
+ end
86
+ end
87
+ ```
88
+
89
+ For all instances of a basic class without need of a `ClassNamePresenter` class.
90
+ ```ruby
91
+ # app/models/some_view_object.rb
92
+ class SomeViewObject
93
+ include EasyPresenter::Base
94
+
95
+ def random_link
96
+ link_to "random", "http://www.random.com"
97
+ end
98
+ end
99
+ ```
100
+
63
101
  ## Credits
64
102
  Extracted out of [Placemark](https://www.placemarkhq.com/).
65
103
 
@@ -1,3 +1,3 @@
1
1
  module EasyPresenter
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -6,11 +6,19 @@ module EasyPresenter
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  included do
9
- presenter_class = "#{self}Presenter".safe_constantize
10
- if presenter_class
11
- include Base
12
- presenter_class.extend ActiveSupport::Concern
13
- include presenter_class
9
+ easy_presenter_subclass
10
+ end
11
+
12
+ module ClassMethods
13
+ protected
14
+ def easy_presenter_subclass
15
+ presenter_class = "#{self}Presenter".safe_constantize
16
+ if presenter_class
17
+ presenter_class.extend ActiveSupport::Concern
18
+ include presenter_class
19
+ include Base
20
+ end
21
+ presenter_class
14
22
  end
15
23
  end
16
24
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - s12chung
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-13 00:00:00.000000000 Z
11
+ date: 2013-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler