checkability 2.0.1 → 2.1.2

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
  SHA256:
3
- metadata.gz: fa1ae6fc8c72cd3073a9301eb633a23bed7a3912a3e338e54c83aba5fc8f4b08
4
- data.tar.gz: 8d1935bd53420a47316e76ce952b18c0b8ca4d96e8ee0193fcce5aea16a159e4
3
+ metadata.gz: 025ba09f183579762584e89daf10b06fe93c8d2da5ce899120ae2c9b8bf15726
4
+ data.tar.gz: 3b5f2c538aa618dfc077c35c2d176bf78a36336a97395caeab236f1101795aa1
5
5
  SHA512:
6
- metadata.gz: 971c297f7e4d8da9eb73a02bdad49329c0e84024553d3f864e0a91e02aee71fc5f71e0ab3d4ef9b66b6696047237c3c36f7c22d72004bc70fc6dfceb4d4ec125
7
- data.tar.gz: 1a22cb5f5f8b25612116f5b302e82b5d914a05aaedfc624c6c635db56fd23d3998b29dc8582f633d78f64f7ef8120d5a87d66052b0c5adba0ec41558174166a6
6
+ metadata.gz: 464e94ce7a7c4538f27c1e740b92f61392f0a08683debb21d39e7189782fc214ad4dc8e9add85278352c36d40249799cef53f00005361cf20439d9d6f534e12b
7
+ data.tar.gz: 16c0f544f7b2164fb31c9be12bfcedcae5a28a54b31028ed048ae4bafe1e49d22dea0ba606ce750eeebdac64cb8fd0a25b9ff5dc4fdab559d982260287a2105e
data/README.md CHANGED
@@ -76,4 +76,5 @@ The gem is available as open source under the terms of the [MIT License](https:/
76
76
 
77
77
  ## Future works
78
78
 
79
- - [ ] Use ChainOfResponsibility pattern to simplify call of checkers
79
+ - [X] Use ChainOfResponsibility pattern to simplify call of checkers
80
+ - [ ] Improve test with adding doubles
@@ -23,7 +23,7 @@ module Checkability
23
23
  end
24
24
  end
25
25
 
26
- attr_accessor :ch_allowed, :ch_messages
26
+ attr_accessor :ch_allowed, :ch_messages, :ch_conf
27
27
 
28
28
  def initialize(params)
29
29
  @ch_messages = []
@@ -32,7 +32,8 @@ module Checkability
32
32
  end
33
33
 
34
34
  def perform_check
35
- Checkability::Checkable.new(self).check(ch_conf)
35
+ @ch_conf = ch_conf
36
+ Checkability::Checkable.new(self).check
36
37
  ch_messages << "#{ch_allowed}:::'#{_value}' is #{_allowness}. "
37
38
  end
38
39
 
@@ -10,10 +10,10 @@ module Checkability
10
10
  :success_message, :failure_message
11
11
 
12
12
  def initialize(opts = {})
13
- @stop_process_on_failure = opts[:stop_process_on_failure] || false
14
- @stop_process_on_success = opts[:stop_process_on_success] || false
15
- @success_message = opts[:success_message] || 'Success.'
16
- @failure_message = opts[:failure_message] || 'Failed.'
13
+ @stop_process_on_failure = opts.fetch(:stop_process_on_failure) { false }
14
+ @stop_process_on_success = opts.fetch(:stop_process_on_success) { false }
15
+ @success_message = opts.fetch(:success_message) { 'Success.' }
16
+ @failure_message = opts.fetch(:failure_message) { 'Failed.' }
17
17
 
18
18
  @next_handler = nil
19
19
  post_initialize(opts) # implemented in subclass
@@ -7,10 +7,10 @@ module Checkability
7
7
  # Possible to implemet as Iterator in future
8
8
  #
9
9
  class Checkable
10
- attr_accessor :check_obj
10
+ attr_accessor :check_obj, :handler_confs
11
11
 
12
12
  extend Forwardable
13
- def_delegators :@check_obj, :ch_messages, :ch_allowed
13
+ def_delegators :@check_obj, :ch_messages, :ch_allowed, :ch_conf
14
14
 
15
15
  def initialize(check_obj)
16
16
  @check_obj = check_obj
@@ -26,11 +26,8 @@ module Checkability
26
26
  #
27
27
  # ChainOfResponsibilty
28
28
  #
29
- def check(handler_confs)
30
- first_handler_name = handler_confs.keys.first
31
- first_handler = _handlers(handler_confs)[first_handler_name]
32
-
33
- first_handler.handle(check_obj)
29
+ def check
30
+ _first_handler.handle(check_obj)
34
31
  rescue StandardError => e
35
32
  check_obj.ch_messages << "false:::#{e}: #{handler_confs}."
36
33
  false
@@ -38,17 +35,21 @@ module Checkability
38
35
 
39
36
  private
40
37
 
41
- def _handlers(handler_confs)
42
- handlers = _make_handlers(handler_confs)
38
+ def _first_handler
39
+ _handlers[ch_conf.keys.first]
40
+ end
41
+
42
+ def _handlers
43
+ handlers = _make_handlers
43
44
  handlers.each_value.with_index do |handler, i|
44
- next_handler_name = handlers.keys[i + 1]
45
- handler.next_handler(handlers[next_handler_name]) if handlers[next_handler_name]
45
+ next_handler = handlers[handlers.keys[i + 1]]
46
+ handler.next_handler(next_handler) if next_handler
46
47
  end
47
48
  handlers
48
49
  end
49
50
 
50
- def _make_handlers(confs)
51
- confs.transform_values { |conf| _make_handler(conf) }
51
+ def _make_handlers
52
+ ch_conf.transform_values { |conf| _make_handler(conf) }
52
53
  end
53
54
 
54
55
  def _make_handler(conf)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Checkability
4
- VERSION = '2.0.1'
4
+ VERSION = '2.1.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checkability
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Eremeev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-06 00:00:00.000000000 Z
11
+ date: 2021-04-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Provide Checkers functionality.
14
14
  email: