Permalink
Browse files

Replaced automatic before_filter with a method that can be used as or…

… in a before_filter, as desired.
  • Loading branch information...
1 parent 6c7b1d4 commit 7ce324ff5ca33092e01c090da47a32333410aaeb @arsduo committed May 10, 2011
Showing with 4 additions and 16 deletions.
  1. +4 −16 lib/mobile-fu.rb
View
@@ -34,10 +34,9 @@ module ClassMethods
# has_mobile_fu true
# end
- def has_mobile_fu(test_mode = nil, &test_mode_block)
+ def has_mobile_fu(test_mode = nil)
+ raise ArgumentError, "test_mode argument to has_mobile_fu is no longer supported, please invoke set_device_type as or in a before_filter instead" unless test_mode.nil?
include ActionController::MobileFu::InstanceMethods
- @@test_mode = test_mode || block
- before_filter :set_device_type
helper_method :is_mobile_device?
helper_method :in_mobile_view?
@@ -47,18 +46,8 @@ def has_mobile_fu(test_mode = nil, &test_mode_block)
end
module InstanceMethods
-
- def set_device_type
- # see if we want to force mobile
- force_mobile = if @@test_mode.is_a?(Proc)
- @@test_mode.call
- elsif (@@test_mode.is_a?(String) || @@test_mode.is_a?(Symbol)) && self.respond_to?(@@test_mode)
- self.send(@@test_mode)
- else
- @@test_mode
- end
-
- force_mobile ? :force_mobile_format : :set_mobile_format
+ def set_device_type(force_mobile = false)
+ force_mobile ? force_mobile_format : set_mobile_format
end
# Forces the request format to be :mobile
@@ -104,7 +93,6 @@ def is_device?(type)
request.user_agent.to_s.downcase.include? type.to_s.downcase
end
end
-
end
end

0 comments on commit 7ce324f

Please sign in to comment.