rein 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rein/constraint/foreign_key.rb +3 -2
- data/lib/rein/constraint/inclusion.rb +11 -0
- data/lib/rein/constraint/numericality.rb +4 -4
- data/lib/rein/version.rb +1 -1
- data/lib/rein.rb +1 -0
- metadata +111 -4
@@ -3,9 +3,10 @@ module RC
|
|
3
3
|
def add_foreign_key_constraint(referencing_table, referenced_table, options = {})
|
4
4
|
referencing_attribute = options[:referencing] || "#{referenced_table.to_s.singularize}_id".to_sym
|
5
5
|
referenced_attribute = "id".to_sym
|
6
|
-
constraint_name = options[:name] || "#{referencing_attribute}_fk".to_sym
|
7
6
|
|
8
|
-
|
7
|
+
name = options[:name] || "#{referencing_attribute}_fk".to_sym
|
8
|
+
|
9
|
+
sql = "ALTER TABLE #{referencing_table} ADD CONSTRAINT #{name} FOREIGN KEY (#{referencing_attribute}) REFERENCES #{referenced_table} (#{referenced_attribute})"
|
9
10
|
sql << " ON DELETE #{referential_action(options[:on_delete])}" if options[:on_delete]
|
10
11
|
sql << " ON UPDATE #{referential_action(options[:on_update])}" if options[:on_update]
|
11
12
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module RC
|
2
|
+
module Inclusion
|
3
|
+
def add_inclusion_constraint(table, attribute, options = {})
|
4
|
+
name = "#{table}_#{attribute}"
|
5
|
+
values = options[:in].map {|x| "'#{x}'" }.join(", ")
|
6
|
+
conditions = "#{attribute} IN (#{values})"
|
7
|
+
|
8
|
+
execute("ALTER TABLE #{table} ADD CONSTRAINT #{name} CHECK (#{conditions})")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -9,14 +9,14 @@ module RC
|
|
9
9
|
}.freeze
|
10
10
|
|
11
11
|
def add_numericality_constraint(table, attribute, options = {})
|
12
|
+
name = "#{table}_#{attribute}"
|
13
|
+
|
12
14
|
conditions = OPERATORS.slice(*options.keys).map do |key, operator|
|
13
15
|
value = options[key]
|
14
16
|
[attribute, operator, value].join(" ")
|
15
|
-
end
|
16
|
-
|
17
|
-
conditions = conditions.join(" AND ")
|
17
|
+
end.join(" AND ")
|
18
18
|
|
19
|
-
execute
|
19
|
+
execute("ALTER TABLE #{table} ADD CONSTRAINT #{name} CHECK (#{conditions})")
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/rein/version.rb
CHANGED
data/lib/rein.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Josh Bassett
|
@@ -19,7 +19,6 @@ default_executable:
|
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activesupport
|
22
|
-
prerelease: false
|
23
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
23
|
none: false
|
25
24
|
requirements:
|
@@ -32,7 +31,113 @@ dependencies:
|
|
32
31
|
- rc
|
33
32
|
version: 3.0.0.rc
|
34
33
|
type: :runtime
|
34
|
+
prerelease: false
|
35
35
|
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 0
|
46
|
+
- 0
|
47
|
+
version: 1.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: hirb
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
- 3
|
61
|
+
- 2
|
62
|
+
version: 0.3.2
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: rake
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
- 8
|
76
|
+
- 7
|
77
|
+
version: 0.8.7
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rcov
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
- 9
|
91
|
+
- 8
|
92
|
+
version: 0.9.8
|
93
|
+
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: *id005
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: rspec
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
segments:
|
104
|
+
- 1
|
105
|
+
- 3
|
106
|
+
- 0
|
107
|
+
version: 1.3.0
|
108
|
+
type: :development
|
109
|
+
prerelease: false
|
110
|
+
version_requirements: *id006
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rr
|
113
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ~>
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
segments:
|
119
|
+
- 1
|
120
|
+
- 0
|
121
|
+
- 0
|
122
|
+
version: 1.0.0
|
123
|
+
type: :development
|
124
|
+
prerelease: false
|
125
|
+
version_requirements: *id007
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: wirble
|
128
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
- 1
|
136
|
+
- 3
|
137
|
+
version: 0.1.3
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: *id008
|
36
141
|
description: Rein adds bunch of methods to your ActiveRecord migrations so you can easily tame your database.
|
37
142
|
email: josh.bassett@gmail.com
|
38
143
|
executables: []
|
@@ -44,6 +149,7 @@ extra_rdoc_files: []
|
|
44
149
|
files:
|
45
150
|
- lib/rein/alone.rb
|
46
151
|
- lib/rein/constraint/foreign_key.rb
|
152
|
+
- lib/rein/constraint/inclusion.rb
|
47
153
|
- lib/rein/constraint/numericality.rb
|
48
154
|
- lib/rein/version.rb
|
49
155
|
- lib/rein.rb
|
@@ -63,6 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
169
|
requirements:
|
64
170
|
- - ">="
|
65
171
|
- !ruby/object:Gem::Version
|
172
|
+
hash: 1515412698680743757
|
66
173
|
segments:
|
67
174
|
- 0
|
68
175
|
version: "0"
|