checkability 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +3 -0
- data/lib/checkability.rb +6 -0
- data/lib/checkability/checkable.rb +25 -0
- data/lib/checkability/external_api_checker.rb +42 -0
- data/lib/checkability/external_api_connector.rb +18 -0
- data/lib/checkability/railtie.rb +4 -0
- data/lib/checkability/storage_checker.rb +26 -0
- data/lib/checkability/validator.rb +25 -0
- data/lib/checkability/version.rb +3 -0
- data/lib/tasks/checkability_tasks.rake +4 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 148d47cb845c2354cee354d4852b43054a2af514
|
4
|
+
data.tar.gz: 91c98f1a5e3cbf800290b645c516db1c69419c17
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f2052db80385a337dd9567ff890f56c299ae99f3341eb1734f701b8f5d536713ffde8fd148f36a358aabcbcc140a9517bca1d49688e200327835e36d02fa104c
|
7
|
+
data.tar.gz: 024178f440d540b3bd9ef2df354793ac137f8bf338902da587881cee4929147d1d698b59eb7419e63b569caf1c1853aa7e3985835c1e19efad40ebfdbfa29f68
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2021 Andrey Eremeev
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Checkability
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'checkability'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install checkability
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/lib/checkability.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Checks if postcode exists in Storage
|
2
|
+
#
|
3
|
+
module Checkability
|
4
|
+
class Checkable
|
5
|
+
attr_reader :checkable
|
6
|
+
|
7
|
+
def initialize(checkable)
|
8
|
+
@checkable = checkable
|
9
|
+
end
|
10
|
+
|
11
|
+
# sentence is a proc
|
12
|
+
# like { |a,b,c| a && ( b || c ) }
|
13
|
+
# where a,b,c are checkers
|
14
|
+
# and each should return [true, message] or [false, message]
|
15
|
+
# checkers is an array of checker objects
|
16
|
+
# e.g. [storage_checker, external_api_checker]
|
17
|
+
def check(algoritm = nil, checkers = [])
|
18
|
+
algoritm.call(
|
19
|
+
checkers.map do |checker|
|
20
|
+
checker.check_value(checkable)
|
21
|
+
end
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#require 'faraday_middleware'
|
2
|
+
require 'faraday'
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
# Checks if postcode exists in Storage
|
8
|
+
#
|
9
|
+
module Checkability
|
10
|
+
class ExternalApiChecker
|
11
|
+
attr_reader :path, :check_method, :connection
|
12
|
+
|
13
|
+
def initialize(conf={})
|
14
|
+
@path = conf[:path]
|
15
|
+
@check_method = conf[:check_method]
|
16
|
+
@connection = Checkability::ExternalApiConnector.new(conf).connect
|
17
|
+
end
|
18
|
+
|
19
|
+
def check_value(checkable)
|
20
|
+
@resp = connection.get(checkable.value.gsub(' ',''))
|
21
|
+
result, message = _result_and_message
|
22
|
+
checkable.messages << message
|
23
|
+
result
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def _message(str); "#{path}: #{str}"; end
|
29
|
+
|
30
|
+
def _parsed(resp); JSON.parse(resp.body); end
|
31
|
+
|
32
|
+
def _result_and_message
|
33
|
+
return [false, _message(@resp.status)] unless @resp.status == 200
|
34
|
+
|
35
|
+
return [true, _message('Found.')] if check_method.call(_parsed(@resp))
|
36
|
+
|
37
|
+
[false, _message('Not found in allowed areas.')]
|
38
|
+
rescue Exception => e
|
39
|
+
[false, _message(e)]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Create connection
|
2
|
+
#
|
3
|
+
module Checkability
|
4
|
+
class ExternalApiConnector
|
5
|
+
attr_reader :path
|
6
|
+
|
7
|
+
def initialize(conf)
|
8
|
+
@path = conf[:path]
|
9
|
+
end
|
10
|
+
|
11
|
+
def connect
|
12
|
+
Faraday.new(:url => self.path) do |faraday|
|
13
|
+
faraday.headers['Content-Type'] = 'application/json'
|
14
|
+
faraday.adapter Faraday.default_adapter
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Checks if postcode exists in Storage
|
2
|
+
#
|
3
|
+
module Checkability
|
4
|
+
class StorageChecker
|
5
|
+
attr_reader :storage_class
|
6
|
+
|
7
|
+
def initialize(conf={})
|
8
|
+
@storage_class = conf[:storage_class]
|
9
|
+
end
|
10
|
+
|
11
|
+
def check_value(checkable)
|
12
|
+
value = checkable.value.upcase
|
13
|
+
result =
|
14
|
+
storage_class.where( value: value )
|
15
|
+
.or( storage_class.where(value: value.strip) )
|
16
|
+
.or( storage_class.where(value: value.gsub(' ','')) )
|
17
|
+
.present?
|
18
|
+
checkable.messages << (result ? _message('Found') : _message('Not found'))
|
19
|
+
result
|
20
|
+
end
|
21
|
+
|
22
|
+
def _message(str)
|
23
|
+
"Allowed #{storage_class}s list: #{str}."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Checks if postcode exists in Storage
|
2
|
+
#
|
3
|
+
module Checkability
|
4
|
+
class Validator
|
5
|
+
attr_reader :format
|
6
|
+
|
7
|
+
def initialize(conf={})
|
8
|
+
@format = conf[:format]
|
9
|
+
end
|
10
|
+
|
11
|
+
def check_value(checkable)
|
12
|
+
result, message = _result_and_message(checkable)
|
13
|
+
checkable.messages << message
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
17
|
+
def _result_and_message(checkable)
|
18
|
+
if (checkable.value.gsub(' ','') =~ format[:regex]).nil?
|
19
|
+
[false, "Value is not comply with format of #{format[:name]}."]
|
20
|
+
else
|
21
|
+
[true, "Value comply with format of #{format[:name]}."]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: checkability
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrey Eremeev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Provide Checkers functionality.
|
14
|
+
email:
|
15
|
+
- andrey.eremeyev@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- MIT-LICENSE
|
21
|
+
- README.md
|
22
|
+
- Rakefile
|
23
|
+
- lib/checkability.rb
|
24
|
+
- lib/checkability/checkable.rb
|
25
|
+
- lib/checkability/external_api_checker.rb
|
26
|
+
- lib/checkability/external_api_connector.rb
|
27
|
+
- lib/checkability/railtie.rb
|
28
|
+
- lib/checkability/storage_checker.rb
|
29
|
+
- lib/checkability/validator.rb
|
30
|
+
- lib/checkability/version.rb
|
31
|
+
- lib/tasks/checkability_tasks.rake
|
32
|
+
homepage: https://github.com/azazelo/checkability
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata:
|
36
|
+
allowed_push_host: https://rubygems.org
|
37
|
+
homepage_uri: https://github.com/azazelo/checkability
|
38
|
+
source_code_uri: https://rubygems.org
|
39
|
+
changelog_uri: https://rubygems.org
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.4.6
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Provide Checkers functionality.
|
60
|
+
test_files: []
|