light-decorator 0.5.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -0
- data/README.md +19 -14
- data/gemfiles/rails_4_0.gemfile.lock +5 -1
- data/gemfiles/rails_4_1.gemfile.lock +5 -1
- data/gemfiles/rails_4_2.gemfile.lock +5 -1
- data/gemfiles/rails_5_0.gemfile.lock +5 -1
- data/lib/generators/light/decorator/install/install_generator.rb +13 -0
- data/lib/generators/light/decorator/install/templates/application_decorator.rb +2 -0
- data/lib/generators/rails/decorator/decorator_generator.rb +14 -0
- data/lib/generators/rails/decorator/templates/decorator.rb +10 -0
- data/lib/generators/rails/hooks.rb +20 -0
- data/lib/generators/rspec/decorator/decorator_generator.rb +11 -0
- data/lib/generators/rspec/decorator/templates/decorator_spec.rb +5 -0
- data/lib/generators/test_unit/decorator/decorator_generator.rb +11 -0
- data/lib/generators/test_unit/decorator/templates/decorator_test.rb +6 -0
- data/lib/light/decorator/decorate.rb +1 -1
- data/lib/light/decorator/railtie.rb +7 -1
- data/lib/light/decorator/version.rb +1 -1
- data/light-decorator.gemspec +1 -0
- metadata +25 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 247bcaa3a6bb0fe2bbe4f112e0422dcd5f294a21
|
4
|
+
data.tar.gz: d501bf7b57e024db89623b2eb7ec7ecb52bc3e73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbf95ea9db48bfc27651e8753ad2c0390ae2755cc6136ac27a04fd0d2156f7e54e4f1315c66e75aa9a3b002f20baf7d18c7322143f718f1c78d4352b3e451cb3
|
7
|
+
data.tar.gz: f2468f0a450f5b6be3f0eeeec071a5c642e491903beeeea03f8eb6b7d0c805aa477b7ee8de28a8131c08d653586991611bbec590a7b52c87b60890d2c78a50dc
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 2.0
|
3
3
|
DisabledByDefault: true
|
4
|
+
Exclude:
|
5
|
+
- 'lib/generators/rails/decorator/templates/decorator.rb'
|
6
|
+
- 'lib/generators/rspec/decorator/templates/decorator_spec.rb'
|
7
|
+
- 'lib/generators/test_unit/decorator/templates/decorator_test.rb'
|
8
|
+
- 'lib/generators/light/decorator/install/templates/application_decorator.rb'
|
4
9
|
|
5
10
|
#################### Lint ################################
|
6
11
|
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
# Light
|
1
|
+
# Light Decorator
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/light-ruby/light-decorator.svg?branch=master)](https://travis-ci.org/light-ruby/light-decorator)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/light-ruby/light-decorator/badges/gpa.svg)](https://codeclimate.com/github/light-ruby/light-decorator)
|
5
5
|
[![Test Coverage](https://codeclimate.com/github/light-ruby/light-decorator/badges/coverage.svg)](https://codeclimate.com/github/light-ruby/light-decorator/coverage)
|
6
6
|
|
7
|
-
Easiest and fast way to decorate Ruby on Rails models.
|
7
|
+
Easiest and fast way to decorate Ruby on Rails models. Compatible with Rails 5.0 and 4.2, 4.1, 4.0.
|
8
8
|
|
9
|
-
Decorator
|
9
|
+
Decorator Pattern – What is it? Check it here:
|
10
10
|
- [Wikipedia](https://en.wikipedia.org/wiki/Decorator_pattern)
|
11
11
|
- [Thoughtbot](https://robots.thoughtbot.com/evaluating-alternative-decorator-implementations-in)
|
12
12
|
|
@@ -15,20 +15,19 @@ Decorator pattern - What is it?
|
|
15
15
|
Add this line to your application's Gemfile:
|
16
16
|
|
17
17
|
```ruby
|
18
|
-
gem 'light-decorator', '~> 0.
|
18
|
+
gem 'light-decorator', '~> 1.0.0'
|
19
19
|
```
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
Create the `ApplicationDecorator`
|
21
|
+
Create base class `ApplicationDecorator` in folder `app/decorators/application_decorator.rb`
|
24
22
|
|
25
|
-
```
|
26
|
-
|
27
|
-
class ApplicationDecorator < Light::Decorator::Decorate
|
28
|
-
end
|
23
|
+
```
|
24
|
+
rails g light:decorator:install
|
29
25
|
```
|
30
26
|
|
27
|
+
## Usage
|
28
|
+
|
31
29
|
Create decorator for your model. For example we will use the `User` model.
|
30
|
+
We can manually create file:
|
32
31
|
|
33
32
|
```ruby
|
34
33
|
# app/decorators/user_decorator.rb
|
@@ -39,6 +38,12 @@ class UserDecorator < Application
|
|
39
38
|
end
|
40
39
|
```
|
41
40
|
|
41
|
+
Or we can just use command to create this file:
|
42
|
+
|
43
|
+
```
|
44
|
+
rails g decorator User
|
45
|
+
```
|
46
|
+
|
42
47
|
Decorate your model in controller or anywhere.
|
43
48
|
|
44
49
|
```ruby
|
@@ -75,15 +80,15 @@ class UserDecorator < ApplicationDecorator
|
|
75
80
|
def full_name_link
|
76
81
|
helpers.link_to full_name, user_path(object)
|
77
82
|
# or
|
78
|
-
h.link_to full_name, user_path(
|
83
|
+
h.link_to full_name, user_path(o)
|
79
84
|
end
|
80
85
|
end
|
81
86
|
```
|
82
87
|
|
83
88
|
## Next steps
|
84
89
|
|
85
|
-
- [
|
86
|
-
- [
|
90
|
+
- [x] Create installation generator
|
91
|
+
- [x] Create decorator generator
|
87
92
|
- [ ] Create configuration file
|
88
93
|
|
89
94
|
## Contributing
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
light-decorator (0.
|
4
|
+
light-decorator (1.0.0)
|
5
5
|
rails (>= 4.0.0)
|
6
6
|
request_store (>= 1.0.0)
|
7
7
|
|
@@ -59,6 +59,9 @@ GEM
|
|
59
59
|
factory_girl (4.7.0)
|
60
60
|
activesupport (>= 3.0.0)
|
61
61
|
ffaker (2.2.0)
|
62
|
+
generator_spec (0.9.3)
|
63
|
+
activesupport (>= 3.0.0)
|
64
|
+
railties (>= 3.0.0)
|
62
65
|
i18n (0.7.0)
|
63
66
|
json (1.8.3)
|
64
67
|
mail (2.6.4)
|
@@ -134,6 +137,7 @@ DEPENDENCIES
|
|
134
137
|
combustion (~> 0.5.4)
|
135
138
|
factory_girl (~> 4.0)
|
136
139
|
ffaker (~> 2.2.0)
|
140
|
+
generator_spec (~> 0.9.3)
|
137
141
|
light-decorator!
|
138
142
|
rails (= 4.0.13)
|
139
143
|
rake (~> 10.0)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
light-decorator (0.
|
4
|
+
light-decorator (1.0.0)
|
5
5
|
rails (>= 4.0.0)
|
6
6
|
request_store (>= 1.0.0)
|
7
7
|
|
@@ -61,6 +61,9 @@ GEM
|
|
61
61
|
factory_girl (4.7.0)
|
62
62
|
activesupport (>= 3.0.0)
|
63
63
|
ffaker (2.2.0)
|
64
|
+
generator_spec (0.9.3)
|
65
|
+
activesupport (>= 3.0.0)
|
66
|
+
railties (>= 3.0.0)
|
64
67
|
i18n (0.7.0)
|
65
68
|
json (1.8.3)
|
66
69
|
mail (2.6.4)
|
@@ -138,6 +141,7 @@ DEPENDENCIES
|
|
138
141
|
combustion (~> 0.5.4)
|
139
142
|
factory_girl (~> 4.0)
|
140
143
|
ffaker (~> 2.2.0)
|
144
|
+
generator_spec (~> 0.9.3)
|
141
145
|
light-decorator!
|
142
146
|
rails (= 4.1.15)
|
143
147
|
rake (~> 10.0)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
light-decorator (0.
|
4
|
+
light-decorator (1.0.0)
|
5
5
|
rails (>= 4.0.0)
|
6
6
|
request_store (>= 1.0.0)
|
7
7
|
|
@@ -70,6 +70,9 @@ GEM
|
|
70
70
|
factory_girl (4.7.0)
|
71
71
|
activesupport (>= 3.0.0)
|
72
72
|
ffaker (2.2.0)
|
73
|
+
generator_spec (0.9.3)
|
74
|
+
activesupport (>= 3.0.0)
|
75
|
+
railties (>= 3.0.0)
|
73
76
|
globalid (0.3.6)
|
74
77
|
activesupport (>= 4.1.0)
|
75
78
|
i18n (0.7.0)
|
@@ -160,6 +163,7 @@ DEPENDENCIES
|
|
160
163
|
combustion (~> 0.5.4)
|
161
164
|
factory_girl (~> 4.0)
|
162
165
|
ffaker (~> 2.2.0)
|
166
|
+
generator_spec (~> 0.9.3)
|
163
167
|
light-decorator!
|
164
168
|
rails (= 4.2.6)
|
165
169
|
rake (~> 10.0)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
light-decorator (0.
|
4
|
+
light-decorator (1.0.0)
|
5
5
|
rails (>= 4.0.0)
|
6
6
|
request_store (>= 1.0.0)
|
7
7
|
|
@@ -72,6 +72,9 @@ GEM
|
|
72
72
|
factory_girl (4.7.0)
|
73
73
|
activesupport (>= 3.0.0)
|
74
74
|
ffaker (2.2.0)
|
75
|
+
generator_spec (0.9.3)
|
76
|
+
activesupport (>= 3.0.0)
|
77
|
+
railties (>= 3.0.0)
|
75
78
|
globalid (0.3.6)
|
76
79
|
activesupport (>= 4.1.0)
|
77
80
|
i18n (0.7.0)
|
@@ -170,6 +173,7 @@ DEPENDENCIES
|
|
170
173
|
combustion (~> 0.5.4)
|
171
174
|
factory_girl (~> 4.0)
|
172
175
|
ffaker (~> 2.2.0)
|
176
|
+
generator_spec (~> 0.9.3)
|
173
177
|
light-decorator!
|
174
178
|
rails (= 5.0.0.rc1)
|
175
179
|
rake (~> 10.0)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Light
|
2
|
+
module Decorator
|
3
|
+
module Generators
|
4
|
+
class InstallGenerator < ::Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def create_application_decorator
|
8
|
+
template 'application_decorator.rb', File.join('app/decorators', 'application_decorator.rb')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Rails
|
2
|
+
module Generators
|
3
|
+
class DecoratorGenerator < ::Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
check_class_collision suffix: 'Decorator'
|
6
|
+
|
7
|
+
def create_decorator
|
8
|
+
template 'decorator.rb', File.join('app/decorators', class_path, "#{file_name}_decorator.rb")
|
9
|
+
end
|
10
|
+
|
11
|
+
hook_for :test_framework
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/rails/model/model_generator'
|
3
|
+
require 'rails/generators/rails/resource/resource_generator'
|
4
|
+
require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
module Generators
|
8
|
+
class ModelGenerator
|
9
|
+
hook_for :decorator, default: true
|
10
|
+
end
|
11
|
+
|
12
|
+
class ResourceGenerator
|
13
|
+
hook_for :decorator, default: true
|
14
|
+
end
|
15
|
+
|
16
|
+
class ScaffoldControllerGenerator
|
17
|
+
hook_for :decorator, default: true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Generators
|
3
|
+
class DecoratorGenerator < ::Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
def create_decorator_spec
|
7
|
+
template 'decorator_spec.rb', File.join('spec/decorators', class_path, "#{file_name}_decorator_spec.rb")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module TestUnit
|
2
|
+
module Generators
|
3
|
+
class DecoratorGenerator < ::Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
def create_decorator_test
|
7
|
+
template 'decorator_test.rb', File.join('test/decorators', class_path, "#{file_name}_decorator_test.rb")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -2,7 +2,6 @@ module Light
|
|
2
2
|
module Decorator
|
3
3
|
class Railtie < Rails::Railtie
|
4
4
|
config.after_initialize do |app|
|
5
|
-
# Eager loading of Decorators classes
|
6
5
|
app.config.paths.add 'app/decorators', eager_load: true
|
7
6
|
end
|
8
7
|
|
@@ -23,6 +22,13 @@ module Light
|
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
25
|
+
|
26
|
+
generators do |app|
|
27
|
+
Rails::Generators.configure! app.config.generators
|
28
|
+
Rails::Generators.hidden_namespaces.uniq!
|
29
|
+
|
30
|
+
require 'generators/rails/hooks'
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
data/light-decorator.gemspec
CHANGED
@@ -35,5 +35,6 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_development_dependency 'capybara', '~> 2.7.0'
|
36
36
|
spec.add_development_dependency 'factory_girl', '~> 4.0'
|
37
37
|
spec.add_development_dependency 'ffaker', '~> 2.2.0'
|
38
|
+
spec.add_development_dependency 'generator_spec', '~> 0.9.3'
|
38
39
|
spec.add_development_dependency 'codeclimate-test-reporter'
|
39
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: light-decorator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Emelianenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -178,6 +178,20 @@ dependencies:
|
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: 2.2.0
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: generator_spec
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 0.9.3
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 0.9.3
|
181
195
|
- !ruby/object:Gem::Dependency
|
182
196
|
name: codeclimate-test-reporter
|
183
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -221,6 +235,15 @@ files:
|
|
221
235
|
- gemfiles/rails_4_2.gemfile.lock
|
222
236
|
- gemfiles/rails_5_0.gemfile
|
223
237
|
- gemfiles/rails_5_0.gemfile.lock
|
238
|
+
- lib/generators/light/decorator/install/install_generator.rb
|
239
|
+
- lib/generators/light/decorator/install/templates/application_decorator.rb
|
240
|
+
- lib/generators/rails/decorator/decorator_generator.rb
|
241
|
+
- lib/generators/rails/decorator/templates/decorator.rb
|
242
|
+
- lib/generators/rails/hooks.rb
|
243
|
+
- lib/generators/rspec/decorator/decorator_generator.rb
|
244
|
+
- lib/generators/rspec/decorator/templates/decorator_spec.rb
|
245
|
+
- lib/generators/test_unit/decorator/decorator_generator.rb
|
246
|
+
- lib/generators/test_unit/decorator/templates/decorator_test.rb
|
224
247
|
- lib/light/decorator.rb
|
225
248
|
- lib/light/decorator/concerns/associations/collection_proxy.rb
|
226
249
|
- lib/light/decorator/concerns/base.rb
|