ohm-validations 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29390f46741b4fc83c1f95ac1ca33ad6b1b09e90
4
+ data.tar.gz: c177830ca00d41b14de8cd001f8c871be2f90061
5
+ SHA512:
6
+ metadata.gz: cfbecaf70848d8c13e41e41e32fbfb66e88335e4af50df1596e42706cb4198a1fcf19fe1b3001ef4210778413c3955dd31dae2ec090865e40463ab4083f0f981
7
+ data.tar.gz: 91e23aa0fe0ad9e3986064c4dbbebf1206f929590ec71ab165ceb5452f8acee3a79d162a62cc5bb8111320ec7dc93ebe619a17cd6750e5ed6ed8c9e67ab6d5b1
data/.gems ADDED
@@ -0,0 +1,3 @@
1
+ ohm -v 2.0.0.rc1
2
+ scrivener -v 0.2.0
3
+ cutest -v 1.2.1
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Francesco Rodriguez
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,54 @@
1
+ ohm-validations
2
+ ===============
3
+
4
+ Validations for Ohm::Model.
5
+
6
+ Usage
7
+ -----
8
+
9
+ ```
10
+ class User < Ohm::Model
11
+ include Ohm::Validations
12
+
13
+ attribute :name
14
+ attribute :email
15
+
16
+ attr :before, :after
17
+
18
+ protected
19
+
20
+ def validate
21
+ assert_present(:name)
22
+ assert_email(:email)
23
+ end
24
+
25
+ def before_validation
26
+ @before = true
27
+ end
28
+
29
+ def after_validation
30
+ @after = true
31
+ end
32
+ end
33
+
34
+ user = User.new({})
35
+ user.valid? # => false
36
+
37
+ user.update_attributes(name: "jhon", email: "jhon@doe.com")
38
+ user.valid? # => true
39
+
40
+ user.before # => true
41
+ user.after # => true
42
+ ```
43
+
44
+ Check [scrivener][scrivener] project for more information
45
+ about the available validations.
46
+
47
+ Installation
48
+ ------------
49
+
50
+ ```
51
+ $ gem install ohm-validations
52
+ ```
53
+
54
+ [scrivener]: https://github.com/soveran/scrivener
@@ -0,0 +1,29 @@
1
+ require "scrivener/validations"
2
+
3
+ module Ohm
4
+ module Validations
5
+ include Scrivener::Validations
6
+
7
+ module Callbacks
8
+ def valid?
9
+ before_validation
10
+
11
+ result = super
12
+
13
+ after_validation
14
+
15
+ result
16
+ end
17
+
18
+ protected
19
+
20
+ def before_validation
21
+ end
22
+
23
+ def after_validation
24
+ end
25
+ end
26
+
27
+ include Callbacks
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "ohm-validations"
3
+ s.version = "0.0.1"
4
+ s.summary = "Validation for Ohm::Model."
5
+ s.description = s.summary
6
+ s.authors = ["Francesco Rodríguez"]
7
+ s.email = ["frodsan@me.com"]
8
+ s.homepage = "https://github.com/frodsan/ohm-validations"
9
+ s.license = "MIT"
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+
13
+ s.add_dependency "ohm"
14
+ s.add_dependency "scrivener"
15
+ s.add_development_dependency "cutest"
16
+ end
@@ -0,0 +1,48 @@
1
+ require "cutest"
2
+ require "ohm"
3
+ require_relative "../lib/ohm/validations"
4
+
5
+ Ohm.redis = Redic.new("redis://127.0.0.1:6379/15")
6
+
7
+ setup do
8
+ Ohm.flush
9
+ end
10
+
11
+ class User < Ohm::Model
12
+ include Ohm::Validations
13
+
14
+ attribute :name
15
+
16
+ attr :before, :after
17
+
18
+ def validate
19
+ assert_present(:name)
20
+ end
21
+
22
+ def before_validation
23
+ @before = true
24
+ end
25
+
26
+ def after_validation
27
+ @after = true
28
+ end
29
+ end
30
+
31
+ test "validations" do
32
+ user = User.new({})
33
+
34
+ assert !user.valid?
35
+
36
+ user.name = "jhon"
37
+
38
+ assert user.valid?
39
+ end
40
+
41
+ test "callbacks" do
42
+ user = User.new({})
43
+
44
+ user.valid?
45
+
46
+ assert user.before
47
+ assert user.after
48
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ohm-validations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Francesco Rodríguez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ohm
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: scrivener
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cutest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Validation for Ohm::Model.
56
+ email:
57
+ - frodsan@me.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gems"
63
+ - LICENSE
64
+ - README.md
65
+ - lib/ohm/validations.rb
66
+ - ohm-validations.gemspec
67
+ - test/validations.rb
68
+ homepage: https://github.com/frodsan/ohm-validations
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.2.0
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Validation for Ohm::Model.
92
+ test_files: []