dm-validations 0.9.6 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Manifest.txt CHANGED
@@ -14,6 +14,7 @@ lib/dm-validations/contextual_validators.rb
14
14
  lib/dm-validations/custom_validator.rb
15
15
  lib/dm-validations/format_validator.rb
16
16
  lib/dm-validations/formats/email.rb
17
+ lib/dm-validations/formats/url.rb
17
18
  lib/dm-validations/generic_validator.rb
18
19
  lib/dm-validations/length_validator.rb
19
20
  lib/dm-validations/method_validator.rb
@@ -25,8 +26,6 @@ lib/dm-validations/uniqueness_validator.rb
25
26
  lib/dm-validations/validation_errors.rb
26
27
  lib/dm-validations/version.rb
27
28
  lib/dm-validations/within_validator.rb
28
- lib/dm-validations/formats/url.rb
29
- lib/dm-validations/formats/email.rb
30
29
  spec/integration/absent_field_validator_spec.rb
31
30
  spec/integration/acceptance_validator_spec.rb
32
31
  spec/integration/auto_validate_spec.rb
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'pathname'
3
3
 
4
- gem 'dm-core', '=0.9.6'
4
+ gem 'dm-core', '~>0.9.7'
5
5
  require 'dm-core'
6
6
 
7
7
  dir = Pathname(__FILE__).dirname.expand_path / 'dm-validations'
@@ -32,16 +32,15 @@ module DataMapper
32
32
 
33
33
  def self.included(model)
34
34
  model.class_eval <<-EOS, __FILE__, __LINE__
35
- if method_defined?(:save) && !method_defined?(:save!)
36
- alias save! save
37
- alias save save_with_validations
35
+ if method_defined?(:save)
36
+ before :save, :check_validations
38
37
  end
39
38
 
40
39
  class << self
41
40
  def create(attributes = {}, context = :default)
42
41
  resource = new(attributes)
43
42
  return resource unless resource.valid?(context)
44
- resource.save
43
+ resource.save!
45
44
  resource
46
45
  end
47
46
 
@@ -54,12 +53,17 @@ module DataMapper
54
53
  EOS
55
54
  end
56
55
 
57
- # Validate the resource before saving. Use #save! to save
58
- # the record without validations.
56
+ # Ensures the object is valid for the context provided, and otherwise
57
+ # throws :halt and returns false.
58
+ #
59
+ def check_validations(context = :default)
60
+ throw(:halt, false) unless context.nil? || valid?(context)
61
+ end
62
+
63
+ # Calls save with a context of nil, thus skipping validations.
59
64
  #
60
- def save_with_validations(context = :default)
61
- return false unless valid?(context)
62
- save!
65
+ def save!
66
+ save(nil)
63
67
  end
64
68
 
65
69
  # Return the ValidationErrors
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  module Validations
3
- VERSION = "0.9.6"
3
+ VERSION = "0.9.7"
4
4
  end
5
5
  end
@@ -20,9 +20,7 @@ describe DataMapper::Validate::ContextualValidators do
20
20
  end
21
21
 
22
22
  it "should raise an exception if you provide an invalid context to save" do
23
-
24
23
  lambda { Kayak.new.save(:invalid_context) }.should raise_error
25
- lambda { Kayak.new.save(nil) }.should raise_error
26
24
  lambda { Kayak.new.save(false) }.should raise_error
27
25
  end
28
26
  end
data/spec/spec_helper.rb CHANGED
@@ -9,7 +9,7 @@ def load_driver(name, default_uri)
9
9
  lib = "do_#{name}"
10
10
 
11
11
  begin
12
- gem lib, '>=0.9.5'
12
+ gem lib, '~>0.9.7'
13
13
  require lib
14
14
  DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
15
15
  DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guy van den Berg
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-12 00:00:00 -06:00
12
+ date: 2008-11-18 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.9.6
23
+ version: 0.9.7
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.7.0
33
+ version: 1.8.2
34
34
  version:
35
35
  description: DataMapper plugin for performing validations on data models
36
36
  email:
@@ -60,6 +60,7 @@ files:
60
60
  - lib/dm-validations/custom_validator.rb
61
61
  - lib/dm-validations/format_validator.rb
62
62
  - lib/dm-validations/formats/email.rb
63
+ - lib/dm-validations/formats/url.rb
63
64
  - lib/dm-validations/generic_validator.rb
64
65
  - lib/dm-validations/length_validator.rb
65
66
  - lib/dm-validations/method_validator.rb
@@ -71,7 +72,6 @@ files:
71
72
  - lib/dm-validations/validation_errors.rb
72
73
  - lib/dm-validations/version.rb
73
74
  - lib/dm-validations/within_validator.rb
74
- - lib/dm-validations/formats/url.rb
75
75
  - spec/integration/absent_field_validator_spec.rb
76
76
  - spec/integration/acceptance_validator_spec.rb
77
77
  - spec/integration/auto_validate_spec.rb
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  requirements: []
116
116
 
117
117
  rubyforge_project: datamapper
118
- rubygems_version: 1.2.0
118
+ rubygems_version: 1.3.1
119
119
  signing_key:
120
120
  specification_version: 2
121
121
  summary: DataMapper plugin for performing validations on data models