tomogram_routing 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b57f52a1d3b707390584af0ec9b94dad68c09eb0
4
+ data.tar.gz: da64f2dac94b134ff9b03b511505cd02374a570c
5
+ SHA512:
6
+ metadata.gz: 915cc3e11f7fd2a2cd3f35dfeb8f5745d891f0d76f5ebcfbea51e4ba0eedba9ba611dc68f44091ea17a0d2bec7dea40128b80333dec47e87287665b382590232
7
+ data.tar.gz: c4620c299c5f135e18db92a40c1b11ae0d044eef30ca84610daaa883ca6c8250b815f3b748ccf76ebd996e41e758532f02118015cdfa34a590db63a0da1356fa
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea/
11
+ .byebug_history
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
6
+
7
+ Style/Documentation:
8
+ Enabled: false
9
+
10
+ Style/FrozenStringLiteralComment:
11
+ Enabled: false
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at d.efimov@fun-box.ru. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tomogram_routing.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 d.efimov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # TomogramRouting
2
+
3
+ From json file with the structure Tomogram api creates an object and adding methods to fast search requests and responses with json-schemes.
4
+
5
+ ## Install
6
+ ```
7
+ gem 'tomogram_routing'
8
+ ```
9
+
10
+ ```
11
+ require 'tomogram_routing'
12
+ ```
13
+
14
+ ## Using
15
+ ```
16
+ tomogram = TomogramRouting::Tomogram.craft(tomogram.json)
17
+ ```
18
+
19
+ ### find_request
20
+ ```
21
+ expect_request = tomogram.find_request(method:, path:)
22
+ ```
23
+
24
+ ### find_find_responses
25
+ ```
26
+ expect_responses = expect_request.find_responses(status:)
27
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'tomogram_routing'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require 'tomogram_routing/version'
2
+ require 'tomogram_routing/tomogram'
3
+ require 'tomogram_routing/request'
4
+
5
+ module TomogramRouting
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,9 @@
1
+ module TomogramRouting
2
+ class Request < Hash
3
+ def find_responses(status:)
4
+ self['responses'].find_all do |response|
5
+ response['status'] == status.to_s
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,69 @@
1
+ require 'multi_json'
2
+
3
+ module TomogramRouting
4
+ class Tomogram < Array
5
+ def self.craft(docs)
6
+ new(MultiJson.load(docs).inject([]) do |res, doc|
7
+ res.push(Request.new.merge(doc))
8
+ end)
9
+ end
10
+
11
+ def find_request(method:, path:)
12
+ find do |doc|
13
+ path = find_request_path(method: method, path: path)
14
+ doc['path'] == path && doc['method'] == method
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def find_request_path(method:, path:)
21
+ return '' unless path && path.size.positive?
22
+
23
+ path = remove_the_slash_at_the_end2(path)
24
+
25
+ action = search_for_an_exact_match(method, path, self)
26
+ return action['path'] if action
27
+
28
+ action = search_with_parameter(method, path, self)
29
+ return action['path'] if action&.first
30
+
31
+ ''
32
+ end
33
+
34
+ def remove_the_slash_at_the_end2(path)
35
+ return path[0..-2] if path[-1] == '/'
36
+ path
37
+ end
38
+
39
+ def search_for_an_exact_match(method, path, documentation)
40
+ documentation.find do |action|
41
+ action['path'] == path && action['method'] == method
42
+ end
43
+ end
44
+
45
+ def search_with_parameter(method, path, documentation)
46
+ documentation = actions_with_same_method(documentation, method)
47
+ sought_for_path = path.split('/')
48
+
49
+ documentation.map do |action|
50
+ current_path = action['path'].split('/')
51
+ next unless sought_for_path.size == current_path.size
52
+ next unless match(sought_for_path, current_path)
53
+ return action
54
+ end
55
+ end
56
+
57
+ def actions_with_same_method(documentation, method)
58
+ documentation.find_all do |doc|
59
+ doc['method'] == method
60
+ end
61
+ end
62
+
63
+ def match(sought_for_path, current_path)
64
+ sought_for_path.zip(current_path).all? do |p|
65
+ p[0] == p[1] || (p[1][0] == '{' && p[1][-1] == '}')
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ module TomogramRouting
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tomogram_routing/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'tomogram_routing'
8
+ spec.version = TomogramRouting::VERSION
9
+ spec.authors = ['d.efimov']
10
+ spec.email = ['d.efimov@fun-box.ru']
11
+
12
+ spec.summary = 'Routing Tomogram'
13
+ spec.description = 'Routing Tomogram API'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'multi_json', '~> 1.11', '>= 1.11.1'
22
+ spec.add_development_dependency 'bundler', '~> 1.12'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
25
+ spec.add_development_dependency 'rubocop', '~> 0.43', '>= 0.43.0'
26
+ spec.add_development_dependency 'byebug', '~> 8.2', '>= 8.2.1'
27
+ spec.add_development_dependency 'simplecov', '~> 0.11', '>= 0.11.2'
28
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tomogram_routing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - d.efimov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.11.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.11'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.11.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.12'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.12'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.4'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 3.4.0
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '3.4'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 3.4.0
81
+ - !ruby/object:Gem::Dependency
82
+ name: rubocop
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '0.43'
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 0.43.0
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0.43'
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 0.43.0
101
+ - !ruby/object:Gem::Dependency
102
+ name: byebug
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '8.2'
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 8.2.1
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '8.2'
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 8.2.1
121
+ - !ruby/object:Gem::Dependency
122
+ name: simplecov
123
+ requirement: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: '0.11'
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 0.11.2
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '0.11'
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: 0.11.2
141
+ description: Routing Tomogram API
142
+ email:
143
+ - d.efimov@fun-box.ru
144
+ executables: []
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - ".gitignore"
149
+ - ".rubocop.yml"
150
+ - CODE_OF_CONDUCT.md
151
+ - Gemfile
152
+ - LICENSE.txt
153
+ - README.md
154
+ - Rakefile
155
+ - bin/console
156
+ - bin/setup
157
+ - lib/tomogram_routing.rb
158
+ - lib/tomogram_routing/request.rb
159
+ - lib/tomogram_routing/tomogram.rb
160
+ - lib/tomogram_routing/version.rb
161
+ - tomogram_routing.gemspec
162
+ homepage:
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.5.1
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: Routing Tomogram
186
+ test_files: []
187
+ has_rdoc: