light-decorator 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "4.2.6"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,171 @@
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.2.6)
12
+ actionpack (= 4.2.6)
13
+ actionview (= 4.2.6)
14
+ activejob (= 4.2.6)
15
+ mail (~> 2.5, >= 2.5.4)
16
+ rails-dom-testing (~> 1.0, >= 1.0.5)
17
+ actionpack (4.2.6)
18
+ actionview (= 4.2.6)
19
+ activesupport (= 4.2.6)
20
+ rack (~> 1.6)
21
+ rack-test (~> 0.6.2)
22
+ rails-dom-testing (~> 1.0, >= 1.0.5)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
+ actionview (4.2.6)
25
+ activesupport (= 4.2.6)
26
+ builder (~> 3.1)
27
+ erubis (~> 2.7.0)
28
+ rails-dom-testing (~> 1.0, >= 1.0.5)
29
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
30
+ activejob (4.2.6)
31
+ activesupport (= 4.2.6)
32
+ globalid (>= 0.3.0)
33
+ activemodel (4.2.6)
34
+ activesupport (= 4.2.6)
35
+ builder (~> 3.1)
36
+ activerecord (4.2.6)
37
+ activemodel (= 4.2.6)
38
+ activesupport (= 4.2.6)
39
+ arel (~> 6.0)
40
+ activesupport (4.2.6)
41
+ i18n (~> 0.7)
42
+ json (~> 1.7, >= 1.7.7)
43
+ minitest (~> 5.1)
44
+ thread_safe (~> 0.3, >= 0.3.4)
45
+ tzinfo (~> 1.1)
46
+ addressable (2.4.0)
47
+ appraisal (2.1.0)
48
+ bundler
49
+ rake
50
+ thor (>= 0.14.0)
51
+ arel (6.0.3)
52
+ builder (3.2.2)
53
+ capybara (2.7.1)
54
+ addressable
55
+ mime-types (>= 1.16)
56
+ nokogiri (>= 1.3.3)
57
+ rack (>= 1.0.0)
58
+ rack-test (>= 0.5.4)
59
+ xpath (~> 2.0)
60
+ codeclimate-test-reporter (0.5.1)
61
+ simplecov (>= 0.7.1, < 1.0.0)
62
+ combustion (0.5.4)
63
+ activesupport (>= 3.0.0)
64
+ railties (>= 3.0.0)
65
+ thor (>= 0.14.6)
66
+ concurrent-ruby (1.0.2)
67
+ diff-lcs (1.2.5)
68
+ docile (1.1.5)
69
+ erubis (2.7.0)
70
+ factory_girl (4.7.0)
71
+ activesupport (>= 3.0.0)
72
+ ffaker (2.2.0)
73
+ globalid (0.3.6)
74
+ activesupport (>= 4.1.0)
75
+ i18n (0.7.0)
76
+ json (1.8.3)
77
+ loofah (2.0.3)
78
+ nokogiri (>= 1.5.9)
79
+ mail (2.6.4)
80
+ mime-types (>= 1.16, < 4)
81
+ mime-types (3.1)
82
+ mime-types-data (~> 3.2015)
83
+ mime-types-data (3.2016.0521)
84
+ mini_portile2 (2.1.0)
85
+ minitest (5.9.0)
86
+ nokogiri (1.6.8)
87
+ mini_portile2 (~> 2.1.0)
88
+ pkg-config (~> 1.1.7)
89
+ pkg-config (1.1.7)
90
+ rack (1.6.4)
91
+ rack-test (0.6.3)
92
+ rack (>= 1.0)
93
+ rails (4.2.6)
94
+ actionmailer (= 4.2.6)
95
+ actionpack (= 4.2.6)
96
+ actionview (= 4.2.6)
97
+ activejob (= 4.2.6)
98
+ activemodel (= 4.2.6)
99
+ activerecord (= 4.2.6)
100
+ activesupport (= 4.2.6)
101
+ bundler (>= 1.3.0, < 2.0)
102
+ railties (= 4.2.6)
103
+ sprockets-rails
104
+ rails-deprecated_sanitizer (1.0.3)
105
+ activesupport (>= 4.2.0.alpha)
106
+ rails-dom-testing (1.0.7)
107
+ activesupport (>= 4.2.0.beta, < 5.0)
108
+ nokogiri (~> 1.6.0)
109
+ rails-deprecated_sanitizer (>= 1.0.1)
110
+ rails-html-sanitizer (1.0.3)
111
+ loofah (~> 2.0)
112
+ railties (4.2.6)
113
+ actionpack (= 4.2.6)
114
+ activesupport (= 4.2.6)
115
+ rake (>= 0.8.7)
116
+ thor (>= 0.18.1, < 2.0)
117
+ rake (10.5.0)
118
+ request_store (1.3.1)
119
+ rspec (3.4.0)
120
+ rspec-core (~> 3.4.0)
121
+ rspec-expectations (~> 3.4.0)
122
+ rspec-mocks (~> 3.4.0)
123
+ rspec-core (3.4.4)
124
+ rspec-support (~> 3.4.0)
125
+ rspec-expectations (3.4.0)
126
+ diff-lcs (>= 1.2.0, < 2.0)
127
+ rspec-support (~> 3.4.0)
128
+ rspec-mocks (3.4.1)
129
+ diff-lcs (>= 1.2.0, < 2.0)
130
+ rspec-support (~> 3.4.0)
131
+ rspec-support (3.4.1)
132
+ simplecov (0.11.2)
133
+ docile (~> 1.1.0)
134
+ json (~> 1.8)
135
+ simplecov-html (~> 0.10.0)
136
+ simplecov-html (0.10.0)
137
+ sprockets (3.6.0)
138
+ concurrent-ruby (~> 1.0)
139
+ rack (> 1, < 3)
140
+ sprockets-rails (3.0.4)
141
+ actionpack (>= 4.0)
142
+ activesupport (>= 4.0)
143
+ sprockets (>= 3.0.0)
144
+ sqlite3 (1.3.11)
145
+ thor (0.19.1)
146
+ thread_safe (0.3.5)
147
+ tzinfo (1.2.2)
148
+ thread_safe (~> 0.1)
149
+ xpath (2.0.0)
150
+ nokogiri (~> 1.3)
151
+
152
+ PLATFORMS
153
+ ruby
154
+
155
+ DEPENDENCIES
156
+ appraisal (~> 2.1)
157
+ bundler (~> 1.12)
158
+ capybara (~> 2.7.0)
159
+ codeclimate-test-reporter
160
+ combustion (~> 0.5.4)
161
+ factory_girl (~> 4.0)
162
+ ffaker (~> 2.2.0)
163
+ light-decorator!
164
+ rails (= 4.2.6)
165
+ rake (~> 10.0)
166
+ rspec (~> 3.0)
167
+ simplecov (~> 0.11.2)
168
+ sqlite3 (~> 1.3.11)
169
+
170
+ BUNDLED WITH
171
+ 1.12.5
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "5.0.0.rc1"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,181 @@
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
+ actioncable (5.0.0.rc1)
12
+ actionpack (= 5.0.0.rc1)
13
+ nio4r (~> 1.2)
14
+ websocket-driver (~> 0.6.1)
15
+ actionmailer (5.0.0.rc1)
16
+ actionpack (= 5.0.0.rc1)
17
+ actionview (= 5.0.0.rc1)
18
+ activejob (= 5.0.0.rc1)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 1.0, >= 1.0.5)
21
+ actionpack (5.0.0.rc1)
22
+ actionview (= 5.0.0.rc1)
23
+ activesupport (= 5.0.0.rc1)
24
+ rack (~> 2.x)
25
+ rack-test (~> 0.6.3)
26
+ rails-dom-testing (~> 1.0, >= 1.0.5)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (5.0.0.rc1)
29
+ activesupport (= 5.0.0.rc1)
30
+ builder (~> 3.1)
31
+ erubis (~> 2.7.0)
32
+ rails-dom-testing (~> 1.0, >= 1.0.5)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
34
+ activejob (5.0.0.rc1)
35
+ activesupport (= 5.0.0.rc1)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.0.0.rc1)
38
+ activesupport (= 5.0.0.rc1)
39
+ activerecord (5.0.0.rc1)
40
+ activemodel (= 5.0.0.rc1)
41
+ activesupport (= 5.0.0.rc1)
42
+ arel (~> 7.0)
43
+ activesupport (5.0.0.rc1)
44
+ concurrent-ruby (~> 1.0, >= 1.0.2)
45
+ i18n (~> 0.7)
46
+ minitest (~> 5.1)
47
+ tzinfo (~> 1.1)
48
+ addressable (2.4.0)
49
+ appraisal (2.1.0)
50
+ bundler
51
+ rake
52
+ thor (>= 0.14.0)
53
+ arel (7.0.0)
54
+ builder (3.2.2)
55
+ capybara (2.7.1)
56
+ addressable
57
+ mime-types (>= 1.16)
58
+ nokogiri (>= 1.3.3)
59
+ rack (>= 1.0.0)
60
+ rack-test (>= 0.5.4)
61
+ xpath (~> 2.0)
62
+ codeclimate-test-reporter (0.5.1)
63
+ simplecov (>= 0.7.1, < 1.0.0)
64
+ combustion (0.5.4)
65
+ activesupport (>= 3.0.0)
66
+ railties (>= 3.0.0)
67
+ thor (>= 0.14.6)
68
+ concurrent-ruby (1.0.2)
69
+ diff-lcs (1.2.5)
70
+ docile (1.1.5)
71
+ erubis (2.7.0)
72
+ factory_girl (4.7.0)
73
+ activesupport (>= 3.0.0)
74
+ ffaker (2.2.0)
75
+ globalid (0.3.6)
76
+ activesupport (>= 4.1.0)
77
+ i18n (0.7.0)
78
+ json (1.8.3)
79
+ loofah (2.0.3)
80
+ nokogiri (>= 1.5.9)
81
+ mail (2.6.4)
82
+ mime-types (>= 1.16, < 4)
83
+ method_source (0.8.2)
84
+ mime-types (3.1)
85
+ mime-types-data (~> 3.2015)
86
+ mime-types-data (3.2016.0521)
87
+ mini_portile2 (2.1.0)
88
+ minitest (5.9.0)
89
+ nio4r (1.2.1)
90
+ nokogiri (1.6.8)
91
+ mini_portile2 (~> 2.1.0)
92
+ pkg-config (~> 1.1.7)
93
+ pkg-config (1.1.7)
94
+ rack (2.0.0.rc1)
95
+ json
96
+ rack-test (0.6.3)
97
+ rack (>= 1.0)
98
+ rails (5.0.0.rc1)
99
+ actioncable (= 5.0.0.rc1)
100
+ actionmailer (= 5.0.0.rc1)
101
+ actionpack (= 5.0.0.rc1)
102
+ actionview (= 5.0.0.rc1)
103
+ activejob (= 5.0.0.rc1)
104
+ activemodel (= 5.0.0.rc1)
105
+ activerecord (= 5.0.0.rc1)
106
+ activesupport (= 5.0.0.rc1)
107
+ bundler (>= 1.3.0, < 2.0)
108
+ railties (= 5.0.0.rc1)
109
+ sprockets-rails (>= 2.0.0)
110
+ rails-deprecated_sanitizer (1.0.3)
111
+ activesupport (>= 4.2.0.alpha)
112
+ rails-dom-testing (1.0.7)
113
+ activesupport (>= 4.2.0.beta, < 5.0)
114
+ nokogiri (~> 1.6.0)
115
+ rails-deprecated_sanitizer (>= 1.0.1)
116
+ rails-html-sanitizer (1.0.3)
117
+ loofah (~> 2.0)
118
+ railties (5.0.0.rc1)
119
+ actionpack (= 5.0.0.rc1)
120
+ activesupport (= 5.0.0.rc1)
121
+ method_source
122
+ rake (>= 0.8.7)
123
+ thor (>= 0.18.1, < 2.0)
124
+ rake (10.5.0)
125
+ request_store (1.3.1)
126
+ rspec (3.4.0)
127
+ rspec-core (~> 3.4.0)
128
+ rspec-expectations (~> 3.4.0)
129
+ rspec-mocks (~> 3.4.0)
130
+ rspec-core (3.4.4)
131
+ rspec-support (~> 3.4.0)
132
+ rspec-expectations (3.4.0)
133
+ diff-lcs (>= 1.2.0, < 2.0)
134
+ rspec-support (~> 3.4.0)
135
+ rspec-mocks (3.4.1)
136
+ diff-lcs (>= 1.2.0, < 2.0)
137
+ rspec-support (~> 3.4.0)
138
+ rspec-support (3.4.1)
139
+ simplecov (0.11.2)
140
+ docile (~> 1.1.0)
141
+ json (~> 1.8)
142
+ simplecov-html (~> 0.10.0)
143
+ simplecov-html (0.10.0)
144
+ sprockets (3.6.0)
145
+ concurrent-ruby (~> 1.0)
146
+ rack (> 1, < 3)
147
+ sprockets-rails (3.0.4)
148
+ actionpack (>= 4.0)
149
+ activesupport (>= 4.0)
150
+ sprockets (>= 3.0.0)
151
+ sqlite3 (1.3.11)
152
+ thor (0.19.1)
153
+ thread_safe (0.3.5)
154
+ tzinfo (1.2.2)
155
+ thread_safe (~> 0.1)
156
+ websocket-driver (0.6.4)
157
+ websocket-extensions (>= 0.1.0)
158
+ websocket-extensions (0.1.2)
159
+ xpath (2.0.0)
160
+ nokogiri (~> 1.3)
161
+
162
+ PLATFORMS
163
+ ruby
164
+
165
+ DEPENDENCIES
166
+ appraisal (~> 2.1)
167
+ bundler (~> 1.12)
168
+ capybara (~> 2.7.0)
169
+ codeclimate-test-reporter
170
+ combustion (~> 0.5.4)
171
+ factory_girl (~> 4.0)
172
+ ffaker (~> 2.2.0)
173
+ light-decorator!
174
+ rails (= 5.0.0.rc1)
175
+ rake (~> 10.0)
176
+ rspec (~> 3.0)
177
+ simplecov (~> 0.11.2)
178
+ sqlite3 (~> 1.3.11)
179
+
180
+ BUNDLED WITH
181
+ 1.12.5
@@ -0,0 +1,20 @@
1
+ require 'rails'
2
+ require 'active_record'
3
+ require 'request_store'
4
+
5
+ require 'light/decorator/version'
6
+ require 'light/decorator/exceptions'
7
+ require 'light/decorator/concerns/base'
8
+ require 'light/decorator/concerns/relation'
9
+ require 'light/decorator/concerns/associations/collection_proxy'
10
+ require 'light/decorator/railtie'
11
+ require 'light/decorator/view_context'
12
+ require 'light/decorator/decorate'
13
+
14
+ module Light
15
+ module Decorator
16
+ NOT_DELEGATABLE_METHODS = (
17
+ Kernel.methods + ActiveRecord::Base.methods + [:decorated?, :==, :===, :eql?, :equal?]
18
+ ).freeze
19
+ end
20
+ end
@@ -0,0 +1,45 @@
1
+ module Light
2
+ module Decorator
3
+ module Concerns
4
+ module Associations
5
+ module CollectionProxy
6
+ extend ActiveSupport::Concern
7
+
8
+ # Decorate ActiveRecord::Model associations
9
+ #
10
+ # @param [Hash] options (optional)
11
+ # @return [ActiveRecord::Associations::CollectionProxy]
12
+ def decorate(options = {})
13
+ @decorated = true
14
+
15
+ override_scope(options)
16
+ override_load_target(options)
17
+
18
+ self
19
+ end
20
+
21
+ # Check current association is decorated or not
22
+ #
23
+ # @return [Bool]
24
+ def decorated?
25
+ !@decorated.nil?
26
+ end
27
+
28
+ private
29
+
30
+ def override_scope(options)
31
+ @association.define_singleton_method :scope do |opts = {}|
32
+ super(opts).decorate(options)
33
+ end
34
+ end
35
+
36
+ def override_load_target(options)
37
+ @association.define_singleton_method :load_target do
38
+ super().map { |target| target.decorate(options) }
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,69 @@
1
+ module Light
2
+ module Decorator
3
+ module Concerns
4
+ module Base
5
+ extend ActiveSupport::Concern
6
+
7
+ # Decorate ActiveRecord::Model
8
+ #
9
+ # @param [Hash] options (optional)
10
+ # @return [Object] decorator or self
11
+ def decorate(options = {})
12
+ return self if decorated?
13
+
14
+ klass = decorator_class(options)
15
+ klass.decorate(self, options)
16
+ rescue Light::Decorator::NotFound => e
17
+ raise e unless options[:soft]
18
+ self
19
+ end
20
+
21
+ # Check current ActiveRecord::Model is decorated or not
22
+ #
23
+ # @return [Bool]
24
+ def decorated?
25
+ false
26
+ end
27
+
28
+ def ==(other)
29
+ super || other.respond_to?(:object) && self == other.object
30
+ end
31
+
32
+ def eql?(other)
33
+ super || other.respond_to?(:object) && eql?(other.object)
34
+ end
35
+
36
+ private
37
+
38
+ def decorator_class(options)
39
+ with = options.delete(:with)
40
+ return "#{self.class}Decorator".constantize unless with
41
+
42
+ with = with.constantize unless with.is_a?(Class)
43
+ with
44
+ rescue NameError
45
+ raise Light::Decorator::NotFound, "Decorator#{with ? " #{with}" : ''} for #{self.class} not found"
46
+ end
47
+
48
+ module ClassMethods
49
+ # Decorate all scope for ActiveRecord::Model
50
+ #
51
+ # @param [Hash] options (optional)
52
+ # @return [ActiveRecord::Relation]
53
+ def decorate(options = {})
54
+ all.decorate(options)
55
+ end
56
+
57
+ # Find ActiveRecord::Model and decorate it
58
+ #
59
+ # @param [Integer] id
60
+ # @param [Hash] options (optional)
61
+ # @return [ActiveRecord::Model]
62
+ def find_and_decorate(id, options = {})
63
+ find(id).decorate(options)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end