page_magic 1.2.7 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +23 -4
- data/.simplecov +5 -3
- data/.zsh_config +6 -0
- data/Dockerfile +11 -0
- data/Gemfile +13 -13
- data/Gemfile.lock +135 -144
- data/Makefile +17 -0
- data/README.md +48 -4
- data/Rakefile +12 -2
- data/VERSION +1 -1
- data/circle.yml +4 -2
- data/lib/active_support/core_ext/object/to_query.rb +84 -0
- data/lib/page_magic.rb +22 -20
- data/lib/page_magic/class_methods.rb +5 -2
- data/lib/page_magic/comparator.rb +37 -0
- data/lib/page_magic/comparator/fuzzy.rb +23 -0
- data/lib/page_magic/comparator/literal.rb +22 -0
- data/lib/page_magic/comparator/null.rb +26 -0
- data/lib/page_magic/comparator/parameter_map.rb +52 -0
- data/lib/page_magic/driver.rb +3 -0
- data/lib/page_magic/drivers.rb +6 -5
- data/lib/page_magic/drivers/poltergeist.rb +2 -0
- data/lib/page_magic/drivers/rack_test.rb +3 -1
- data/lib/page_magic/drivers/selenium.rb +4 -2
- data/lib/page_magic/element.rb +35 -15
- data/lib/page_magic/element/locators.rb +8 -5
- data/lib/page_magic/element/not_found.rb +38 -0
- data/lib/page_magic/element/query.rb +21 -20
- data/lib/page_magic/element/query/multiple_results.rb +21 -0
- data/lib/page_magic/element/query/prefetched_result.rb +26 -0
- data/lib/page_magic/element/query/single_result.rb +20 -0
- data/lib/page_magic/element/selector.rb +41 -16
- data/lib/page_magic/element/selector/methods.rb +18 -0
- data/lib/page_magic/element/selector/model.rb +21 -0
- data/lib/page_magic/element_context.rb +7 -21
- data/lib/page_magic/element_definition_builder.rb +20 -24
- data/lib/page_magic/elements.rb +65 -68
- data/lib/page_magic/elements/config.rb +103 -0
- data/lib/page_magic/elements/inheritance_hooks.rb +15 -0
- data/lib/page_magic/elements/types.rb +25 -0
- data/lib/page_magic/exceptions.rb +6 -1
- data/lib/page_magic/instance_methods.rb +8 -3
- data/lib/page_magic/mapping.rb +79 -0
- data/lib/page_magic/session.rb +15 -35
- data/lib/page_magic/session_methods.rb +3 -1
- data/lib/page_magic/transitions.rb +49 -0
- data/lib/page_magic/utils/string.rb +18 -0
- data/lib/page_magic/utils/url.rb +20 -0
- data/lib/page_magic/wait_methods.rb +3 -0
- data/lib/page_magic/watcher.rb +12 -17
- data/lib/page_magic/watchers.rb +31 -15
- data/page_magic.gemspec +17 -13
- data/spec/lib/active_support/core_ext/object/to_query_test.rb +78 -0
- data/spec/page_magic/class_methods_spec.rb +66 -37
- data/spec/page_magic/comparator/fuzzy_spec.rb +44 -0
- data/spec/page_magic/comparator/literal_spec.rb +41 -0
- data/spec/page_magic/comparator/null_spec.rb +35 -0
- data/spec/page_magic/comparator/parameter_map_spec.rb +75 -0
- data/spec/page_magic/driver_spec.rb +26 -28
- data/spec/page_magic/drivers/poltergeist_spec.rb +6 -7
- data/spec/page_magic/drivers/rack_test_spec.rb +6 -9
- data/spec/page_magic/drivers/selenium_spec.rb +11 -12
- data/spec/page_magic/drivers_spec.rb +38 -29
- data/spec/page_magic/element/locators_spec.rb +28 -25
- data/spec/page_magic/element/not_found_spec.rb +24 -0
- data/spec/page_magic/element/query/multiple_results_spec.rb +14 -0
- data/spec/page_magic/element/query/single_result_spec.rb +21 -0
- data/spec/page_magic/element/query_spec.rb +26 -45
- data/spec/page_magic/element/selector_spec.rb +120 -110
- data/spec/page_magic/element_context_spec.rb +47 -87
- data/spec/page_magic/element_definition_builder_spec.rb +14 -71
- data/spec/page_magic/element_spec.rb +256 -0
- data/spec/page_magic/elements/config_spec.rb +200 -0
- data/spec/page_magic/elements_spec.rb +90 -127
- data/spec/page_magic/instance_methods_spec.rb +65 -63
- data/spec/page_magic/mapping_spec.rb +181 -0
- data/spec/page_magic/session_methods_spec.rb +29 -25
- data/spec/page_magic/session_spec.rb +109 -199
- data/spec/page_magic/transitions_spec.rb +43 -0
- data/spec/page_magic/utils/string_spec.rb +29 -0
- data/spec/page_magic/utils/url_spec.rb +9 -0
- data/spec/page_magic/wait_methods_spec.rb +16 -22
- data/spec/page_magic/watcher_spec.rb +22 -0
- data/spec/page_magic/watchers_spec.rb +58 -62
- data/spec/page_magic_spec.rb +31 -30
- data/spec/spec_helper.rb +9 -2
- data/spec/support/shared_contexts.rb +3 -1
- data/spec/support/shared_examples.rb +17 -17
- metadata +101 -48
- data/lib/page_magic/element/query_builder.rb +0 -48
- data/lib/page_magic/element/selector_methods.rb +0 -13
- data/lib/page_magic/matcher.rb +0 -121
- data/spec/element_spec.rb +0 -249
- data/spec/page_magic/element/query_builder_spec.rb +0 -108
- data/spec/page_magic/matcher_spec.rb +0 -336
- data/spec/support/shared_contexts/files_context.rb +0 -7
- data/spec/support/shared_contexts/nested_elements_html_context.rb +0 -16
- data/spec/support/shared_contexts/rack_application_context.rb +0 -9
- data/spec/support/shared_contexts/webapp_fixture_context.rb +0 -39
- data/spec/watcher_spec.rb +0 -61
metadata
CHANGED
@@ -1,115 +1,143 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: page_magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leon Davis
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: capybara
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: github-markup
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
39
46
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: jeweler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: redcarpet
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: rubocop
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
|
-
- - "
|
87
|
+
- - ">="
|
60
88
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
89
|
+
version: '0'
|
62
90
|
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
|
-
- - "
|
94
|
+
- - ">="
|
67
95
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0
|
96
|
+
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
98
|
+
name: rubocop-rspec
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
|
-
- - "
|
101
|
+
- - ">="
|
74
102
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0
|
103
|
+
version: '0'
|
76
104
|
type: :development
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
|
-
- - "
|
108
|
+
- - ">="
|
81
109
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0
|
110
|
+
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
112
|
+
name: ruby-debug-ide
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
|
-
- - "
|
115
|
+
- - ">="
|
88
116
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
117
|
+
version: '0'
|
90
118
|
type: :development
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
94
|
-
- - "
|
122
|
+
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
124
|
+
version: '0'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
126
|
+
name: yard
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
100
128
|
requirements:
|
101
129
|
- - "~>"
|
102
130
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
131
|
+
version: '0.8'
|
104
132
|
type: :development
|
105
133
|
prerelease: false
|
106
134
|
version_requirements: !ruby/object:Gem::Requirement
|
107
135
|
requirements:
|
108
136
|
- - "~>"
|
109
137
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
138
|
+
version: '0.8'
|
111
139
|
description: Framework for modeling and interacting with webpages which wraps capybara
|
112
|
-
email: info@
|
140
|
+
email: info@lvl-up.uk
|
113
141
|
executables: []
|
114
142
|
extensions: []
|
115
143
|
extra_rdoc_files:
|
@@ -121,14 +149,23 @@ files:
|
|
121
149
|
- ".rubocop.yml"
|
122
150
|
- ".simplecov"
|
123
151
|
- ".yardopts"
|
152
|
+
- ".zsh_config"
|
153
|
+
- Dockerfile
|
124
154
|
- Gemfile
|
125
155
|
- Gemfile.lock
|
156
|
+
- Makefile
|
126
157
|
- README.md
|
127
158
|
- Rakefile
|
128
159
|
- VERSION
|
129
160
|
- circle.yml
|
161
|
+
- lib/active_support/core_ext/object/to_query.rb
|
130
162
|
- lib/page_magic.rb
|
131
163
|
- lib/page_magic/class_methods.rb
|
164
|
+
- lib/page_magic/comparator.rb
|
165
|
+
- lib/page_magic/comparator/fuzzy.rb
|
166
|
+
- lib/page_magic/comparator/literal.rb
|
167
|
+
- lib/page_magic/comparator/null.rb
|
168
|
+
- lib/page_magic/comparator/parameter_map.rb
|
132
169
|
- lib/page_magic/driver.rb
|
133
170
|
- lib/page_magic/drivers.rb
|
134
171
|
- lib/page_magic/drivers/poltergeist.rb
|
@@ -136,56 +173,73 @@ files:
|
|
136
173
|
- lib/page_magic/drivers/selenium.rb
|
137
174
|
- lib/page_magic/element.rb
|
138
175
|
- lib/page_magic/element/locators.rb
|
176
|
+
- lib/page_magic/element/not_found.rb
|
139
177
|
- lib/page_magic/element/query.rb
|
140
|
-
- lib/page_magic/element/
|
178
|
+
- lib/page_magic/element/query/multiple_results.rb
|
179
|
+
- lib/page_magic/element/query/prefetched_result.rb
|
180
|
+
- lib/page_magic/element/query/single_result.rb
|
141
181
|
- lib/page_magic/element/selector.rb
|
142
|
-
- lib/page_magic/element/
|
182
|
+
- lib/page_magic/element/selector/methods.rb
|
183
|
+
- lib/page_magic/element/selector/model.rb
|
143
184
|
- lib/page_magic/element_context.rb
|
144
185
|
- lib/page_magic/element_definition_builder.rb
|
145
186
|
- lib/page_magic/elements.rb
|
187
|
+
- lib/page_magic/elements/config.rb
|
188
|
+
- lib/page_magic/elements/inheritance_hooks.rb
|
189
|
+
- lib/page_magic/elements/types.rb
|
146
190
|
- lib/page_magic/exceptions.rb
|
147
191
|
- lib/page_magic/instance_methods.rb
|
148
|
-
- lib/page_magic/
|
192
|
+
- lib/page_magic/mapping.rb
|
149
193
|
- lib/page_magic/session.rb
|
150
194
|
- lib/page_magic/session_methods.rb
|
195
|
+
- lib/page_magic/transitions.rb
|
196
|
+
- lib/page_magic/utils/string.rb
|
197
|
+
- lib/page_magic/utils/url.rb
|
151
198
|
- lib/page_magic/wait_methods.rb
|
152
199
|
- lib/page_magic/watcher.rb
|
153
200
|
- lib/page_magic/watchers.rb
|
154
201
|
- page_magic.gemspec
|
155
|
-
- spec/
|
202
|
+
- spec/lib/active_support/core_ext/object/to_query_test.rb
|
156
203
|
- spec/page_magic/class_methods_spec.rb
|
204
|
+
- spec/page_magic/comparator/fuzzy_spec.rb
|
205
|
+
- spec/page_magic/comparator/literal_spec.rb
|
206
|
+
- spec/page_magic/comparator/null_spec.rb
|
207
|
+
- spec/page_magic/comparator/parameter_map_spec.rb
|
157
208
|
- spec/page_magic/driver_spec.rb
|
158
209
|
- spec/page_magic/drivers/poltergeist_spec.rb
|
159
210
|
- spec/page_magic/drivers/rack_test_spec.rb
|
160
211
|
- spec/page_magic/drivers/selenium_spec.rb
|
161
212
|
- spec/page_magic/drivers_spec.rb
|
162
213
|
- spec/page_magic/element/locators_spec.rb
|
163
|
-
- spec/page_magic/element/
|
214
|
+
- spec/page_magic/element/not_found_spec.rb
|
215
|
+
- spec/page_magic/element/query/multiple_results_spec.rb
|
216
|
+
- spec/page_magic/element/query/single_result_spec.rb
|
164
217
|
- spec/page_magic/element/query_spec.rb
|
165
218
|
- spec/page_magic/element/selector_spec.rb
|
166
219
|
- spec/page_magic/element_context_spec.rb
|
167
220
|
- spec/page_magic/element_definition_builder_spec.rb
|
221
|
+
- spec/page_magic/element_spec.rb
|
222
|
+
- spec/page_magic/elements/config_spec.rb
|
168
223
|
- spec/page_magic/elements_spec.rb
|
169
224
|
- spec/page_magic/instance_methods_spec.rb
|
170
|
-
- spec/page_magic/
|
225
|
+
- spec/page_magic/mapping_spec.rb
|
171
226
|
- spec/page_magic/session_methods_spec.rb
|
172
227
|
- spec/page_magic/session_spec.rb
|
228
|
+
- spec/page_magic/transitions_spec.rb
|
229
|
+
- spec/page_magic/utils/string_spec.rb
|
230
|
+
- spec/page_magic/utils/url_spec.rb
|
173
231
|
- spec/page_magic/wait_methods_spec.rb
|
232
|
+
- spec/page_magic/watcher_spec.rb
|
174
233
|
- spec/page_magic/watchers_spec.rb
|
175
234
|
- spec/page_magic_spec.rb
|
176
235
|
- spec/spec_helper.rb
|
177
236
|
- spec/support/shared_contexts.rb
|
178
|
-
- spec/support/shared_contexts/files_context.rb
|
179
|
-
- spec/support/shared_contexts/nested_elements_html_context.rb
|
180
|
-
- spec/support/shared_contexts/rack_application_context.rb
|
181
|
-
- spec/support/shared_contexts/webapp_fixture_context.rb
|
182
237
|
- spec/support/shared_examples.rb
|
183
|
-
- spec/watcher_spec.rb
|
184
238
|
homepage: https://github.com/ladtech/page_magic
|
185
239
|
licenses:
|
186
240
|
- ruby
|
187
241
|
metadata: {}
|
188
|
-
post_install_message:
|
242
|
+
post_install_message:
|
189
243
|
rdoc_options: []
|
190
244
|
require_paths:
|
191
245
|
- lib
|
@@ -200,9 +254,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
254
|
- !ruby/object:Gem::Version
|
201
255
|
version: '0'
|
202
256
|
requirements: []
|
203
|
-
|
204
|
-
|
205
|
-
signing_key:
|
257
|
+
rubygems_version: 3.1.4
|
258
|
+
signing_key:
|
206
259
|
specification_version: 4
|
207
260
|
summary: Framework for modeling and interacting with webpages
|
208
261
|
test_files: []
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'capybara/query'
|
2
|
-
require 'page_magic/element/query'
|
3
|
-
module PageMagic
|
4
|
-
class Element
|
5
|
-
# class QueryBuilder - builds query to be executed on capybara driver, queries can include:
|
6
|
-
# - requirements on element type
|
7
|
-
# - selection criteria, modeled through the Selector class
|
8
|
-
# - options
|
9
|
-
class QueryBuilder
|
10
|
-
class << self
|
11
|
-
# Find a query using it's name
|
12
|
-
# @param [Symbol] type the name of the required query in snakecase format
|
13
|
-
# @return [QueryBuilder] returns the predefined query with the given name
|
14
|
-
def find(type)
|
15
|
-
query = constants.find { |constant| constant.to_s.casecmp(type.to_s).zero? }
|
16
|
-
return ELEMENT unless query
|
17
|
-
const_get(query)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
attr_reader :type
|
22
|
-
|
23
|
-
# @param type -
|
24
|
-
def initialize(type = nil)
|
25
|
-
@type = type
|
26
|
-
end
|
27
|
-
|
28
|
-
# Build query parameters for Capybara's find method
|
29
|
-
# @param [Hash] locator the location method e.g. text: 'button text'
|
30
|
-
# @param [Hash] capybara_options additional options to be provided to Capybara. e.g. count: 3
|
31
|
-
# @return [Array] list of compatible capybara query parameters.
|
32
|
-
def build(locator, capybara_options = {}, multiple_results: false)
|
33
|
-
args = [].tap do |array|
|
34
|
-
selector = Selector.find(locator.keys.first)
|
35
|
-
array << selector.build(type, locator.values.first)
|
36
|
-
array << capybara_options unless capybara_options.empty?
|
37
|
-
end.flatten
|
38
|
-
|
39
|
-
Query.new(args, multiple_results: multiple_results)
|
40
|
-
end
|
41
|
-
|
42
|
-
ELEMENT = QueryBuilder.new
|
43
|
-
TEXT_FIELD = CHECKBOX = SELECT_LIST = RADIO = TEXTAREA = QueryBuilder.new(:field)
|
44
|
-
LINK = QueryBuilder.new(:link)
|
45
|
-
BUTTON = QueryBuilder.new(:button)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module PageMagic
|
2
|
-
class Element
|
3
|
-
# module SelectorMethods - adds method for getting and setting an element selector
|
4
|
-
module SelectorMethods
|
5
|
-
# Gets/Sets a selector
|
6
|
-
# @param [Hash] selector method for locating the browser element. E.g. text: 'the text'
|
7
|
-
def selector(selector = nil)
|
8
|
-
return @selector unless selector
|
9
|
-
@selector = selector
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/page_magic/matcher.rb
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/object/to_query'
|
2
|
-
module PageMagic
|
3
|
-
# models mapping used to relate pages to uris
|
4
|
-
class Matcher
|
5
|
-
attr_reader :path, :parameters, :fragment
|
6
|
-
|
7
|
-
# @param [Object] path String or Regular expression to match with
|
8
|
-
# @param [Hash] parameters mapping of parameter name to literal or regex to match with
|
9
|
-
# @param [Object] fragment String or Regular expression to match with
|
10
|
-
# @raise [MatcherInvalidException] if at least one component is not specified
|
11
|
-
def initialize(path = nil, parameters: nil, fragment: nil)
|
12
|
-
raise MatcherInvalidException unless path || parameters || fragment
|
13
|
-
@path = path
|
14
|
-
@parameters = parameters
|
15
|
-
@fragment = fragment
|
16
|
-
end
|
17
|
-
|
18
|
-
# @return [Boolean] true if no component contains a Regexp
|
19
|
-
def can_compute_uri?
|
20
|
-
!fuzzy?(fragment) && !fuzzy?(path) && !fuzzy?(parameters)
|
21
|
-
end
|
22
|
-
|
23
|
-
# @return [String] uri represented by this mapping
|
24
|
-
def compute_uri
|
25
|
-
path.to_s.tap do |uri|
|
26
|
-
uri << "?#{parameters.to_query}" if parameters
|
27
|
-
uri << "##{fragment}" if fragment
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# @return [Fixnum] hash for instance
|
32
|
-
def hash
|
33
|
-
[path, parameters, fragment].hash
|
34
|
-
end
|
35
|
-
|
36
|
-
# @param [String] uri
|
37
|
-
# @return [Boolean] returns true if the uri is matched against this matcher
|
38
|
-
def match?(uri)
|
39
|
-
uri = URI(uri)
|
40
|
-
path_valid?(uri.path) && query_string_valid?(uri.query) && fragment_valid?(uri.fragment)
|
41
|
-
end
|
42
|
-
|
43
|
-
# compare this matcher against another
|
44
|
-
# @param [Matcher] other
|
45
|
-
# @return [Fixnum] -1 = smaller, 0 = equal to, 1 = greater than
|
46
|
-
def <=>(other)
|
47
|
-
results = [:path, :parameters, :fragment].collect do |component|
|
48
|
-
compare(send(component), other.send(component))
|
49
|
-
end
|
50
|
-
results.find { |result| !result.zero? } || 0
|
51
|
-
end
|
52
|
-
|
53
|
-
# check equality
|
54
|
-
# @param [Matcher] other
|
55
|
-
# @return [Boolean]
|
56
|
-
def ==(other)
|
57
|
-
return false unless other.is_a?(Matcher)
|
58
|
-
path == other.path && parameters == other.parameters && fragment == other.fragment
|
59
|
-
end
|
60
|
-
|
61
|
-
alias eql? ==
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def compare(this, other)
|
66
|
-
return presence_comparison(this, other) unless this && other
|
67
|
-
fuzzy_comparison(this, other)
|
68
|
-
end
|
69
|
-
|
70
|
-
def compatible?(string, comparitor)
|
71
|
-
return true if comparitor.nil?
|
72
|
-
if fuzzy?(comparitor)
|
73
|
-
string =~ comparitor ? true : false
|
74
|
-
else
|
75
|
-
string == comparitor
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def fragment_valid?(string)
|
80
|
-
compatible?(string, fragment)
|
81
|
-
end
|
82
|
-
|
83
|
-
def fuzzy?(component)
|
84
|
-
return false unless component
|
85
|
-
if component.is_a?(Hash)
|
86
|
-
component.values.any? { |o| fuzzy?(o) }
|
87
|
-
else
|
88
|
-
component.is_a?(Regexp)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def fuzzy_comparison(this, other)
|
93
|
-
if fuzzy?(this)
|
94
|
-
fuzzy?(other) ? 0 : 1
|
95
|
-
else
|
96
|
-
fuzzy?(other) ? -1 : 0
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def parameters_hash(string)
|
101
|
-
CGI.parse(string.to_s.downcase).collect { |key, value| [key.downcase, value.first] }.to_h
|
102
|
-
end
|
103
|
-
|
104
|
-
def path_valid?(string)
|
105
|
-
compatible?(string, path)
|
106
|
-
end
|
107
|
-
|
108
|
-
def presence_comparison(this, other)
|
109
|
-
return 0 if this.nil? && other.nil?
|
110
|
-
return 1 if this.nil? && other
|
111
|
-
-1
|
112
|
-
end
|
113
|
-
|
114
|
-
def query_string_valid?(string)
|
115
|
-
return true unless parameters
|
116
|
-
!parameters.any? do |key, value|
|
117
|
-
!compatible?(parameters_hash(string)[key.downcase.to_s], value)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|