~ubuntu-branches/ubuntu/vivid/ruby-sequel/vivid

« back to all changes in this revision

Viewing changes to lib/sequel/model/exceptions.rb

  • Committer: Package Import Robot
  • Author(s): Dmitry Borodaenko, Dmitry Borodaenko, Cédric Boutillier
  • Date: 2013-08-10 18:38:17 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20130810183817-iqanz804j32i5myi
Tags: 4.1.1-1
[ Dmitry Borodaenko ]
* New upstream release.
* Standards-Version upgraded to 3.9.4 (no changes).
* Added Build-Depend on ruby-sqlite3.

[ Cédric Boutillier ]
* debian/control: remove obsolete DM-Upload-Allowed flag.
* use canonical URI in Vcs-* fields.
* debian/copyright: use DEP5 copyright-format/1.0 official URL for Format
  field.
* Update debian/watch. Thanks Bart Martens.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
module Sequel
2
2
  # Exception class raised when +raise_on_save_failure+ is set and a before hook returns false
3
3
  # or an around hook doesn't call super or yield.
4
 
  class HookFailed < Error; end
 
4
  class HookFailed < Error
 
5
    # The Sequel::Model instance related to this error.
 
6
    attr_reader :model
 
7
 
 
8
    def initialize(message, model=nil)
 
9
      @model = model
 
10
      super(message)
 
11
    end
 
12
  end
5
13
 
6
14
  # Deprecated alias for HookFailed, kept for backwards compatibility
7
15
  BeforeHookFailed = HookFailed
15
23
  
16
24
  # Exception class raised when +raise_on_save_failure+ is set and validation fails
17
25
  class ValidationFailed < Error
 
26
    # The Sequel::Model object related to this exception.
 
27
    attr_reader :model
 
28
 
 
29
    # The Sequel::Model::Errors object related to this exception.
 
30
    attr_reader :errors
 
31
 
18
32
    def initialize(errors)
 
33
      if errors.is_a?(Sequel::Model)
 
34
        @model = errors
 
35
        errors = @model.errors
 
36
      end
 
37
 
19
38
      if errors.respond_to?(:full_messages)
20
39
        @errors = errors
21
40
        super(errors.full_messages.join(', '))
23
42
        super
24
43
      end
25
44
    end
26
 
    attr_reader :errors
27
45
  end
28
46
end