Class: Camping::H

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/camping-unabridged.rb,
lib/camping.rb

Overview

An object-like Hash, based on ActiveSupport’s HashWithIndifferentAccess. All Camping query string and cookie variables are loaded as this.

To access the query string, for instance, use the @input variable.

module Blog::Models
  class Index < R '/'
    def get
      if page = @input.page.to_i > 0
        page -= 1
      end
      @posts = Post.find :all, :offset => page * 20, :limit => 20
      render :index
    end
  end
end

In the above example if you visit /?page=2, you’ll get the second page of twenty posts. You can also use @input[:page] or @input['page'] to get the value for the page query variable.

Use the @cookies variable in the same fashion to access cookie variables.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *a) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/camping-unabridged.rb', line 116

def method_missing(m,*a)
    if m.to_s =~ /=$/
        self[$`] = a[0]
    elsif a.empty?
        self[m]
    else
        raise NoMethodError, "#{m}"
    end
end