Class: Var

Inherits:
Application show all
Defined in:
app/controllers/var.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/var.rb', line 2

def index
  only_provides :json, :text, :pp

  filter = Hash.new
  params.each do |key, value|
    # skip parameters from merb itself
    next if ["action", "controller", "format", "id"].include?(key)
    next if value == nil

    # If it looks like a regex, treat it like one.
    # That is, if the value is /something/ (begin and end with slash)
    if value =~ /^\/.+\/$/
      filter[key] = Regexp.new(value[1..-2]) rescue value
    else
      # otherwise, treat it like a literal string to full match.
      filter[key] = Regexp.new("^#{Regexp.escape(value)}$")
    end
  end

  # ensure filter isn't changed
  filter.freeze

  @attributes = SlashPort::Component.get_attributes(filter)
  display @attributes
end