dekorator 1.0.0.pre.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.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +14 -0
  3. data/.gitignore +11 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +114 -0
  6. data/.simplecov +5 -0
  7. data/.travis.yml +37 -0
  8. data/Appraisals +17 -0
  9. data/CHANGELOG.md +16 -0
  10. data/CODE_OF_CONDUCT.md +74 -0
  11. data/Gemfile +22 -0
  12. data/Gemfile.lock +157 -0
  13. data/LICENSE.txt +21 -0
  14. data/README.md +179 -0
  15. data/Rakefile +21 -0
  16. data/bin/console +16 -0
  17. data/bin/setup +8 -0
  18. data/dekorator.gemspec +34 -0
  19. data/gemfiles/.bundle/config +2 -0
  20. data/gemfiles/rails_5.0.x.gemfile +21 -0
  21. data/gemfiles/rails_5.0.x.gemfile.lock +207 -0
  22. data/gemfiles/rails_5.1.x.gemfile +21 -0
  23. data/gemfiles/rails_5.1.x.gemfile.lock +207 -0
  24. data/gemfiles/rails_5.2.x.gemfile +21 -0
  25. data/gemfiles/rails_5.2.x.gemfile.lock +207 -0
  26. data/gemfiles/rails_6.0.x.gemfile +21 -0
  27. data/gemfiles/rails_6.0.x.gemfile.lock +220 -0
  28. data/lib/dekorator.rb +123 -0
  29. data/lib/dekorator/decorators_helper.rb +5 -0
  30. data/lib/dekorator/railtie.rb +11 -0
  31. data/lib/dekorator/rspec.rb +0 -0
  32. data/lib/dekorator/version.rb +5 -0
  33. data/lib/generators/decorator/USAGE +9 -0
  34. data/lib/generators/decorator/decorator_generator.rb +11 -0
  35. data/lib/generators/decorator/templates/decorator.rb +17 -0
  36. data/lib/generators/decorator/templates/decorator_test.rb +1 -0
  37. data/lib/generators/dekorator/install_generator.rb +35 -0
  38. data/lib/generators/rspec/decorator_generator.rb +13 -0
  39. data/lib/generators/rspec/templates/decorator_spec.rb +17 -0
  40. data/lib/generators/test_unit/decorator_generator.rb +13 -0
  41. data/lib/generators/test_unit/templates/decorator_test.rb +6 -0
  42. metadata +187 -0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Pantographe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,179 @@
