Module: MethodWithSave

Defined in:
lib/method_with_save.rb,
lib/method_with_save/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/method_with_save.rb', line 4

def method_missing(method_name, *args)
  if /^(.+)_with_save(\!?)$/.match(method_name)
    if defined? $1
      send($1,*args)
      if $2.blank?
        return self.save
      else
        return self.save!
      end
    end
  end

  if /^(.+)_with_save_without_validate(\!?)$/.match(method_name)
    if defined? $1
      send($1,*args)
      if $2.blank?
        return self.save(:validate=>false)
      else
        return self.save!(:validate=>false)
      end
    end
  end
  super
end