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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ef4662b01dddfa99efdc01e395b75490a4fe7b2
4
- data.tar.gz: 4422ee47ef65b3aa1d5188d3d009f911eb1be652
3
+ metadata.gz: 426579708bc9b59286a012e4eccbf37f1ff5394d
4
+ data.tar.gz: 2f0e3f57e653759f0b3c6fc4252ccb5ddf4fcaf4
5
5
  SHA512:
6
- metadata.gz: 9fb88d0f765aa69e8f6d0e4b8523c4e07e505fb666ca1a02c2f27a502e54049967d101157de1e7ab426fa117f11ed84e078f842eea456be96b4bb674ee8c943d
7
- data.tar.gz: 5d4ea13f2f580f8c9bdefa84fef462030504b396fdbec84d5dbec00f4c271c23b5597cc61ffc722b57572bc1730b1e730a14591db24953c6528961e9f85dfba5
6
+ metadata.gz: 21f6d659534bcedaff0f1c46cdf8b6cc772c99d890f1a1dd4cc9a4c4519a2c559f5008d18df45a56281f3147c2f404371189d8091a373dcc3c12051ec221b29b
7
+ data.tar.gz: 2f000e3341a5084c14eefdf64ae70f5a35f8363f561a06becfba96b209b746c29583fa4880d573014ecf176d06724b5eca69b475d7e3381f72f3796a0a28de36
@@ -0,0 +1,6 @@
1
+ image: ruby:2.3.1
2
+ testing:
3
+ before_script:
4
+ - gem install bundler
5
+ - bundle install
6
+ script: rspec
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'AR2H'
7
- spec.version = '0.0.2'
7
+ spec.version = '1.0.0'
8
8
  spec.authors = ['Eugene Yak']
9
9
  spec.email = ['GeneAYak@gmail.com']
10
10
 
@@ -1,3 +1,6 @@
1
+ require 'active_support'
2
+ require 'active_record'
3
+
1
4
  require 'AR2H/executor'
2
5
  require 'AR2H/logger'
3
6
 
@@ -1,5 +1,3 @@
1
- require 'active_record'
2
-
3
1
  module AR2H
4
2
  module Concerns
5
3
  module ActiveRecordConcern
@@ -1,5 +1,3 @@
1
- require 'active_record'
2
-
3
1
  module AR2H
4
2
  module Concerns
5
3
  module ActiveRecordConcern
@@ -10,11 +10,10 @@ module AR2H
10
10
 
11
11
  case multiple
12
12
  when false
13
- new(object, presenter).execute
13
+ new(object, presenter).run
14
14
  when true
15
- object.map { |el| new(el, presenter).execute }
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 execute
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
@@ -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? 'action_controller'
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.name
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?(name)
26
- list.include? name
25
+ def include?(presenter)
26
+ list.include? presenter.name
27
27
  end
28
28
 
29
29
  def find(name)
@@ -9,7 +9,11 @@ module AR2H
9
9
  attr_reader :name
10
10
 
11
11
  def block
12
- @block ? @block : Proc.new
12
+ @block ? @block : Proc.new{}
13
+ end
14
+
15
+ def eql?(candidate)
16
+ self.name == candidate.name
13
17
  end
14
18
 
15
19
  end
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.2
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-05 00:00:00.000000000 Z
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