Module: Hovercraft::Helpers
- Defined in:
- lib/hovercraft/helpers.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate_with_warden ⇒ Object
- #default_format ⇒ Object
- #format ⇒ Object
- #format_method_name ⇒ Object
- #preferred_type ⇒ Object
- #respond_with(content) ⇒ Object
- #warden ⇒ Object
Class Method Details
.registered(application) ⇒ Object
3 4 5 |
# File 'lib/hovercraft/helpers.rb', line 3 def self.registered(application) application.helpers(Hovercraft::Helpers) end |
Instance Method Details
#authenticate_with_warden ⇒ Object
7 8 9 |
# File 'lib/hovercraft/helpers.rb', line 7 def authenticate_with_warden warden.authenticate! if warden end |
#default_format ⇒ Object
42 43 44 |
# File 'lib/hovercraft/helpers.rb', line 42 def default_format :json end |
#format ⇒ Object
27 28 29 30 31 |
# File 'lib/hovercraft/helpers.rb', line 27 def format params[:format] || preferred_type || default_format end |
#format_method_name ⇒ Object
23 24 25 |
# File 'lib/hovercraft/helpers.rb', line 23 def format_method_name "to_#{format}" end |
#preferred_type ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/hovercraft/helpers.rb', line 33 def preferred_type case request.preferred_type when /.*\/json/ then :json when /.*\/xml/ then :xml when /.*\/\*/ then default_format else fail "Unknown media type: %p" % request.preferred_type end end |
#respond_with(content) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/hovercraft/helpers.rb', line 15 def respond_with(content) if content.respond_to?(format_method_name) content.send(format_method_name) else fail "Serialization method not supported: #{format_method_name}" end end |
#warden ⇒ Object
11 12 13 |
# File 'lib/hovercraft/helpers.rb', line 11 def warden env.fetch('warden') end |