Created
August 21, 2008 08:09
-
-
Save koshigoe/6520 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/jpmobile.rb b/lib/jpmobile.rb | |
index af7ac4c..d18ca28 100644 | |
--- a/lib/jpmobile.rb | |
+++ b/lib/jpmobile.rb | |
@@ -20,8 +20,32 @@ module Jpmobile | |
autoload :Livedoor, 'jpmobile/mobile/livedoor' | |
autoload :Goo, 'jpmobile/mobile/goo' | |
- def self.constants_with_discovery_order | |
- [ :Google, :Yahoo, :Livedoor, :Goo, :Docomo, :Au, :Softbank, :Vodafone, :Jphone, :Emobile, :Willcom, :Ddipocket ] | |
+ def self.include_crawler= value | |
+ @@include_crawler = value | |
+ end | |
+ | |
+ def self.include_crawler | |
+ @@include_crawler ||= false | |
+ end | |
+ | |
+ def self.crawlers | |
+ [ :Google, :Yahoo, :Livedoor, :Goo ] | |
+ end | |
+ | |
+ def self.careers_without_crawler | |
+ constants - crawlers | |
+ end | |
+ | |
+ def self.careers_with_crawler | |
+ crawlers + careers_without_crawler | |
+ end | |
+ | |
+ def self.careers | |
+ @careers ||= include_crawler ? careers_with_crawler : careers_without_crawler | |
+ end | |
+ | |
+ def self.careers= ary | |
+ @careers = ary | |
end | |
end | |
end | |
diff --git a/lib/jpmobile/request_with_mobile.rb b/lib/jpmobile/request_with_mobile.rb | |
index 15dcf39..46f119b 100644 | |
--- a/lib/jpmobile/request_with_mobile.rb | |
+++ b/lib/jpmobile/request_with_mobile.rb | |
@@ -33,7 +33,7 @@ module Jpmobile | |
def mobile | |
return @__mobile if @__mobile | |
- Jpmobile::Mobile.constants_with_discovery_order.each do |const| | |
+ Jpmobile::Mobile.careers.each do |const| | |
c = Jpmobile::Mobile.const_get(const) | |
return @__mobile = c.new(self) if c::USER_AGENT_REGEXP && user_agent =~ c::USER_AGENT_REGEXP | |
end | |
diff --git a/spec/controllers/goo_spec.rb b/spec/controllers/goo_spec.rb | |
index 731e531..9d7941f 100644 | |
--- a/spec/controllers/goo_spec.rb | |
+++ b/spec/controllers/goo_spec.rb | |
@@ -2,8 +2,12 @@ require File.dirname(__FILE__) + '/../spec_helper' | |
describe "モバイルgoo 携帯検索クローラ からのアクセス" do | |
before do | |
+ Jpmobile::Mobile.include_crawler = true | |
request.user_agent = "DoCoMo/2.0 P900i(c100;TB;W24H11)(compatible; ichiro/mobile goo; +http://help.goo.ne.jp/door/crawler.html)" | |
end | |
+ after do | |
+ Jpmobile::Mobile.include_crawler = false | |
+ end | |
controller_name :mobile_spec | |
it "request.mobile は Goo のインスタンスであるべき" do | |
request.mobile.should be_an_instance_of(Jpmobile::Mobile::Goo) | |
diff --git a/spec/controllers/google_spec.rb b/spec/controllers/google_spec.rb | |
index 51b69ec..900ed8b 100644 | |
--- a/spec/controllers/google_spec.rb | |
+++ b/spec/controllers/google_spec.rb | |
@@ -2,8 +2,12 @@ require File.dirname(__FILE__) + '/../spec_helper' | |
describe "Google モバイルウェブクローラー からのアクセス" do | |
before do | |
+ Jpmobile::Mobile.include_crawler = true | |
request.user_agent = "DoCoMo/1.0/N505i/c20/TB/W20H10 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)" | |
end | |
+ after do | |
+ Jpmobile::Mobile.include_crawler = false | |
+ end | |
controller_name :mobile_spec | |
it "request.mobile は Google のインスタンスであるべき" do | |
request.mobile.should be_an_instance_of(Jpmobile::Mobile::Google) | |
diff --git a/spec/controllers/livedoor_spec.rb b/spec/controllers/livedoor_spec.rb | |
index 52955ab..6100f1e 100644 | |
--- a/spec/controllers/livedoor_spec.rb | |
+++ b/spec/controllers/livedoor_spec.rb | |
@@ -2,8 +2,12 @@ require File.dirname(__FILE__) + '/../spec_helper' | |
describe "Livedoor モバイルサイト検索用のクローラー からのアクセス" do | |
before do | |
+ Jpmobile::Mobile.include_crawler = true | |
request.user_agent = "DoCoMo/1.0/N505i/c20/TB/W20H10 (compatible; LD_mobile_bot; +http://helpguide.livedoor.com/help/search/qa/grp627)" | |
end | |
+ after do | |
+ Jpmobile::Mobile.include_crawler = false | |
+ end | |
controller_name :mobile_spec | |
it "request.mobile は Livedoor のインスタンスであるべき" do | |
request.mobile.should be_an_instance_of(Jpmobile::Mobile::Livedoor) | |
diff --git a/spec/controllers/yahoo_spec.rb b/spec/controllers/yahoo_spec.rb | |
index 2344d81..bdc3e4f 100644 | |
--- a/spec/controllers/yahoo_spec.rb | |
+++ b/spec/controllers/yahoo_spec.rb | |
@@ -1,6 +1,12 @@ | |
require File.dirname(__FILE__) + '/../spec_helper' | |
describe "モバイル版Yahoo!検索の検索エンジン用ロボット からのアクセス" do | |
+ before do | |
+ Jpmobile::Mobile.include_crawler = true | |
+ end | |
+ after do | |
+ Jpmobile::Mobile.include_crawler = false | |
+ end | |
controller_name :mobile_spec | |
it "request.mobile は Yahoo のインスタンスであるべき" do | |
%w(Y!J-SRD/1.0 Y!J-MBS/1.0).each do |user_agent| |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment