makeover 1.0.0.rc2 → 1.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/makeover.rb +10 -0
- data/lib/makeover/delegation.rb +47 -0
- data/lib/makeover/presenter.rb +4 -31
- data/lib/makeover/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmFlN2YwMWM5YzVjOGY1NWUwMTZlOGFjM2I4MDk4M2IwNjk4NzBkNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2E5NzJlNjcxOTBjODQzMGU5ZjI1ODE4MjRmNjE4ZWM4OGVlZjNiZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzA4ZDI4ZmZjNjc5NTAzMzEwMDM1ZTI0NzYzYzM3NDE4MmVkMzg3MjYxZGQ0
|
10
|
+
YmRlZDEyZDNjYjU3YWVhOWZmYjdjYzA0NjhkYmI0ZTZmYjk5NTMxZjYxOGJh
|
11
|
+
ZjI1MzRjZWM5ZDAyYWU2ODJhOTE5NDViZDRiNGViYmJjMTJhNzc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2JhYTQwMTIyZDQ2ZDI3YTYxNzY4NGVlMTIxYTdmZjljYzdhNmU3Y2EwYjdh
|
14
|
+
YTk3ZDhjOTA0NzJjZmNhMWI4OGI0NDkzNTM5OTIyMDNjY2I4ZjMyY2Q5YTUw
|
15
|
+
OWRkZjdjMzM4YWYxMjMyODRmN2JmYzM0MjhkMzUwMjFlNDI2NmY=
|
data/lib/makeover.rb
CHANGED
@@ -9,4 +9,14 @@ module Makeover
|
|
9
9
|
autoload :Presenter
|
10
10
|
autoload :CollectionPresenter
|
11
11
|
autoload :Presentable
|
12
|
+
autoload :Delegation
|
13
|
+
|
14
|
+
def self.deprecator
|
15
|
+
ActiveSupport::Deprecation.new next_major_version, name
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.next_major_version
|
19
|
+
major = VERSION.split('.').first.to_i + 1
|
20
|
+
"#{major}.0"
|
21
|
+
end
|
12
22
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Makeover
|
2
|
+
# +ActiveSupport#delegate+ behavior customization and default
|
3
|
+
# delegation to objects like +I18n+ and the derived model class, or a
|
4
|
+
# custom one.
|
5
|
+
module Delegation
|
6
|
+
# @!attribute model_class [w]
|
7
|
+
# Customize the model class that this presenter should wrap.
|
8
|
+
attr_writer :model_class
|
9
|
+
|
10
|
+
# Figure out model class of presenter so we can delegate to the
|
11
|
+
# proper model_name instance.
|
12
|
+
def model_class
|
13
|
+
@model_class ||= derived_model_class_name.constantize
|
14
|
+
end
|
15
|
+
|
16
|
+
# Wraps +ActiveSupport#delegate+ to specifically delegate methods to
|
17
|
+
# the underlying object.
|
18
|
+
#
|
19
|
+
# @param methods [Array<Symbol>] *methods
|
20
|
+
# @param to [Symbol] :to
|
21
|
+
# @param options [Hash]
|
22
|
+
# @option options [Boolean] :allow_nil
|
23
|
+
# @option options [Boolean] :allow_blank
|
24
|
+
def delegate(*methods, to: :model, **options)
|
25
|
+
if to == :model
|
26
|
+
Makeover.deprecator.deprecation_warning 'delegate without specifying :to'
|
27
|
+
end
|
28
|
+
super(*methods, to: to, **options)
|
29
|
+
end
|
30
|
+
|
31
|
+
delegate :model_name, to: :model_class
|
32
|
+
|
33
|
+
# No-op for Draper support.
|
34
|
+
#
|
35
|
+
# @return [NilClass] +nil+ and a deprecation message.
|
36
|
+
def delegate_all
|
37
|
+
# noop
|
38
|
+
end
|
39
|
+
deprecate :delegate_all, deprecator: Makeover.deprecator
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def derived_model_class_name
|
44
|
+
name.gsub(/Presenter/, '').classify
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/makeover/presenter.rb
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
module Makeover
|
3
3
|
# Base Presenter class for all decorator objects.
|
4
4
|
class Presenter < Delegator
|
5
|
+
extend Delegation
|
6
|
+
|
7
|
+
delegate :t, :translate, to: I18n
|
8
|
+
|
5
9
|
# @!attribute [r] model
|
6
10
|
# @return [Object] Object being delegated to.
|
7
11
|
attr_reader :model
|
@@ -17,37 +21,6 @@ module Makeover
|
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
|
-
# Wraps +ActiveSupport#delegate+ to specifically delegate methods to
|
21
|
-
# the underlying object.
|
22
|
-
#
|
23
|
-
# @param methods [Array<Symbol>] *methods
|
24
|
-
# @param to [Symbol] :to
|
25
|
-
# @param options [Hash]
|
26
|
-
# @option options [Boolean] :allow_nil
|
27
|
-
# @option options [Boolean] :allow_blank
|
28
|
-
def self.delegate(*methods, to: :model, **options)
|
29
|
-
super(*methods, to: to, **options)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Delegate translation methods to i18n
|
33
|
-
delegate :t, to: I18n
|
34
|
-
|
35
|
-
# Figure out model class of presenter so we can delegate to the
|
36
|
-
# proper model_name instance.
|
37
|
-
def self.model_class
|
38
|
-
name.gsub(/Presenter/, '').classify.constantize
|
39
|
-
end
|
40
|
-
|
41
|
-
class << self
|
42
|
-
# Delegate model name lookups to model class of this presenter.
|
43
|
-
delegate :model_name, to: :model_class
|
44
|
-
end
|
45
|
-
|
46
|
-
# No-op for Draper support.
|
47
|
-
def self.delegate_all
|
48
|
-
# noop
|
49
|
-
end
|
50
|
-
|
51
24
|
# Return the model object.
|
52
25
|
#
|
53
26
|
# @return [Object]
|
data/lib/makeover/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: makeover
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Scott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- lib/generators/presenter/templates/test.rb.erb
|
188
188
|
- lib/makeover.rb
|
189
189
|
- lib/makeover/collection_presenter.rb
|
190
|
+
- lib/makeover/delegation.rb
|
190
191
|
- lib/makeover/engine.rb
|
191
192
|
- lib/makeover/helpers.rb
|
192
193
|
- lib/makeover/presentable.rb
|