is_crawler 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- You can use the `is_crawler?` method with just a user agent string to determine if the that string matches *any* known crawler, like so:
21
+ You can use the `is_crawler?` method with just a user agent string to determine if it matches *any* crawler, like so:
22
22
 
23
23
  class MyController < ActionController::Base
24
24
  include IsCrawler
@@ -35,7 +35,11 @@ You can use the `is_crawler?` method with just a user agent string to determine
35
35
 
36
36
  is_crawler?("Some User Agent/1.0", :facebook, :google)
37
37
 
38
- You can also define custom crawlers like this:
38
+ ...or you can use the method sugar:
39
+
40
+ is_facebook_crawler? request.env["HTTP_USER_AGENT"]
41
+
42
+ ...and you can add to the list of detectables:
39
43
 
40
44
  Crawler::CUSTOM << Crawler.new(:custom_crawler_name, "string that is always present in the crawler's user agent")
41
45
 
@@ -1,3 +1,3 @@
1
1
  module IsCrawler
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/is_crawler.rb CHANGED
@@ -9,4 +9,10 @@ module IsCrawler
9
9
  Crawler.matches_any?(requesting_user_agent)
10
10
  end
11
11
  end
12
+
13
+ Crawler.all.each do |crawler|
14
+ define_method "is_#{crawler.name.to_s}_crawler?" do |requesting_user_agent|
15
+ is_crawler? requesting_user_agent, crawler.name
16
+ end
17
+ end
12
18
  end
@@ -36,6 +36,16 @@ describe IsCrawler do
36
36
  end
37
37
  end
38
38
  end
39
+
40
+ Crawler.all.each do |crawler|
41
+ describe '#is_{some}_crawler' do
42
+ let(:crawler) { Crawler.all.first }
43
+ subject { Test.new.send("is_#{crawler.name}_crawler?", user_agent) }
44
+ it "provides method sugar for each crawler" do
45
+ subject.should == false
46
+ end
47
+ end
48
+ end
39
49
  end
40
50
 
41
51
  class Test; include IsCrawler; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: is_crawler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-04 00:00:00.000000000 Z
12
+ date: 2013-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -77,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  segments:
79
79
  - 0
80
- hash: -1826155163722186205
80
+ hash: 1790514343912662541
81
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  none: false
83
83
  requirements:
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  segments:
88
88
  - 0
89
- hash: -1826155163722186205
89
+ hash: 1790514343912662541
90
90
  requirements: []
91
91
  rubyforge_project:
92
92
  rubygems_version: 1.8.24