Module: Sinatra::Thumbnails::Settings

Defined in:
lib/sinatra/thumbnails.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sinatra/thumbnails.rb', line 6

def method_missing(name, *args)
  if (name.to_s =~ /=$/)
    key = name.to_s[0..-2].to_sym
    raise NoMethodError unless self[key]
    raise ArgumentError if args.length != 1
    Thumbnails::Settings.send(:define_method, name) do |val|
      self[key] = val
    end
    self.send(args[0])
  elsif args.length == 0
    raise NoMethodError unless self[name]
    Thumbnails::Settings.send(:define_method, name) do
      self[name]
    end
    self.send(name)
  else
    raise ArgumentError
  end
end