Module: Returning::ActiveRecord::Returning

Defined in:
lib/returning/active_record/returning.rb

Instance Method Summary collapse

Instance Method Details

#create_or_updateObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/returning/active_record/returning.rb', line 19

def create_or_update
  if @_returning
    raise ReadOnlyRecord if readonly?
    if new_record?
      create
      self
    elsif r = update
      r = self.class.send(:instantiate, r[0])
      r.readonly!
      r
    else
      false
    end
  else
    super
  end
end

#destroy(options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/returning/active_record/returning.rb', line 37

def destroy(options = {})
  if r = options[:returning]
    begin
      old_returning, @_returning = @_returning, r
      if r = super()
        r = self.class.send(:instantiate, r[0])
        r.readonly!
      end

      r
    ensure
      @_returning = old_returning
    end
  else
    super()
  end
end

#save(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/returning/active_record/returning.rb', line 6

def save(options = {})
  if r = options[:returning]
    begin
      old_returning, @_returning = @_returning, r
      super
    ensure
      @_returning = old_returning
    end
  else
    super
  end
end