page_magic 1.2.5 → 1.2.6
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 +4 -4
- data/.rubocop.yml +4 -1
- data/Gemfile.lock +24 -24
- data/VERSION +1 -1
- data/lib/page_magic/matcher.rb +6 -2
- data/lib/page_magic.rb +8 -0
- data/page_magic.gemspec +2 -2
- data/spec/page_magic/matcher_spec.rb +118 -17
- data/spec/page_magic_spec.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f5e27b2a270ba1333f9ae3b00500892ca2db6ea
|
4
|
+
data.tar.gz: adb6f8c204b92c581ae8d05198899f1fe54decb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 220f194ecca9dc7ddcb6f912d0ea45caf922dc2704011e4fc5d897382d8af1d0a2a9725db585767d23a9913ad0f387e258dc0d9b73545290a25bb181b9e82578
|
7
|
+
data.tar.gz: aeefe035655fc201c01d4539026be9162fea73fe7e173314ce0fe7389529d089507af383299727307598b1e0c406a576a55f160f38f5128df201dde38f2fa167
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activesupport (4.2.
|
4
|
+
activesupport (4.2.7)
|
5
5
|
i18n (~> 0.7)
|
6
6
|
json (~> 1.7, >= 1.7.7)
|
7
7
|
minitest (~> 5.1)
|
8
8
|
thread_safe (~> 0.3, >= 0.3.4)
|
9
9
|
tzinfo (~> 1.1)
|
10
10
|
addressable (2.4.0)
|
11
|
-
arbre (1.
|
11
|
+
arbre (1.1.1)
|
12
12
|
activesupport (>= 3.0.0)
|
13
13
|
ast (2.3.0)
|
14
14
|
builder (3.2.2)
|
@@ -31,15 +31,15 @@ GEM
|
|
31
31
|
docile (1.1.5)
|
32
32
|
faraday (0.9.2)
|
33
33
|
multipart-post (>= 1.2, < 3)
|
34
|
-
ffi (1.9.
|
34
|
+
ffi (1.9.14)
|
35
35
|
git (1.3.0)
|
36
36
|
github-markup (1.4.0)
|
37
|
-
github_api (0.14.
|
37
|
+
github_api (0.14.4)
|
38
38
|
addressable (~> 2.4.0)
|
39
39
|
descendants_tracker (~> 0.0.4)
|
40
40
|
faraday (~> 0.8, < 0.10)
|
41
41
|
hashie (>= 3.4)
|
42
|
-
oauth2
|
42
|
+
oauth2 (~> 1.0.0)
|
43
43
|
hashie (3.4.4)
|
44
44
|
highline (1.7.8)
|
45
45
|
i18n (0.7.0)
|
@@ -54,7 +54,7 @@ GEM
|
|
54
54
|
rdoc
|
55
55
|
semver
|
56
56
|
json (1.8.3)
|
57
|
-
jwt (1.5.
|
57
|
+
jwt (1.5.4)
|
58
58
|
mime-types (3.1)
|
59
59
|
mime-types-data (~> 3.2015)
|
60
60
|
mime-types-data (3.2016.0521)
|
@@ -66,12 +66,12 @@ GEM
|
|
66
66
|
nokogiri (1.6.8)
|
67
67
|
mini_portile2 (~> 2.1.0)
|
68
68
|
pkg-config (~> 1.1.7)
|
69
|
-
oauth2 (1.
|
69
|
+
oauth2 (1.0.0)
|
70
70
|
faraday (>= 0.8, < 0.10)
|
71
|
-
jwt (~> 1.0
|
71
|
+
jwt (~> 1.0)
|
72
72
|
multi_json (~> 1.3)
|
73
73
|
multi_xml (~> 0.5)
|
74
|
-
rack (
|
74
|
+
rack (~> 1.2)
|
75
75
|
parser (2.3.1.2)
|
76
76
|
ast (~> 2.2)
|
77
77
|
pkg-config (1.1.7)
|
@@ -93,20 +93,20 @@ GEM
|
|
93
93
|
rdoc (4.2.2)
|
94
94
|
json (~> 1.4)
|
95
95
|
redcarpet (3.3.4)
|
96
|
-
rspec (3.
|
97
|
-
rspec-core (~> 3.
|
98
|
-
rspec-expectations (~> 3.
|
99
|
-
rspec-mocks (~> 3.
|
100
|
-
rspec-core (3.
|
101
|
-
rspec-support (~> 3.
|
102
|
-
rspec-expectations (3.
|
96
|
+
rspec (3.5.0)
|
97
|
+
rspec-core (~> 3.5.0)
|
98
|
+
rspec-expectations (~> 3.5.0)
|
99
|
+
rspec-mocks (~> 3.5.0)
|
100
|
+
rspec-core (3.5.1)
|
101
|
+
rspec-support (~> 3.5.0)
|
102
|
+
rspec-expectations (3.5.0)
|
103
103
|
diff-lcs (>= 1.2.0, < 2.0)
|
104
|
-
rspec-support (~> 3.
|
105
|
-
rspec-mocks (3.
|
104
|
+
rspec-support (~> 3.5.0)
|
105
|
+
rspec-mocks (3.5.0)
|
106
106
|
diff-lcs (>= 1.2.0, < 2.0)
|
107
|
-
rspec-support (~> 3.
|
108
|
-
rspec-support (3.
|
109
|
-
rubocop (0.
|
107
|
+
rspec-support (~> 3.5.0)
|
108
|
+
rspec-support (3.5.0)
|
109
|
+
rubocop (0.42.0)
|
110
110
|
parser (>= 2.3.1.1, < 3.0)
|
111
111
|
powerpack (~> 0.1)
|
112
112
|
rainbow (>= 1.99.1, < 3.0)
|
@@ -119,9 +119,9 @@ GEM
|
|
119
119
|
rubyzip (~> 1.0)
|
120
120
|
websocket (~> 1.0)
|
121
121
|
semver (1.0.1)
|
122
|
-
simplecov (0.
|
122
|
+
simplecov (0.12.0)
|
123
123
|
docile (~> 1.1.0)
|
124
|
-
json (
|
124
|
+
json (>= 1.8, < 3)
|
125
125
|
simplecov-html (~> 0.10.0)
|
126
126
|
simplecov-html (0.10.0)
|
127
127
|
sinatra (1.4.7)
|
@@ -141,7 +141,7 @@ GEM
|
|
141
141
|
websocket-extensions (0.1.2)
|
142
142
|
xpath (2.0.0)
|
143
143
|
nokogiri (~> 1.3)
|
144
|
-
yard (0.
|
144
|
+
yard (0.9.5)
|
145
145
|
|
146
146
|
PLATFORMS
|
147
147
|
ruby
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.6
|
data/lib/page_magic/matcher.rb
CHANGED
@@ -4,6 +4,9 @@ module PageMagic
|
|
4
4
|
class Matcher
|
5
5
|
attr_reader :path, :parameters, :fragment
|
6
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
|
7
10
|
# @raise [MatcherInvalidException] if at least one component is not specified
|
8
11
|
def initialize(path = nil, parameters: nil, fragment: nil)
|
9
12
|
raise MatcherInvalidException unless path || parameters || fragment
|
@@ -41,9 +44,10 @@ module PageMagic
|
|
41
44
|
# @param [Matcher] other
|
42
45
|
# @return [Fixnum] -1 = smaller, 0 = equal to, 1 = greater than
|
43
46
|
def <=>(other)
|
44
|
-
[:path, :parameters, :fragment].
|
45
|
-
|
47
|
+
results = [:path, :parameters, :fragment].collect do |component|
|
48
|
+
compare(send(component), other.send(component))
|
46
49
|
end
|
50
|
+
results.find { |result| !result.zero? } || 0
|
47
51
|
end
|
48
52
|
|
49
53
|
# check equality
|
data/lib/page_magic.rb
CHANGED
@@ -35,6 +35,14 @@ module PageMagic
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
# Create a more complex mapping to identify when a page should be loaded
|
39
|
+
# @example
|
40
|
+
# PageMagic.mapping '/', parameters: {project: 'page_magic'}, fragment: 'display'
|
41
|
+
# @see Matchers#initialize
|
42
|
+
def mapping(path = nil, parameters: nil, fragment: nil)
|
43
|
+
Matcher.new(path, parameters: parameters, fragment: fragment)
|
44
|
+
end
|
45
|
+
|
38
46
|
# Visit this page based on the class level registered url
|
39
47
|
# @param [Object] application rack application (optional)
|
40
48
|
# @param [Symbol] browser name of browser
|
data/page_magic.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: page_magic 1.2.
|
5
|
+
# stub: page_magic 1.2.6 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "page_magic"
|
9
|
-
s.version = "1.2.
|
9
|
+
s.version = "1.2.6"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
@@ -206,28 +206,129 @@ module PageMagic
|
|
206
206
|
end
|
207
207
|
|
208
208
|
describe '<=>' do
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
209
|
+
let(:literal_path_matcher) { '/' }
|
210
|
+
let(:fuzzy_path_matcher) { // }
|
211
|
+
let(:literal_parameter_matchers) { { param: 'value' } }
|
212
|
+
let(:fuzzy_parameter_matchers) { { param: // } }
|
213
|
+
|
214
|
+
let(:literal_fragment_matcher) { 'fragment' }
|
215
|
+
let(:fuzzy_fragment_matcher) { // }
|
216
|
+
|
217
|
+
context 'path' do
|
218
|
+
context 'path is of same class as path on other' do
|
219
|
+
subject(:a) { described_class.new('/a') }
|
220
|
+
subject(:b) { described_class.new('/b') }
|
221
|
+
it 'returns self and other as equivalent' do
|
222
|
+
expect(a <=> b).to eq(0)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
context 'path on other is fuzzy' do
|
227
|
+
subject(:a) { described_class.new(literal_path_matcher) }
|
228
|
+
subject(:b) { described_class.new(fuzzy_path_matcher) }
|
229
|
+
it 'returns other as lesser' do
|
230
|
+
expect(a <=> b).to eq(-1)
|
231
|
+
end
|
232
|
+
end
|
213
233
|
end
|
214
234
|
|
215
|
-
context '
|
216
|
-
|
217
|
-
subject
|
218
|
-
|
219
|
-
|
220
|
-
|
235
|
+
context 'parameters' do
|
236
|
+
context 'parameters on self and other contain literal values' do
|
237
|
+
subject(:a) do
|
238
|
+
described_class.new(literal_path_matcher,
|
239
|
+
parameters: literal_parameter_matchers)
|
240
|
+
end
|
241
|
+
subject(:b) do
|
242
|
+
described_class.new(literal_path_matcher,
|
243
|
+
parameters: literal_parameter_matchers)
|
244
|
+
end
|
245
|
+
it 'returns self and other as equivalent' do
|
246
|
+
expect(a <=> b).to eq(0)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context 'parameters on self literal values and other has fuzzy values' do
|
251
|
+
subject(:a) do
|
252
|
+
described_class.new(literal_path_matcher,
|
253
|
+
parameters: literal_parameter_matchers)
|
254
|
+
end
|
255
|
+
subject(:b) do
|
256
|
+
described_class.new(literal_path_matcher,
|
257
|
+
parameters: fuzzy_parameter_matchers)
|
258
|
+
end
|
259
|
+
it 'returns other as lesser' do
|
260
|
+
expect(a <=> b).to eq(-1)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
context 'parameters on self fuzzy values and other has literal values' do
|
264
|
+
subject(:a) do
|
265
|
+
described_class.new(literal_path_matcher,
|
266
|
+
parameters: fuzzy_parameter_matchers)
|
267
|
+
end
|
268
|
+
|
269
|
+
subject(:b) do
|
270
|
+
described_class.new(literal_path_matcher,
|
271
|
+
parameters: literal_parameter_matchers)
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'returns other as greater' do
|
275
|
+
expect(a <=> b).to eq(1)
|
276
|
+
end
|
221
277
|
end
|
222
278
|
end
|
223
279
|
|
224
|
-
context '
|
225
|
-
|
226
|
-
subject
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
280
|
+
context 'fragment' do
|
281
|
+
context 'fragment is of same class as path on other' do
|
282
|
+
subject(:a) do
|
283
|
+
described_class.new(literal_path_matcher,
|
284
|
+
parameters: literal_parameter_matchers,
|
285
|
+
fragment: literal_fragment_matcher)
|
286
|
+
end
|
287
|
+
|
288
|
+
subject(:b) do
|
289
|
+
described_class.new(literal_path_matcher,
|
290
|
+
parameters: literal_parameter_matchers,
|
291
|
+
fragment: literal_fragment_matcher)
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'returns self and other as equivalent' do
|
295
|
+
expect(a <=> b).to eq(0)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
context 'fragment is literal on self and fuzzy on other' do
|
300
|
+
subject(:a) do
|
301
|
+
described_class.new(literal_path_matcher,
|
302
|
+
parameters: literal_parameter_matchers,
|
303
|
+
fragment: literal_fragment_matcher)
|
304
|
+
end
|
305
|
+
|
306
|
+
subject(:b) do
|
307
|
+
described_class.new(literal_path_matcher,
|
308
|
+
parameters: literal_parameter_matchers,
|
309
|
+
fragment: fuzzy_fragment_matcher)
|
310
|
+
end
|
311
|
+
|
312
|
+
it 'returns other as lesser' do
|
313
|
+
expect(a <=> b).to eq(-1)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
context 'fragment is fuzzy on self and literal on other' do
|
318
|
+
subject(:a) do
|
319
|
+
described_class.new(literal_path_matcher,
|
320
|
+
parameters: literal_parameter_matchers,
|
321
|
+
fragment: fuzzy_fragment_matcher)
|
322
|
+
end
|
323
|
+
|
324
|
+
subject(:b) do
|
325
|
+
described_class.new(literal_path_matcher,
|
326
|
+
parameters: literal_parameter_matchers,
|
327
|
+
fragment: literal_fragment_matcher)
|
328
|
+
end
|
329
|
+
it 'returns other as lesser' do
|
330
|
+
expect(a <=> b).to eq(1)
|
331
|
+
end
|
231
332
|
end
|
232
333
|
end
|
233
334
|
end
|
data/spec/page_magic_spec.rb
CHANGED
@@ -48,6 +48,13 @@ describe PageMagic do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
describe '#mapping' do
|
52
|
+
it 'returns a matcher' do
|
53
|
+
mapping = described_class.mapping('/', parameters: {}, fragment: '')
|
54
|
+
expect(mapping).to eq(PageMagic::Matcher.new('/', parameters: {}, fragment: ''))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
51
58
|
describe '.session' do
|
52
59
|
let(:url) { 'http://url.com/' }
|
53
60
|
let(:application) { rack_application.new }
|