AR2H 0.0.2 → 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/.gitlab-ci.yml +6 -0
- data/AR2H.gemspec +1 -1
- data/lib/AR2H.rb +3 -0
- data/lib/AR2H/concerns/active_record/base.rb +0 -2
- data/lib/AR2H/concerns/active_record/relation.rb +0 -2
- data/lib/AR2H/executor.rb +9 -6
- data/lib/AR2H/logger.rb +1 -1
- data/lib/AR2H/presenters/collection.rb +3 -3
- data/lib/AR2H/presenters/presenter.rb +5 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 426579708bc9b59286a012e4eccbf37f1ff5394d
|
4
|
+
data.tar.gz: 2f0e3f57e653759f0b3c6fc4252ccb5ddf4fcaf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21f6d659534bcedaff0f1c46cdf8b6cc772c99d890f1a1dd4cc9a4c4519a2c559f5008d18df45a56281f3147c2f404371189d8091a373dcc3c12051ec221b29b
|
7
|
+
data.tar.gz: 2f000e3341a5084c14eefdf64ae70f5a35f8363f561a06becfba96b209b746c29583fa4880d573014ecf176d06724b5eca69b475d7e3381f72f3796a0a28de36
|
data/.gitlab-ci.yml
ADDED
data/AR2H.gemspec
CHANGED
data/lib/AR2H.rb
CHANGED
data/lib/AR2H/executor.rb
CHANGED
@@ -10,11 +10,10 @@ module AR2H
|
|
10
10
|
|
11
11
|
case multiple
|
12
12
|
when false
|
13
|
-
new(object, presenter).
|
13
|
+
new(object, presenter).run
|
14
14
|
when true
|
15
|
-
object.map { |el| new(el, presenter).
|
16
|
-
else
|
17
|
-
raise ArgumentError.new('Bad multiple argument')
|
15
|
+
object.map { |el| new(el, presenter).run }
|
16
|
+
else raise ArgumentError.new("Bad multiple argument, expected Boolean but got #{multiple.class}")
|
18
17
|
end
|
19
18
|
end
|
20
19
|
end
|
@@ -27,7 +26,7 @@ module AR2H
|
|
27
26
|
|
28
27
|
attr_reader :object
|
29
28
|
|
30
|
-
def
|
29
|
+
def run
|
31
30
|
instance_eval(&@presenter.block)
|
32
31
|
@result
|
33
32
|
end
|
@@ -50,10 +49,14 @@ module AR2H
|
|
50
49
|
_has_branch(model, presenter, true)
|
51
50
|
end
|
52
51
|
|
52
|
+
def belongs_to(model, presenter: nil)
|
53
|
+
_has_branch(model, presenter, false)
|
54
|
+
end
|
55
|
+
|
53
56
|
def _has_branch(model, presenter, multiple) # :nodoc:
|
54
57
|
child_presenter = presenter || @presenter.name
|
55
58
|
child_object = object.send(model)
|
56
|
-
@result[model] = Executor.run(child_object, child_presenter, multiple)
|
59
|
+
@result[model] = child_object ? Executor.run(child_object, child_presenter, multiple) : nil
|
57
60
|
end
|
58
61
|
end
|
59
62
|
end
|
data/lib/AR2H/logger.rb
CHANGED
@@ -4,4 +4,4 @@ ActiveSupport::Notifications.subscribe('ar2h.presenting') do |_, started, finish
|
|
4
4
|
presenter = payload[:presenter]
|
5
5
|
message = " Presented #{model} as #{presenter} in #{time}ms"
|
6
6
|
ActionController::Base.logger.info message
|
7
|
-
end if defined?
|
7
|
+
end if defined? ActionController::Base
|
@@ -7,7 +7,7 @@ module AR2H
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def add(presenter)
|
10
|
-
if self.include? presenter
|
10
|
+
if self.include? presenter
|
11
11
|
raise Exception.new("#{@model}: presenter #{presenter.name} is already exists")
|
12
12
|
else
|
13
13
|
@presenters << presenter
|
@@ -22,8 +22,8 @@ module AR2H
|
|
22
22
|
@presenters.map { |presenter| presenter.name }
|
23
23
|
end
|
24
24
|
|
25
|
-
def include?(
|
26
|
-
list.include? name
|
25
|
+
def include?(presenter)
|
26
|
+
list.include? presenter.name
|
27
27
|
end
|
28
28
|
|
29
29
|
def find(name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: AR2H
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Yak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,7 @@ extensions: []
|
|
122
122
|
extra_rdoc_files: []
|
123
123
|
files:
|
124
124
|
- ".gitignore"
|
125
|
+
- ".gitlab-ci.yml"
|
125
126
|
- AR2H.gemspec
|
126
127
|
- Gemfile
|
127
128
|
- README.md
|