rein 0.1.0
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/LICENSE +20 -0
- data/README.md +17 -0
- data/lib/rein.rb +11 -0
- data/lib/rein/alone.rb +14 -0
- data/lib/rein/constraint/numericality.rb +22 -0
- data/lib/rein/version.rb +3 -0
- metadata +186 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Josh Bassett
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Rein
|
2
|
+
|
3
|
+
Database constraints made easy for ActiveRecord.
|
4
|
+
|
5
|
+
## Introduction
|
6
|
+
|
7
|
+
ActiveRecord doesn't make it easy for you to weild the power of your database.
|
8
|
+
|
9
|
+
## Quick Start
|
10
|
+
|
11
|
+
First, install the gem:
|
12
|
+
|
13
|
+
gem install rein
|
14
|
+
|
15
|
+
Then slap some constraints in your migrations. For example:
|
16
|
+
|
17
|
+
add_numericality_constraint :my_table, :my_field, :greater_than_or_equal_to => 0
|
data/lib/rein.rb
ADDED
data/lib/rein/alone.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
rc = "#{ENV['HOME']}/.rubyrc"
|
2
|
+
load(rc) if File.exist?(rc)
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler'
|
6
|
+
|
7
|
+
envs = [:default]
|
8
|
+
envs << ENV["REIN_ENV"].downcase.to_sym if ENV["REIN_ENV"]
|
9
|
+
Bundler.setup(*envs)
|
10
|
+
|
11
|
+
path = File.join(File.expand_path(File.dirname(__FILE__)), '..')
|
12
|
+
$LOAD_PATH.unshift(path)
|
13
|
+
|
14
|
+
require 'rein'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RC
|
2
|
+
module Numericality
|
3
|
+
OPERATORS = {
|
4
|
+
:greater_than => :>,
|
5
|
+
:greater_than_or_equal_to => :>=,
|
6
|
+
:equal_to => :==,
|
7
|
+
:less_than => :<,
|
8
|
+
:less_than_or_equal_to => :<=
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
def self.add_numericality_constraint(table, attribute, options)
|
12
|
+
conditions = OPERATORS.slice(*options.keys).map do |key, operator|
|
13
|
+
value = options[key]
|
14
|
+
[attribute, operator, value].join(" ")
|
15
|
+
end
|
16
|
+
|
17
|
+
conditions_sql = conditions.map {|condition| "(#{condition})" }.join(" AND ")
|
18
|
+
|
19
|
+
"ALTER TABLE #{table} ADD CONSTRAINT #{attribute} CHECK #{conditions_sql}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/rein/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rein
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Josh Bassett
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-28 00:00:00 +10:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 7712042
|
28
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- rc
|
33
|
+
version: 3.0.0.rc
|
34
|
+
requirement: *id001
|
35
|
+
name: activesupport
|
36
|
+
prerelease: false
|
37
|
+
type: :runtime
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 23
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 0
|
48
|
+
- 0
|
49
|
+
version: 1.0.0
|
50
|
+
requirement: *id002
|
51
|
+
name: bundler
|
52
|
+
prerelease: false
|
53
|
+
type: :development
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 23
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
- 3
|
64
|
+
- 2
|
65
|
+
version: 0.3.2
|
66
|
+
requirement: *id003
|
67
|
+
name: hirb
|
68
|
+
prerelease: false
|
69
|
+
type: :development
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 49
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
- 8
|
80
|
+
- 7
|
81
|
+
version: 0.8.7
|
82
|
+
requirement: *id004
|
83
|
+
name: rake
|
84
|
+
prerelease: false
|
85
|
+
type: :development
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ~>
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 43
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
- 9
|
96
|
+
- 8
|
97
|
+
version: 0.9.8
|
98
|
+
requirement: *id005
|
99
|
+
name: rcov
|
100
|
+
prerelease: false
|
101
|
+
type: :development
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ~>
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
hash: 27
|
109
|
+
segments:
|
110
|
+
- 1
|
111
|
+
- 3
|
112
|
+
- 0
|
113
|
+
version: 1.3.0
|
114
|
+
requirement: *id006
|
115
|
+
name: rspec
|
116
|
+
prerelease: false
|
117
|
+
type: :development
|
118
|
+
- !ruby/object:Gem::Dependency
|
119
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
hash: 23
|
125
|
+
segments:
|
126
|
+
- 1
|
127
|
+
- 0
|
128
|
+
- 0
|
129
|
+
version: 1.0.0
|
130
|
+
requirement: *id007
|
131
|
+
name: rr
|
132
|
+
prerelease: false
|
133
|
+
type: :development
|
134
|
+
description: Rein provides a bunch of methods to make adding constraints to your database easier.
|
135
|
+
email: josh.bassett@gmail.com
|
136
|
+
executables: []
|
137
|
+
|
138
|
+
extensions: []
|
139
|
+
|
140
|
+
extra_rdoc_files: []
|
141
|
+
|
142
|
+
files:
|
143
|
+
- lib/rein/alone.rb
|
144
|
+
- lib/rein/constraint/numericality.rb
|
145
|
+
- lib/rein/version.rb
|
146
|
+
- lib/rein.rb
|
147
|
+
- LICENSE
|
148
|
+
- README.md
|
149
|
+
has_rdoc: true
|
150
|
+
homepage: http://github.com/nullobject/rein
|
151
|
+
licenses: []
|
152
|
+
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
|
156
|
+
require_paths:
|
157
|
+
- lib
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
none: false
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
hash: 3
|
164
|
+
segments:
|
165
|
+
- 0
|
166
|
+
version: "0"
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
none: false
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
hash: 23
|
173
|
+
segments:
|
174
|
+
- 1
|
175
|
+
- 3
|
176
|
+
- 6
|
177
|
+
version: 1.3.6
|
178
|
+
requirements: []
|
179
|
+
|
180
|
+
rubyforge_project: rein
|
181
|
+
rubygems_version: 1.3.7
|
182
|
+
signing_key:
|
183
|
+
specification_version: 3
|
184
|
+
summary: Database constraints made easy for ActiveRecord.
|
185
|
+
test_files: []
|
186
|
+
|