morito 0.0.2 → 0.0.3
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/README.md +2 -1
- data/lib/morito/client.rb +9 -1
- data/lib/morito/processor.rb +5 -1
- data/lib/morito/version.rb +1 -1
- data/spec/morito/client_spec.rb +15 -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: 1c55decebb4c9e07810ea06f3f21d8f40088faa5
|
4
|
+
data.tar.gz: 1268725db5c75afe009299dbd5f3c29e3780ba80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f36208dbab6355df0c691c3f4cef8783abbf10ae211c7b8440df5bd951380d4db4c0f452391f95e3b7a8e9b54c93f1a5aedea890edcaf495784ef2a1e0c120ee
|
7
|
+
data.tar.gz: 58dae02a4a09fa4529f6889a8da4597431a857285938c03e887813797347069ac34995dbde8ca756eec89537e4026c26f5929c4570bbc289fe27d55fa60af63c
|
data/README.md
CHANGED
data/lib/morito/client.rb
CHANGED
@@ -9,11 +9,19 @@ module Morito
|
|
9
9
|
def allowed?(requesting_url, cache: true)
|
10
10
|
uri = URI.parse(requesting_url)
|
11
11
|
robots_txt_body = robots_txt_body(uri, cache: cache)
|
12
|
-
Morito::Processor.new(robots_txt_body).allowed?(@user_agent, uri
|
12
|
+
Morito::Processor.new(robots_txt_body).allowed?(@user_agent, path(uri))
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
+
def path(uri)
|
18
|
+
if uri.query
|
19
|
+
"#{uri.path}?#{uri.query}"
|
20
|
+
else
|
21
|
+
uri.path
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
17
25
|
def robots_txt_body(uri, cache: true)
|
18
26
|
if cache
|
19
27
|
with_cache(uri.host) do
|
data/lib/morito/processor.rb
CHANGED
@@ -41,7 +41,7 @@ module Morito
|
|
41
41
|
end
|
42
42
|
|
43
43
|
class LineParser
|
44
|
-
attr_reader :user_agent
|
44
|
+
attr_reader :user_agent
|
45
45
|
|
46
46
|
def parse(line)
|
47
47
|
case line
|
@@ -55,6 +55,10 @@ module Morito
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
def disallow
|
59
|
+
Regexp.escape(@disallow).gsub('\*', '.*').gsub('\$', '$')
|
60
|
+
end
|
61
|
+
|
58
62
|
def disallow?
|
59
63
|
@user_agent && @disallow
|
60
64
|
end
|
data/lib/morito/version.rb
CHANGED
data/spec/morito/client_spec.rb
CHANGED
@@ -13,6 +13,7 @@ describe Morito::Client do
|
|
13
13
|
<<-EOS
|
14
14
|
User-agent: *
|
15
15
|
Disallow: /private
|
16
|
+
Disallow: /*?$
|
16
17
|
|
17
18
|
# Comment
|
18
19
|
User-agent: restricted agent # Comment
|
@@ -65,6 +66,20 @@ EOS
|
|
65
66
|
it { should == true }
|
66
67
|
end
|
67
68
|
end
|
69
|
+
|
70
|
+
context 'with patternized path' do
|
71
|
+
let(:user_agent) { 'some agent' }
|
72
|
+
|
73
|
+
context 'for eol' do
|
74
|
+
let(:requesting_url) { 'http://example.com/some/path?' }
|
75
|
+
it { should == false }
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'for no eol' do
|
79
|
+
let(:requesting_url) { 'http://example.com/some/path?param=1' }
|
80
|
+
it { should == true }
|
81
|
+
end
|
82
|
+
end
|
68
83
|
end
|
69
84
|
|
70
85
|
context 'with 404' do
|