Module: DataMapper::Resource
- Defined in:
- lib/data_mapper/noisy_failures.rb
Constant Summary collapse
- @@original_included_method =
self.method(:included) rescue nil
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/data_mapper/noisy_failures.rb', line 30 def self.included(base) @@original_included_method.call(base) unless @@original_included_method.nil? def base.create?(*args) self.create(*args) rescue => e nil end end |
Instance Method Details
#destroy ⇒ Object
12 13 14 15 16 |
# File 'lib/data_mapper/noisy_failures.rb', line 12 def destroy return true if self.destroy? = "#{self.class}: Unable to destroy, probably due to associated records." raise SaveFailureError.new(, self) end |
#destroy? ⇒ Object
4 |
# File 'lib/data_mapper/noisy_failures.rb', line 4 alias_method :destroy?, :destroy |
#save ⇒ Object
6 7 8 9 10 |
# File 'lib/data_mapper/noisy_failures.rb', line 6 def save return true if self.save? || self.errors.empty? = self.errors.map { |e| "#{self.class}: #{e.join(', ')}" }.join("; ") raise SaveFailureError.new(, self) end |
#save? ⇒ Object
3 |
# File 'lib/data_mapper/noisy_failures.rb', line 3 alias_method :save?, :save |
#update?(*args) ⇒ Boolean
18 19 20 21 22 23 24 25 26 |
# File 'lib/data_mapper/noisy_failures.rb', line 18 def update?(*args) self.update(*args) true rescue => e # This seems like the cleanest way of doing this. #update calls #save internally, so we can't # use alias_method because then #update? would call #save, which would raise an exception now # that we've done our monkey-patching. false end |