Module: DataMapper::Resource
- Defined in:
- lib/data_mapper/noisy_failures.rb
Constant Summary collapse
- @@original_included_method =
begin method(:included) rescue nil end
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/data_mapper/noisy_failures.rb', line 36 def self.included(base) @@original_included_method&.call(base) def base.create?(*args) create(*args) rescue nil end end |
Instance Method Details
#destroy ⇒ Object
13 14 15 16 17 18 |
# File 'lib/data_mapper/noisy_failures.rb', line 13 def destroy return true if 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 11 |
# File 'lib/data_mapper/noisy_failures.rb', line 6 def save return true if save? || errors.empty? = 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
20 21 22 23 24 25 26 27 28 |
# File 'lib/data_mapper/noisy_failures.rb', line 20 def update?(*args) update(*args) true rescue # 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 |