Sha256: 8bfc6ed839139ae855461f3efb17ac4d89f459ec914506afce4264f578b4b5f7

Contents?: true

Size: 1.23 KB

Versions: 22

Compression:

Stored size: 1.23 KB

Contents

module Bizside
  class UserAgent
    module ControllerHelper
      extend ActiveSupport::Concern

      included do
        case Rails::VERSION::MAJOR
        when 3
          before_filter :detect_user_agent
        when 4
          before_action :detect_user_agent
        when 5
          before_action :detect_user_agent
        else
          raise "Rails-#{Rails::VERSION::MAJOR} は未対応です。"
        end

        ::ActionController::Base.helper_method :user_agent
      end

      protected

      def detect_user_agent
        if params[:ua].present?
          self.user_agent = ::Bizside::UserAgent.new(params[:ua], request.env['HTTP_USER_AGENT'])
        else
          self.user_agent = ::Bizside::UserAgent.parse(request.env['HTTP_USER_AGENT'])
        end

        set_request_variant if Bizside.config.user_agent.use_variant?

        request.env['BIZSIDE_DEVICE'] = self.user_agent.name
      end

      def set_request_variant
        if self.user_agent.present? && self.user_agent.priorities.present?
          request.variant = self.user_agent.priorities.map(&:to_sym)
        end
      end

      def user_agent
        @_user_agent
      end

      def user_agent=(value)
        @_user_agent = value
      end

    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
bizside-2.1.12 lib/bizside/user_agent/controller_helper.rb
bizside-2.1.11 lib/bizside/user_agent/controller_helper.rb
bizside-2.1.10 lib/bizside/user_agent/controller_helper.rb
bizside-2.1.9 lib/bizside/user_agent/controller_helper.rb
bizside-2.1.8 lib/bizside/user_agent/controller_helper.rb
bizside-2.1.7 lib/bizside/user_agent/controller_helper.rb
bizside-2.1.6 lib/bizside/user_agent/controller_helper.rb
bizside-2.1.5 lib/bizside/user_agent/controller_helper.rb
bizside-2.1.4 lib/bizside/user_agent/controller_helper.rb
bizside-2.1.3 lib/bizside/user_agent/controller_helper.rb
bizside-2.1.2 lib/bizside/user_agent/controller_helper.rb
bizside-2.1.1 lib/bizside/user_agent/controller_helper.rb
bizside-2.1.0 lib/bizside/user_agent/controller_helper.rb
bizside-2.0.9 lib/bizside/user_agent/controller_helper.rb
bizside-2.0.8 lib/bizside/user_agent/controller_helper.rb
bizside-2.0.7 lib/bizside/user_agent/controller_helper.rb
bizside-2.0.6 lib/bizside/user_agent/controller_helper.rb
bizside-2.0.5 lib/bizside/user_agent/controller_helper.rb
bizside-2.0.4 lib/bizside/user_agent/controller_helper.rb
bizside-2.0.3 lib/bizside/user_agent/controller_helper.rb