light-decorator 0.5.0

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.
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ sudo: false
2
+ language: ruby
3
+
4
+ rvm:
5
+ - 2.3.0
6
+
7
+ before_install: gem install bundler -v 1.12.5
8
+
9
+ gemfile:
10
+ - gemfiles/rails_4_0.gemfile
11
+ - gemfiles/rails_4_1.gemfile
12
+ - gemfiles/rails_4_2.gemfile
13
+ - gemfiles/rails_5_0.gemfile
14
+
15
+ addons:
16
+ code_climate:
17
+ repo_token: f5d73d0bacb7771f55364c3af480bf0338cef449dcea216f8f73097acdb93642
data/Appraisals ADDED
@@ -0,0 +1,16 @@
1
+ appraise 'rails-4-0' do
2
+ gem 'rails', '4.0.13'
3
+ end
4
+
5
+ appraise 'rails-4-1' do
6
+ gem 'rails', '4.1.15'
7
+ end
8
+
9
+ appraise 'rails-4-2' do
10
+ gem 'rails', '4.2.6'
11
+ end
12
+
13
+ appraise 'rails-5-0' do
14
+ gem 'rails', '5.0.0.rc1'
15
+ end
16
+
@@ -0,0 +1,50 @@
1
+
2
+ # Contributor Code of Conduct
3
+
4
+ As contributors and maintainers of this project, and in the interest of
5
+ fostering an open and welcoming community, we pledge to respect all people who
6
+ contribute through reporting issues, posting feature requests, updating
7
+ documentation, submitting pull requests or patches, and other activities.
8
+
9
+ We are committed to making participation in this project a harassment-free
10
+ experience for everyone, regardless of level of experience, gender, gender
11
+ identity and expression, sexual orientation, disability, personal appearance,
12
+ body size, race, ethnicity, age, religion, or nationality.
13
+
14
+ Examples of unacceptable behavior by participants include:
15
+
16
+ * The use of sexualized language or imagery
17
+ * Personal attacks
18
+ * Trolling or insulting/derogatory comments
19
+ * Public or private harassment
20
+ * Publishing other's private information, such as physical or electronic
21
+ addresses, without explicit permission
22
+ * Other unethical or unprofessional conduct
23
+
24
+ Project maintainers have the right and responsibility to remove, edit, or
25
+ reject comments, commits, code, wiki edits, issues, and other contributions
26
+ that are not aligned to this Code of Conduct, or to ban temporarily or
27
+ permanently any contributor for other behaviors that they deem inappropriate,
28
+ threatening, offensive, or harmful.
29
+
30
+ By adopting this Code of Conduct, project maintainers commit themselves to
31
+ fairly and consistently applying these principles to every aspect of managing
32
+ this project. Project maintainers who do not follow or enforce the Code of
33
+ Conduct may be permanently removed from the project team.
34
+
35
+ This code of conduct applies both within project spaces and in public spaces
36
+ when an individual is representing the project or its community.
37
+
38
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
39
+ reported by contacting a project maintainer at emelianenko.web@gmail.com. All
40
+ complaints will be reviewed and investigated and will result in a response that
41
+ is deemed necessary and appropriate to the circumstances. Maintainers are
42
+ obligated to maintain confidentiality with regard to the reporter of an
43
+ incident.
44
+
45
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
46
+ version 1.3.0, available at
47
+ [http://contributor-covenant.org/version/1/3/0/][version]
48
+
49
+ [homepage]: http://contributor-covenant.org
50
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in light-decorator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Andrew Emelianenko
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.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # Light::Decorator
2
+
3
+ [![Build Status](https://travis-ci.org/light-ruby/light-decorator.svg?branch=master)](https://travis-ci.org/light-ruby/light-decorator)
4
+ [![Code Climate](https://codeclimate.com/github/light-ruby/light-decorator/badges/gpa.svg)](https://codeclimate.com/github/light-ruby/light-decorator)
5
+ [![Test Coverage](https://codeclimate.com/github/light-ruby/light-decorator/badges/coverage.svg)](https://codeclimate.com/github/light-ruby/light-decorator/coverage)
6
+
7
+ Easiest and fast way to decorate Ruby on Rails models.
8
+
9
+ Decorator pattern - What is it?
10
+ - [Wikipedia](https://en.wikipedia.org/wiki/Decorator_pattern)
11
+ - [Thoughtbot](https://robots.thoughtbot.com/evaluating-alternative-decorator-implementations-in)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'light-decorator', '~> 0.5.0'
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Create the `ApplicationDecorator`
24
+
25
+ ```ruby
26
+ # app/decorators/application_decorator.rb
27
+ class ApplicationDecorator < Light::Decorator::Decorate
28
+ end
29
+ ```
30
+
31
+ Create decorator for your model. For example we will use the `User` model.
32
+
33
+ ```ruby
34
+ # app/decorators/user_decorator.rb
35
+ class UserDecorator < Application
36
+ def full_name
37
+ "#{object.first_name} #{object.last_name}"
38
+ end
39
+ end
40
+ ```
41
+
42
+ Decorate your model in controller or anywhere.
43
+
44
+ ```ruby
45
+ # Single record
46
+ User.find(params[:id]).decorate
47
+ User.find_and_decorate(params[:id])
48
+ User.decorate.find(params[:id])
49
+
50
+ # Collection
51
+ User.all.decorate
52
+ User.decorate
53
+ User.limit(10).decorate
54
+ User.decorate.limit(10)
55
+
56
+ # Options
57
+ User.find_and_decorate(params[:id], with: AnotherUserDecorator)
58
+
59
+ # Associations will be decorated automatically
60
+ user = User.find_and_decorate(params[:id])
61
+ user.decorated? # true
62
+ user.comments.decorated? # true
63
+ user.comments.first.decorated? # true
64
+ ```
65
+
66
+ Example of Decorator
67
+ ```ruby
68
+ class UserDecorator < ApplicationDecorator
69
+ def full_name
70
+ "#{object.first_name} #{object.last_name}"
71
+ # or
72
+ "#{o.first_name} #{o.last_name}"
73
+ end
74
+
75
+ def full_name_link
76
+ helpers.link_to full_name, user_path(object)
77
+ # or
78
+ h.link_to full_name, user_path(object)
79
+ end
80
+ end
81
+ ```
82
+
83
+ ## Next steps
84
+
85
+ - [ ] Create rake task `light-decorator:install`
86
+ - [ ] Create generators
87
+ - [ ] Create configuration file
88
+
89
+ ## Contributing
90
+
91
+ Bug reports and pull requests are welcome on GitHub at https://github.com/light-ruby/light-decorator. 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.
92
+
93
+ ## License
94
+
95
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
96
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'light/decorator'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -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
data/config.ru ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
5
+
6
+ Combustion.initialize! :all
7
+ run Combustion::Application
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "4.0.13"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,145 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ light-decorator (0.5.0)
5
+ rails (>= 4.0.0)
6
+ request_store (>= 1.0.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionmailer (4.0.13)
12
+ actionpack (= 4.0.13)
13
+ mail (~> 2.5, >= 2.5.4)
14
+ actionpack (4.0.13)
15
+ activesupport (= 4.0.13)
16
+ builder (~> 3.1.0)
17
+ erubis (~> 2.7.0)
18
+ rack (~> 1.5.2)
19
+ rack-test (~> 0.6.2)
20
+ activemodel (4.0.13)
21
+ activesupport (= 4.0.13)
22
+ builder (~> 3.1.0)
23
+ activerecord (4.0.13)
24
+ activemodel (= 4.0.13)
25
+ activerecord-deprecated_finders (~> 1.0.2)
26
+ activesupport (= 4.0.13)
27
+ arel (~> 4.0.0)
28
+ activerecord-deprecated_finders (1.0.4)
29
+ activesupport (4.0.13)
30
+ i18n (~> 0.6, >= 0.6.9)
31
+ minitest (~> 4.2)
32
+ multi_json (~> 1.3)
33
+ thread_safe (~> 0.1)
34
+ tzinfo (~> 0.3.37)
35
+ addressable (2.4.0)
36
+ appraisal (2.1.0)
37
+ bundler
38
+ rake
39
+ thor (>= 0.14.0)
40
+ arel (4.0.2)
41
+ builder (3.1.4)
42
+ capybara (2.7.1)
43
+ addressable
44
+ mime-types (>= 1.16)
45
+ nokogiri (>= 1.3.3)
46
+ rack (>= 1.0.0)
47
+ rack-test (>= 0.5.4)
48
+ xpath (~> 2.0)
49
+ codeclimate-test-reporter (0.5.1)
50
+ simplecov (>= 0.7.1, < 1.0.0)
51
+ combustion (0.5.4)
52
+ activesupport (>= 3.0.0)
53
+ railties (>= 3.0.0)
54
+ thor (>= 0.14.6)
55
+ concurrent-ruby (1.0.2)
56
+ diff-lcs (1.2.5)
57
+ docile (1.1.5)
58
+ erubis (2.7.0)
59
+ factory_girl (4.7.0)
60
+ activesupport (>= 3.0.0)
61
+ ffaker (2.2.0)
62
+ i18n (0.7.0)
63
+ json (1.8.3)
64
+ mail (2.6.4)
65
+ mime-types (>= 1.16, < 4)
66
+ mime-types (3.1)
67
+ mime-types-data (~> 3.2015)
68
+ mime-types-data (3.2016.0521)
69
+ mini_portile2 (2.1.0)
70
+ minitest (4.7.5)
71
+ multi_json (1.12.1)
72
+ nokogiri (1.6.8)
73
+ mini_portile2 (~> 2.1.0)
74
+ pkg-config (~> 1.1.7)
75
+ pkg-config (1.1.7)
76
+ rack (1.5.5)
77
+ rack-test (0.6.3)
78
+ rack (>= 1.0)
79
+ rails (4.0.13)
80
+ actionmailer (= 4.0.13)
81
+ actionpack (= 4.0.13)
82
+ activerecord (= 4.0.13)
83
+ activesupport (= 4.0.13)
84
+ bundler (>= 1.3.0, < 2.0)
85
+ railties (= 4.0.13)
86
+ sprockets-rails (~> 2.0)
87
+ railties (4.0.13)
88
+ actionpack (= 4.0.13)
89
+ activesupport (= 4.0.13)
90
+ rake (>= 0.8.7)
91
+ thor (>= 0.18.1, < 2.0)
92
+ rake (10.5.0)
93
+ request_store (1.3.1)
94
+ rspec (3.4.0)
95
+ rspec-core (~> 3.4.0)
96
+ rspec-expectations (~> 3.4.0)
97
+ rspec-mocks (~> 3.4.0)
98
+ rspec-core (3.4.4)
99
+ rspec-support (~> 3.4.0)
100
+ rspec-expectations (3.4.0)
101
+ diff-lcs (>= 1.2.0, < 2.0)
102
+ rspec-support (~> 3.4.0)
103
+ rspec-mocks (3.4.1)
104
+ diff-lcs (>= 1.2.0, < 2.0)
105
+ rspec-support (~> 3.4.0)
106
+ rspec-support (3.4.1)
107
+ simplecov (0.11.2)
108
+ docile (~> 1.1.0)
109
+ json (~> 1.8)
110
+ simplecov-html (~> 0.10.0)
111
+ simplecov-html (0.10.0)
112
+ sprockets (3.6.0)
113
+ concurrent-ruby (~> 1.0)
114
+ rack (> 1, < 3)
115
+ sprockets-rails (2.3.3)
116
+ actionpack (>= 3.0)
117
+ activesupport (>= 3.0)
118
+ sprockets (>= 2.8, < 4.0)
119
+ sqlite3 (1.3.11)
120
+ thor (0.19.1)
121
+ thread_safe (0.3.5)
122
+ tzinfo (0.3.49)
123
+ xpath (2.0.0)
124
+ nokogiri (~> 1.3)
125
+
126
+ PLATFORMS
127
+ ruby
128
+
129
+ DEPENDENCIES
130
+ appraisal (~> 2.1)
131
+ bundler (~> 1.12)
132
+ capybara (~> 2.7.0)
133
+ codeclimate-test-reporter
134
+ combustion (~> 0.5.4)
135
+ factory_girl (~> 4.0)
136
+ ffaker (~> 2.2.0)
137
+ light-decorator!
138
+ rails (= 4.0.13)
139
+ rake (~> 10.0)
140
+ rspec (~> 3.0)
141
+ simplecov (~> 0.11.2)
142
+ sqlite3 (~> 1.3.11)
143
+
144
+ BUNDLED WITH
145
+ 1.12.5
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "4.1.15"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,149 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ light-decorator (0.5.0)
5
+ rails (>= 4.0.0)
6
+ request_store (>= 1.0.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionmailer (4.1.15)
12
+ actionpack (= 4.1.15)
13
+ actionview (= 4.1.15)
14
+ mail (~> 2.5, >= 2.5.4)
15
+ actionpack (4.1.15)
16
+ actionview (= 4.1.15)
17
+ activesupport (= 4.1.15)
18
+ rack (~> 1.5.2)
19
+ rack-test (~> 0.6.2)
20
+ actionview (4.1.15)
21
+ activesupport (= 4.1.15)
22
+ builder (~> 3.1)
23
+ erubis (~> 2.7.0)
24
+ activemodel (4.1.15)
25
+ activesupport (= 4.1.15)
26
+ builder (~> 3.1)
27
+ activerecord (4.1.15)
28
+ activemodel (= 4.1.15)
29
+ activesupport (= 4.1.15)
30
+ arel (~> 5.0.0)
31
+ activesupport (4.1.15)
32
+ i18n (~> 0.6, >= 0.6.9)
33
+ json (~> 1.7, >= 1.7.7)
34
+ minitest (~> 5.1)
35
+ thread_safe (~> 0.1)
36
+ tzinfo (~> 1.1)
37
+ addressable (2.4.0)
38
+ appraisal (2.1.0)
39
+ bundler
40
+ rake
41
+ thor (>= 0.14.0)
42
+ arel (5.0.1.20140414130214)
43
+ builder (3.2.2)
44
+ capybara (2.7.1)
45
+ addressable
46
+ mime-types (>= 1.16)
47
+ nokogiri (>= 1.3.3)
48
+ rack (>= 1.0.0)
49
+ rack-test (>= 0.5.4)
50
+ xpath (~> 2.0)
51
+ codeclimate-test-reporter (0.5.1)
52
+ simplecov (>= 0.7.1, < 1.0.0)
53
+ combustion (0.5.4)
54
+ activesupport (>= 3.0.0)
55
+ railties (>= 3.0.0)
56
+ thor (>= 0.14.6)
57
+ concurrent-ruby (1.0.2)
58
+ diff-lcs (1.2.5)
59
+ docile (1.1.5)
60
+ erubis (2.7.0)
61
+ factory_girl (4.7.0)
62
+ activesupport (>= 3.0.0)
63
+ ffaker (2.2.0)
64
+ i18n (0.7.0)
65
+ json (1.8.3)
66
+ mail (2.6.4)
67
+ mime-types (>= 1.16, < 4)
68
+ mime-types (3.1)
69
+ mime-types-data (~> 3.2015)
70
+ mime-types-data (3.2016.0521)
71
+ mini_portile2 (2.1.0)
72
+ minitest (5.9.0)
73
+ nokogiri (1.6.8)
74
+ mini_portile2 (~> 2.1.0)
75
+ pkg-config (~> 1.1.7)
76
+ pkg-config (1.1.7)
77
+ rack (1.5.5)
78
+ rack-test (0.6.3)
79
+ rack (>= 1.0)
80
+ rails (4.1.15)
81
+ actionmailer (= 4.1.15)
82
+ actionpack (= 4.1.15)
83
+ actionview (= 4.1.15)
84
+ activemodel (= 4.1.15)
85
+ activerecord (= 4.1.15)
86
+ activesupport (= 4.1.15)
87
+ bundler (>= 1.3.0, < 2.0)
88
+ railties (= 4.1.15)
89
+ sprockets-rails (~> 2.0)
90
+ railties (4.1.15)
91
+ actionpack (= 4.1.15)
92
+ activesupport (= 4.1.15)
93
+ rake (>= 0.8.7)
94
+ thor (>= 0.18.1, < 2.0)
95
+ rake (10.5.0)
96
+ request_store (1.3.1)
97
+ rspec (3.4.0)
98
+ rspec-core (~> 3.4.0)
99
+ rspec-expectations (~> 3.4.0)
100
+ rspec-mocks (~> 3.4.0)
101
+ rspec-core (3.4.4)
102
+ rspec-support (~> 3.4.0)
103
+ rspec-expectations (3.4.0)
104
+ diff-lcs (>= 1.2.0, < 2.0)
105
+ rspec-support (~> 3.4.0)
106
+ rspec-mocks (3.4.1)
107
+ diff-lcs (>= 1.2.0, < 2.0)
108
+ rspec-support (~> 3.4.0)
109
+ rspec-support (3.4.1)
110
+ simplecov (0.11.2)
111
+ docile (~> 1.1.0)
112
+ json (~> 1.8)
113
+ simplecov-html (~> 0.10.0)
114
+ simplecov-html (0.10.0)
115
+ sprockets (3.6.0)
116
+ concurrent-ruby (~> 1.0)
117
+ rack (> 1, < 3)
118
+ sprockets-rails (2.3.3)
119
+ actionpack (>= 3.0)
120
+ activesupport (>= 3.0)
121
+ sprockets (>= 2.8, < 4.0)
122
+ sqlite3 (1.3.11)
123
+ thor (0.19.1)
124
+ thread_safe (0.3.5)
125
+ tzinfo (1.2.2)
126
+ thread_safe (~> 0.1)
127
+ xpath (2.0.0)
128
+ nokogiri (~> 1.3)
129
+
130
+ PLATFORMS
131
+ ruby
132
+
133
+ DEPENDENCIES
134
+ appraisal (~> 2.1)
135
+ bundler (~> 1.12)
136
+ capybara (~> 2.7.0)
137
+ codeclimate-test-reporter
138
+ combustion (~> 0.5.4)
139
+ factory_girl (~> 4.0)
140
+ ffaker (~> 2.2.0)
141
+ light-decorator!
142
+ rails (= 4.1.15)
143
+ rake (~> 10.0)
144
+ rspec (~> 3.0)
145
+ simplecov (~> 0.11.2)
146
+ sqlite3 (~> 1.3.11)
147
+
148
+ BUNDLED WITH
149
+ 1.12.5