1
+ # Dekorator
2
+
3
+ [![Build Status](https://travis-ci.org/pantographe/dekorator.svg?branch=master)](https://travis-ci.org/pantographe/dekorator)
4
+ [![Gem Version](https://badge.fury.io/rb/dekorator.svg)](https://rubygems.org/gems/dekorator)
5
+ [![Coverage Status](https://coveralls.io/repos/github/pantographe/dekorator/badge.svg)](https://coveralls.io/github/pantographe/dekorator)
6
+ [![Inch CI](https://inch-ci.org/github/pantographe/dekorator.svg?branch=master)](https://inch-ci.org/github/pantographe/dekorator)
7
+ [![Yardoc](https://img.shields.io/badge/doc-yardoc-blue.svg)](https://www.rubydoc.info/github/pantographe/dekorator/master)
8
+
9
+ **Dekorator** is an opinionated way of organizing model-view code in Ruby on Rails, based on _decorators_.
10
+
11
+ **Not production ready**
12
+
13
+ ## Compatibility
14
+
15
+ * Ruby 2.3+
16
+ * Rails 5.0+
17
+
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem "dekorator"
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+
32
+ ## Getting started
33
+
34
+ Run the following command to set up your project:
35
+
36
+ $ rails generate dekorator:install
37
+
38
+ This command will create an `ApplicationDecorator` file.
39
+
40
+
41
+ ## Usage
42
+
43
+ Generate a new decorator with the `decorator` generator:
44
+
45
+ $ rails generate decorator user
46
+
47
+ This command will generate the following file:
48
+
49
+ ```ruby
50
+ class UserDecorator < ApplicationDecorator
51
+ # include ActionView::Helpers::TextHelper
52
+ #
53
+ # decorates_association :posts
54
+ #
55
+ # def full_name
56
+ # [first_name, last_name].join(" ")
57
+ # end
58
+ #
59
+ # def biography_summary
60
+ # truncate(biography, length: 170)
61
+ # end
62
+ end
63
+ ```
64
+
65
+ ### Associations
66
+
67
+ If you want to automatically decorates association for a decorated object,
68
+ you have to use `#decorates_association` as following:
69
+
70
+ ```ruby
71
+ class UserDecorator < ApplicationDecorator
72
+ decorates_association :posts
73
+
74
+ ...
75
+ end
76
+
77
+ class PostDecorator < ApplicationDecorator
78
+ ...
79
+ end
80
+ ```
81
+
82
+ In this example, `UserDecorator#posts` will be decorated.
83
+
84
+ ```ruby
85
+ decorated_user = decorator(User.first)
86
+ decorated_user # => UserDecorator
87
+ decorated_user.posts.first # => PostDecorator
88
+ ```
89
+
90
+ ### Specify decorator
91
+
92
+ If you want to create specific decorator or sub-decorator, you could simply
93
+ specify the decorator class that should be use.
94
+
95
+ ```ruby
96
+ class AdminDecorator < ApplicationDecorator
97
+ end
98
+
99
+ decorated_user = decorator(User.first, with: AdminDecorator)
100
+ decorated_user # => AdminDecorator
101
+ ```
102
+
103
+ You also could specify the decorator for associations:
104
+
105
+ ```ruby
106
+ class UserDecorator < ApplicationDecorator
107
+ decorates_association :posts, ArticleDecorator
108
+
109
+ ...
110
+ end
111
+
112
+ class ArticleDecorator < ApplicationDecorator
113
+ end
114
+
115
+ decorated_user = decorator(User.first)
116
+ decorated_user # => UserDecorator
117
+ decorated_user.posts.first # => ArticleDecorator
118
+ ```
119
+
120
+ ## Compatibility
121
+
122
+ ### ActiveAdmin
123
+
124
+ This gem is compatible with [`activeadmin`][activeadmin].
125
+
126
+ Simply use `#decorate_with`
127
+
128
+ ```ruby
129
+ # app/admin/post.rb
130
+ ActiveAdmin.register Post do
131
+ decorate_with PostDecorator
132
+
133
+ index do
134
+ column :title
135
+ column :image
136
+ actions
137
+ end
138
+ end
139
+ ```
140
+
141
+ ### Devise
142
+
143
+ If you use [`device`][devise] gem you may have an issue if you decorate your
144
+ `User` model.
145
+
146
+ You must define `#devise_scope` as following. Devise need to manage with
147
+ `User` model (https://github.com/plataformatec/devise/blob/369ba267efaa10d01c8dba59b09c3b94dd9e5551/lib/devise/mapping.rb#L35).
148
+
149
+ ```ruby
150
+ class UserDecorator < ApplicationDecorator
151
+ ...
152
+
153
+ def devise_scope
154
+ __getobj__
155
+ end
156
+ end
157
+ ```
158
+
159
+
160
+ ## Development
161
+
162
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
163
+
164
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
165
+
166
+ ## Contributing
167
+
168
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pantographe/dekorator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
169
+
170
+ ## License
171
+
172
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
173
+
174
+ ## Code of Conduct
175
+
176
+ Everyone interacting in the Dekorator project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/pantographe/dekorator/blob/master/CODE_OF_CONDUCT.md).
177
+
178
+ [activeadmin]: https://activeadmin.info/11-decorators.html
179
+ [devise]: https://github.com/plataformatec/devise/
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+ require "rspec/core/rake_task"
6
+ require "coveralls/rake/task"
7
+
8
+ namespace :test do
9
+ task all: %i[rubocop spec]
10
+ task all_with_coverage: %i[all coveralls:push]
11
+
12
+ RuboCop::RakeTask.new
13
+
14
+ RSpec::Core::RakeTask.new(:spec)
15
+
16
+ Coveralls::RakeTask.new
17
+ end
18
+
19
+ task test: :"test:all"
20
+
21
+ task default: :test
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "bundler/setup"
6
+ require "dekorator"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require "irb"
16
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "dekorator/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "dekorator"
9
+ spec.version = Dekorator::VERSION
10
+ spec.authors = ["Nicolas Brousse"]
11
+ spec.email = ["nicolas@pantographe.studio"]
12
+
13
+ spec.summary = "An opinionated way of organizing model-view code in Ruby on Rails, based on decorators"
14
+ spec.description = "An opinionated way of organizing model-view code in Ruby on Rails, based on decorators"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.required_ruby_version = ">= 2.3"
26
+
27
+ spec.add_runtime_dependency "actionview", ">= 5.0", "< 6.1"
28
+ spec.add_runtime_dependency "activesupport", ">= 5.0", "< 6.1"
29
+ spec.add_runtime_dependency "railties", ">= 5.0", "< 6.1"
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ end
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by Appraisal
4
+
5
+ source "https://rubygems.org"
6
+
7
+ gem "activerecord"
8
+ gem "activemodel"
9
+ gem "activesupport"
10
+ gem "actionview"
11
+ gem "railties"
12
+ gem "appraisal", require: false
13
+ gem "rubocop", require: false
14
+ gem "rails", "~> 5.0"
15
+
16
+ group :test do
17
+ gem "simplecov", require: false
18
+ gem "coveralls", require: false
19
+ end
20
+
21
+ gemspec path: "../"
@@ -0,0 +1,207 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ dekorator (1.0.0.pre.1)
5
+ actionview (>= 5.0, < 6.1)
6
+ activesupport (>= 5.0, < 6.1)
7
+ railties (>= 5.0, < 6.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actioncable (5.2.2)
13
+ actionpack (= 5.2.2)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailer (5.2.2)
17
+ actionpack (= 5.2.2)
18
+ actionview (= 5.2.2)
19
+ activejob (= 5.2.2)
20
+ mail (~> 2.5, >= 2.5.4)
21
+ rails-dom-testing (~> 2.0)
22
+ actionpack (5.2.2)
23
+ actionview (= 5.2.2)
24
+ activesupport (= 5.2.2)
25
+ rack (~> 2.0)
26
+ rack-test (>= 0.6.3)
27
+ rails-dom-testing (~> 2.0)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
+ actionview (5.2.2)
30
+ activesupport (= 5.2.2)
31
+ builder (~> 3.1)
32
+ erubi (~> 1.4)
33
+ rails-dom-testing (~> 2.0)
34
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
35
+ activejob (5.2.2)
36
+ activesupport (= 5.2.2)
37
+ globalid (>= 0.3.6)
38
+ activemodel (5.2.2)
39
+ activesupport (= 5.2.2)
40
+ activerecord (5.2.2)
41
+ activemodel (= 5.2.2)
42
+ activesupport (= 5.2.2)
43
+ arel (>= 9.0)
44
+ activestorage (5.2.2)
45
+ actionpack (= 5.2.2)
46
+ activerecord (= 5.2.2)
47
+ marcel (~> 0.3.1)
48
+ activesupport (5.2.2)
49
+ concurrent-ruby (~> 1.0, >= 1.0.2)
50
+ i18n (>= 0.7, < 2)
51
+ minitest (~> 5.1)
52
+ tzinfo (~> 1.1)
53
+ appraisal (2.2.0)
54
+ bundler
55
+ rake
56
+ thor (>= 0.14.0)
57
+ arel (9.0.0)
58
+ ast (2.4.0)
59
+ builder (3.2.3)
60
+ concurrent-ruby (1.1.4)
61
+ coveralls (0.7.1)
62
+ multi_json (~> 1.3)
63
+ rest-client
64
+ simplecov (>= 0.7)
65
+ term-ansicolor
66
+ thor
67
+ crass (1.0.4)
68
+ diff-lcs (1.3)
69
+ docile (1.3.1)
70
+ domain_name (0.5.20180417)
71
+ unf (>= 0.0.5, < 1.0.0)
72
+ erubi (1.8.0)
73
+ globalid (0.4.2)
74
+ activesupport (>= 4.2.0)
75
+ http-cookie (1.0.3)
76
+ domain_name (~> 0.5)
77
+ i18n (1.5.3)
78
+ concurrent-ruby (~> 1.0)
79
+ jaro_winkler (1.5.2)
80
+ json (2.1.0)
81
+ loofah (2.2.3)
82
+ crass (~> 1.0.2)
83
+ nokogiri (>= 1.5.9)
84
+ mail (2.7.1)
85
+ mini_mime (>= 0.1.1)
86
+ marcel (0.3.3)
87
+ mimemagic (~> 0.3.2)
88
+ method_source (0.9.2)
89
+ mime-types (3.2.2)
90
+ mime-types-data (~> 3.2015)
91
+ mime-types-data (3.2018.0812)
92
+ mimemagic (0.3.3)
93
+ mini_mime (1.0.1)
94
+ mini_portile2 (2.4.0)
95
+ minitest (5.11.3)
96
+ multi_json (1.13.1)
97
+ netrc (0.11.0)
98
+ nio4r (2.3.1)
99
+ nokogiri (1.10.1)
100
+ mini_portile2 (~> 2.4.0)
101
+ parallel (1.13.0)
102
+ parser (2.6.0.0)
103
+ ast (~> 2.4.0)
104
+ powerpack (0.1.2)
105
+ rack (2.0.6)
106
+ rack-test (1.1.0)
107
+ rack (>= 1.0, < 3)
108
+ rails (5.2.2)
109
+ actioncable (= 5.2.2)
110
+ actionmailer (= 5.2.2)
111
+ actionpack (= 5.2.2)
112
+ actionview (= 5.2.2)
113
+ activejob (= 5.2.2)
114
+ activemodel (= 5.2.2)
115
+ activerecord (= 5.2.2)
116
+ activestorage (= 5.2.2)
117
+ activesupport (= 5.2.2)
118
+ bundler (>= 1.3.0)
119
+ railties (= 5.2.2)
120
+ sprockets-rails (>= 2.0.0)
121
+ rails-dom-testing (2.0.3)
122
+ activesupport (>= 4.2.0)
123
+ nokogiri (>= 1.6)
124
+ rails-html-sanitizer (1.0.4)
125
+ loofah (~> 2.2, >= 2.2.2)
126
+ railties (5.2.2)
127
+ actionpack (= 5.2.2)
128
+ activesupport (= 5.2.2)
129
+ method_source
130
+ rake (>= 0.8.7)
131
+ thor (>= 0.19.0, < 2.0)
132
+ rainbow (3.0.0)
133
+ rake (10.5.0)
134
+ rest-client (2.0.2)
135
+ http-cookie (>= 1.0.2, < 2.0)
136
+ mime-types (>= 1.16, < 4.0)
137
+ netrc (~> 0.8)
138
+ rspec (3.8.0)
139
+ rspec-core (~> 3.8.0)
140
+ rspec-expectations (~> 3.8.0)
141
+ rspec-mocks (~> 3.8.0)
142
+ rspec-core (3.8.0)
143
+ rspec-support (~> 3.8.0)
144
+ rspec-expectations (3.8.2)
145
+ diff-lcs (>= 1.2.0, < 2.0)
146
+ rspec-support (~> 3.8.0)
147
+ rspec-mocks (3.8.0)
148
+ diff-lcs (>= 1.2.0, < 2.0)
149
+ rspec-support (~> 3.8.0)
150
+ rspec-support (3.8.0)
151
+ rubocop (0.63.1)
152
+ jaro_winkler (~> 1.5.1)
153
+ parallel (~> 1.10)
154
+ parser (>= 2.5, != 2.5.1.1)
155
+ powerpack (~> 0.1)
156
+ rainbow (>= 2.2.2, < 4.0)
157
+ ruby-progressbar (~> 1.7)
158
+ unicode-display_width (~> 1.4.0)
159
+ ruby-progressbar (1.10.0)
160
+ simplecov (0.16.1)
161
+ docile (~> 1.1)
162
+ json (>= 1.8, < 3)
163
+ simplecov-html (~> 0.10.0)
164
+ simplecov-html (0.10.2)
165
+ sprockets (3.7.2)
166
+ concurrent-ruby (~> 1.0)
167
+ rack (> 1, < 3)
168
+ sprockets-rails (3.2.1)
169
+ actionpack (>= 4.0)
170
+ activesupport (>= 4.0)
171
+ sprockets (>= 3.0.0)
172
+ term-ansicolor (1.7.1)
173
+ tins (~> 1.0)
174
+ thor (0.20.3)
175
+ thread_safe (0.3.6)
176
+ tins (1.20.2)
177
+ tzinfo (1.2.5)
178
+ thread_safe (~> 0.1)
179
+ unf (0.1.4)
180
+ unf_ext
181
+ unf_ext (0.0.7.5)
182
+ unicode-display_width (1.4.1)
183
+ websocket-driver (0.7.0)
184
+ websocket-extensions (>= 0.1.0)
185
+ websocket-extensions (0.1.3)
186
+
187
+ PLATFORMS
188
+ ruby
189
+
190
+ DEPENDENCIES
191
+ actionview
192
+ activemodel
193
+ activerecord
194
+ activesupport
195
+ appraisal
196
+ bundler (~> 2.0)
197
+ coveralls
198
+ dekorator!
199
+ rails (~> 5.0)
200
+ railties
201
+ rake (~> 10.0)
202
+ rspec (~> 3.0)
203
+ rubocop
204
+ simplecov
205
+
206
+ BUNDLED WITH
207
+ 2.0.1