sequel_validation_exceptions 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/validation_exceptions.rb +41 -0
  2. metadata +64 -0
@@ -0,0 +1,41 @@
1
+ module Sequel
2
+ class ValidationException < RuntimeError
3
+ attr_reader :validation_errors
4
+
5
+ def initialize validation_errors
6
+ @validation_errors = validation_errors
7
+ end
8
+ end
9
+
10
+ module Plugins
11
+ module ValidationExceptions
12
+ module ClassMethods
13
+ def create! attributes={}
14
+ instance = self.new attributes
15
+ instance.save!
16
+ instance
17
+ end
18
+
19
+ def find_or_create! cond, &block
20
+ find(cond) || create!(cond, &block)
21
+ end
22
+ end
23
+
24
+ module InstanceMethods
25
+ def save! *columns
26
+ success = save *columns
27
+ if !success
28
+ raise ValidationException.new(errors), "Could not save #{id.nil? ? 'new' : ''} #{self.class.name} model #{id} due to failing validation: #{errors.inspect}\nmodel was: #{inspect}"
29
+ end
30
+ end
31
+
32
+ def update! *columns
33
+ success = update *columns
34
+ if !success
35
+ raise ValidationException.new(errors), "Could not update #{id.nil? ? 'new' : ''} #{self.class.name} model #{id} due to failing validation: #{errors.inspect}\nmodel was: #{inspect}"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel_validation_exceptions
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Misha Conway
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-08-30 00:00:00 Z
18
+ dependencies: []
19
+
20
+ description:
21
+ email: MishaAConway@gmail.com
22
+ executables: []
23
+
24
+ extensions: []
25
+
26
+ extra_rdoc_files: []
27
+
28
+ files:
29
+ - lib/validation_exceptions.rb
30
+ homepage:
31
+ licenses: []
32
+
33
+ post_install_message:
34
+ rdoc_options: []
35
+
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ requirements: []
57
+
58
+ rubyforge_project: nowarning
59
+ rubygems_version: 1.8.8
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Adds save!, update!, create!, and find_or_create! to sequel models.
63
+ test_files: []
64
+