Sha256: f7311f13ed005d5174fb9fbf27f7d91bb56285ac5bd4f8a7252b43747b3d8d85

Contents?: true

Size: 1.01 KB

Versions: 9

Compression:

Stored size: 1.01 KB

Contents

# DoCoMoの時guid=onの付与
class ActionController::Base #:nodoc:
  class_attribute :docomo_guid_mode

  class << self
    def docomo_guid(mode = :docomo)
      include Jpmobile::DocomoGuid
      self.docomo_guid_mode = mode
    end
  end
end

module Jpmobile::DocomoGuid #:nodoc:
  protected

  def default_url_options
    result = super || {}
    return result unless request # for test process
    return result unless apply_add_guid?

    result.merge({ guid: 'ON' })
  end

  # guid=ONを付与すべきか否かを返す
  def apply_add_guid?
    return true if docomo_guid_mode == :always
    return false if docomo_guid_mode == :none

    return false unless request.mobile?
    return false unless request.mobile.is_a?(Jpmobile::Mobile::Docomo)
    return false if not_apply_guid_user_agent?

    if docomo_guid_mode == :valid_ip
      return false unless request.mobile.valid_ip?
    end

    true
  end

  def not_apply_guid_user_agent?
    request.user_agent.match(%r{(?:Googlebot|Y!J-SRD/1\.0|Y!J-MBS/1\.0)})
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
jpmobile-6.1.0 lib/jpmobile/docomo_guid.rb
jpmobile-6.0.0 lib/jpmobile/docomo_guid.rb
jpmobile-5.2.5 lib/jpmobile/docomo_guid.rb
jpmobile-6.0.0.beta lib/jpmobile/docomo_guid.rb
jpmobile-5.2.4 lib/jpmobile/docomo_guid.rb
jpmobile-5.2.3 lib/jpmobile/docomo_guid.rb
jpmobile-5.2.2 lib/jpmobile/docomo_guid.rb
jpmobile-5.2.1 lib/jpmobile/docomo_guid.rb
jpmobile-5.2.0 lib/jpmobile/docomo_guid.rb