checkability 1.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f427c18e28549b00de27a9b29d5c3278be27a07f76b5efeb3c88bd07c9fa8004
4
- data.tar.gz: 68c2e5ca988d593452a15b07c2b0a9f6155cf4a170434c40509c2e8f570a1cff
3
+ metadata.gz: ae01f58d2012ce52ed74568c007178ad6e43b40046c41d6f088b42bcbac0d766
4
+ data.tar.gz: 769768802d26c6a47f90517fb5875f3b18f6b347ffd86455d7d0b79ab0d6c930
5
5
  SHA512:
6
- metadata.gz: 6f86d27e1c09d25597de9a6f82701aba4ebfe77c29c469857c1cb2b07d492e87485a9f234c957083220df84f03d66d991b1e700a7aa4121782e567a8be9a3cb2
7
- data.tar.gz: d52836824181062c8e294b56e27d3b6d486b5860d6f13be64d2fe6cefd6c9e98f22d3980a1d35d5ebde74374f3df3c89a4be8bf1b2feb7be4f69ff750c23713c
6
+ metadata.gz: 393836e6c626564325df8a5c13583804c071b720ad100003f876d4cdddda55aecd6e815b03d2389a204c4746d0ed9d9700a76d7a1d5a9ee8db79cfd86323d38b
7
+ data.tar.gz: 0a45353c00ca35c7ee4acf69097f937667f1dcb850ff1285d2e92e31a6bc4995edad468c10bb970bad2db6bc4c5ace876cf85181b85bf6d85cd182995b55e320
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,8 +32,9 @@ module Checkability
32
32
  end
33
33
 
34
34
  def perform_check
35
- Checkability::Checkable.new(self).check(ch_conf)
36
- ch_messages << "#{ch_allowed}::'#{_value}' is #{_allowness}. "
35
+ @ch_conf = ch_conf
36
+ Checkability::Checkable.new(self).check
37
+ ch_messages << "#{ch_allowed}:::'#{_value}' is #{_allowness}. "
37
38
  end
38
39
 
39
40
  private
@@ -53,8 +53,8 @@ module Checkability
53
53
 
54
54
  str = res ? success_message : failure_message
55
55
  [res, message(res, str)]
56
- # rescue StandardError => e
57
- # [false, message(false, e)]
56
+ rescue StandardError => e
57
+ [false, message(false, e)]
58
58
  end
59
59
 
60
60
  # subclass should implement
@@ -64,7 +64,7 @@ module Checkability
64
64
 
65
65
  # subclass may override
66
66
  def message(res, str)
67
- "#{res}::#{str}"
67
+ "#{res}:::#{str}"
68
68
  end
69
69
 
70
70
  private
@@ -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
@@ -24,29 +24,32 @@ module Checkability
24
24
  #
25
25
  # validator.handle(request)
26
26
  #
27
- def check(handler_confs)
28
- first_handler_name = handler_confs.keys.first
29
- first_handler = _handlers(handler_confs)[first_handler_name]
30
-
31
- first_handler.handle(check_obj)
32
- rescue StandardError => e
33
- check_obj.ch_messages << "false::#{e}: #{handler_confs}."
34
- false
27
+ # ChainOfResponsibilty
28
+ #
29
+ def check
30
+ _first_handler.handle(check_obj)
31
+ # rescue StandardError => e
32
+ # check_obj.ch_messages << "false:::#{e}: #{handler_confs}."
33
+ # false
35
34
  end
36
35
 
37
36
  private
38
37
 
39
- def _handlers(handler_confs)
40
- handlers = _make_handlers(handler_confs)
38
+ def _first_handler
39
+ _handlers[ch_conf.keys.first]
40
+ end
41
41
 
42
- handlers.each do |handler_name, handler|
43
- next_handler_name = handler_confs[handler_name][:next_handler]
44
- handler.next_handler(handlers[next_handler_name]) if handlers[next_handler_name]
42
+ def _handlers
43
+ handlers = _make_handlers
44
+ handlers.each_value.with_index do |handler, i|
45
+ next_handler = handlers[handlers.keys[i + 1]]
46
+ handler.next_handler(next_handler) if next_handler
45
47
  end
48
+ handlers
46
49
  end
47
50
 
48
- def _make_handlers(confs)
49
- confs.transform_values { |conf| _make_handler(conf) }
51
+ def _make_handlers
52
+ ch_conf.transform_values { |conf| _make_handler(conf) }
50
53
  end
51
54
 
52
55
  def _make_handler(conf)
@@ -35,7 +35,7 @@ module Checkability
35
35
  end
36
36
 
37
37
  def message(res, str = nil)
38
- "#{res}::#{path}: #{str}"
38
+ "#{res}:::#{path}: #{str}"
39
39
  end
40
40
 
41
41
  private
@@ -18,7 +18,7 @@ module Checkability
18
18
  end
19
19
 
20
20
  def message(res, str = nil)
21
- "#{res}::Allowed #{storage_class}s list: #{str}"
21
+ "#{res}:::Allowed #{storage_class}s list: #{str}"
22
22
  end
23
23
 
24
24
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Checkability
4
- VERSION = '1.0.0'
4
+ VERSION = '2.1.0'
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: 1.0.0
4
+ version: 2.1.0
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-05 00:00:00.000000000 Z
11
+ date: 2021-04-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Provide Checkers functionality.
14
14
  email: