morito 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50f1f0b304f54a4d042d91ab748679af6aa8064d
4
- data.tar.gz: ada9db82752169ccfd43f7337bb97ec51d36827a
3
+ metadata.gz: 1c55decebb4c9e07810ea06f3f21d8f40088faa5
4
+ data.tar.gz: 1268725db5c75afe009299dbd5f3c29e3780ba80
5
5
  SHA512:
6
- metadata.gz: 7d864fa9b215e1b7b076b4fdba050e993ef52a402e4792dd8c882cc9f057eeb73c888eaeab624731393a2675b421801ffe7a32811719a1539f74f5d09ffcbdd3
7
- data.tar.gz: 50a9ed68a538e2f8b15caa8b26221a770a5507abc51e310d0453223eb1b313e217f6954d4c4cf432eb8c0a5c6e6f3bfd4cdcce4d93e27a9562a796088cfb83a4
6
+ metadata.gz: f36208dbab6355df0c691c3f4cef8783abbf10ae211c7b8440df5bd951380d4db4c0f452391f95e3b7a8e9b54c93f1a5aedea890edcaf495784ef2a1e0c120ee
7
+ data.tar.gz: 58dae02a4a09fa4529f6889a8da4597431a857285938c03e887813797347069ac34995dbde8ca756eec89537e4026c26f5929c4570bbc289fe27d55fa60af63c
data/README.md CHANGED
@@ -26,7 +26,8 @@ client.allowed?('http://example.com/some/path', cache: false) # => true / false
26
26
 
27
27
  ## TODO
28
28
 
29
- - Currently does not handle `Allow:` description.
29
+ - Handle `Allow:` description.
30
+ - Pattern matching like `Disallow: /*?`
30
31
 
31
32
  ## Contributing
32
33
 
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.path)
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
@@ -41,7 +41,7 @@ module Morito
41
41
  end
42
42
 
43
43
  class LineParser
44
- attr_reader :user_agent, :disallow
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
@@ -1,3 +1,3 @@
1
1
  module Morito
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morito
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - negipo