1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/models/eye.rb
David Chelimsky 1f06652a57 use persisted? instead of new_record? wherever possible
- persisted? is the API defined in ActiveModel
- makes it easier for extension libraries to conform to ActiveModel APIs
  without concern for whether the extended object is specifically
  ActiveRecord

[#5927 state:committed]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2010-11-09 13:54:04 -02:00

37 lines
1,015 B
Ruby

class Eye < ActiveRecord::Base
attr_reader :after_create_callbacks_stack
attr_reader :after_update_callbacks_stack
attr_reader :after_save_callbacks_stack
# Callbacks configured before the ones has_one sets up.
after_create :trace_after_create
after_update :trace_after_update
after_save :trace_after_save
has_one :iris
accepts_nested_attributes_for :iris
# Callbacks configured after the ones has_one sets up.
after_create :trace_after_create2
after_update :trace_after_update2
after_save :trace_after_save2
def trace_after_create
(@after_create_callbacks_stack ||= []) << !iris.persisted?
end
alias trace_after_create2 trace_after_create
def trace_after_update
(@after_update_callbacks_stack ||= []) << iris.changed?
end
alias trace_after_update2 trace_after_update
def trace_after_save
(@after_save_callbacks_stack ||= []) << iris.changed?
end
alias trace_after_save2 trace_after_save
end
class Iris < ActiveRecord::Base
belongs_to :eye
end