Skip to content
Browse files

cleanup up impl

git-svn-id: https://svn.thoughtbot.com/plugins/what@357 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information...
1 parent 587c0eb commit 94c9e4933ac7cf5f1732af95bf9cabea0f4b97c4 jcarroll committed Feb 19, 2008
Showing with 23 additions and 18 deletions.
  1. +3 −2 init.rb
  2. +13 −12 lib/what.rb
  3. +5 −2 test/fixtures/what_controller.rb
  4. +2 −2 test/what_test.rb
View
5 init.rb
@@ -1,2 +1,3 @@
-require File.dirname(__FILE__) + '/lib/what.rb'
-ActionController::Base.send :include, What::ActionControllerHook
+require File.join(File.dirname(__FILE__), 'lib', 'what.rb')
+
+ActionController::Base.send :include, What
View
25 lib/what.rb
@@ -1,18 +1,19 @@
module What
- module ActionControllerHook
-
- # Mime::Type.register 'image/gif', :gif
- # Mime::Type.register 'text/iphone', :iphone
- # Mime::Type.register 'text/x-mobile', :mobile
- # Mime::Type.register 'application/pdf', :pdf
- # Mime::Type.register 'image/png', :png
-
- Mime::SET.each do |mime_type|
- define_method "#{mime_type.to_sym}?" do
- request.format == mime_type
+ # Mime::Type.register 'image/gif', :gif
+ # Mime::Type.register 'text/iphone', :iphone
+ # Mime::Type.register 'text/x-mobile', :mobile
+ # Mime::Type.register 'application/pdf', :pdf
+ # Mime::Type.register 'image/png', :png
+
+ def self.included(clazz)
+ clazz.class_eval do
+ Mime::SET.each do |mime_type|
+ define_method "#{mime_type.to_sym}?" do
+ request.format == mime_type
+ end
end
end
-
end
+
end
View
7 test/fixtures/what_controller.rb
@@ -1,8 +1,11 @@
class WhatController < ActionController::Base
def index
- redirect_to :action => :new and return if csv?
- render :text => 'The what#index HTML formatted view.'
+ if csv?
+ redirect_to :action => :new
+ else
+ render :text => 'The what#index HTML formatted view.'
+ end
end
def new
View
4 test/what_test.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/test_helper'
-require File.dirname(__FILE__) + '/fixtures/what_controller'
+require File.join(File.dirname(__FILE__), 'test_helper')
+require File.join(File.dirname(__FILE__), 'fixtures', 'what_controller')
class WhatControllerTest < Test::Unit::TestCase

0 comments on commit 94c9e49

Please sign in to comment.
Something went wrong with that request. Please try again.