rein 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,6 +10,19 @@ Database constraints made easy for ActiveRecord. Rein currently supports Postgre
10
10
  Unfortunately, ActiveRecord doesn't encourage (or even allow) you to use database integrity without resorting to hand-crafted SQL. Rein adds a handful of methods to your ActiveRecord migrations so that you can easily tame your database.
11
11
 
12
12
 
13
+ ## FAQ
14
+
15
+ ### How is Rein different to other gems like [foreigner](http://github.com/matthuhiggins/foreigner) or [redhillonrails](http://github.com/mlomnicki/redhillonrails_core), which do the same thing?
16
+
17
+ If you're using MySQL then there is no difference, Rein should work as a drop-in replacement. If you're using PostgreSQL however, then Rein provides you with extra methods for placing check constraints on your data.
18
+
19
+ ### If [DHH](http://en.wikipedia.org/wiki/David_Heinemeier_Hansson) wanted my app to have database constraints then Rails would have been born with them?
20
+
21
+ Rails is an opinionated piece of software. One opinion is that your database should simply function as a "dumb" container which your application controls. This is the opinion of Rails.
22
+
23
+ Another opinion is that your database is actually a powerful [DBMS](http://en.wikipedia.org/wiki/Database_management_system) which has already solved problems like data integrity, and your application should wield this power.
24
+
25
+
13
26
  ## Quick Start
14
27
 
15
28
  Install the gem:
@@ -65,3 +78,10 @@ And here we have a table of books:
65
78
 
66
79
  # State is always either "available" or "on_loan".
67
80
  add_inclusion_constraint :books, :state, :in => %w(available on_loan)
81
+
82
+
83
+ ## Credits
84
+
85
+ * [Marcus Crafter](http://github.com/crafterm)
86
+ * [Tim Lucas](http://github.com/toolmantim)
87
+ * [Xavier Shay](http://github.com/xaviershay)
@@ -6,13 +6,18 @@ module RC
6
6
 
7
7
  name = options[:name] || "#{referencing_attribute}_fk".to_sym
8
8
 
9
- sql = "ALTER TABLE #{referencing_table} ADD CONSTRAINT #{name} FOREIGN KEY (#{referencing_attribute}) REFERENCES #{referenced_table} (#{referenced_attribute})"
10
- sql << " ON DELETE #{referential_action(options[:on_delete])}" if options[:on_delete]
11
- sql << " ON UPDATE #{referential_action(options[:on_update])}" if options[:on_update]
12
-
13
- add_index(referencing_table, referencing_attribute) if options[:index] == true
9
+ sql = "ALTER TABLE #{referencing_table}".tap do |sql|
10
+ sql << " ADD CONSTRAINT #{name}"
11
+ sql << " FOREIGN KEY (#{referencing_attribute})"
12
+ sql << " REFERENCES #{referenced_table} (#{referenced_attribute})"
13
+ sql << " ON DELETE #{referential_action(options[:on_delete] || :restrict)}"
14
+ sql << " ON UPDATE #{referential_action(options[:on_update] || :restrict)}"
15
+ end
14
16
 
15
17
  execute(sql)
18
+
19
+ # A foreign key constraint doesn't have an implicit index.
20
+ add_index(referencing_table, referencing_attribute) if options[:add_index] == true
16
21
  end
17
22
 
18
23
  alias_method :add_foreign_key, :add_foreign_key_constraint
@@ -1,3 +1,3 @@
1
1
  module Rein
2
- VERSION = "0.5.1" unless defined?(Rein::VERSION)
2
+ VERSION = "0.5.2" unless defined?(Rein::VERSION)
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 1
9
- version: 0.5.1
8
+ - 2
9
+ version: 0.5.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Josh Bassett
@@ -14,11 +14,12 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-29 00:00:00 +10:00
17
+ date: 2010-08-30 00:00:00 +10:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activerecord
22
+ prerelease: false
22
23
  requirement: &id001 !ruby/object:Gem::Requirement
23
24
  none: false
24
25
  requirements:
@@ -28,10 +29,10 @@ dependencies:
28
29
  - 0
29
30
  version: "0"
30
31
  type: :runtime
31
- prerelease: false
32
32
  version_requirements: *id001
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
+ prerelease: false
35
36
  requirement: &id002 !ruby/object:Gem::Requirement
36
37
  none: false
37
38
  requirements:
@@ -43,10 +44,10 @@ dependencies:
43
44
  - 0
44
45
  version: 1.0.0
45
46
  type: :development
46
- prerelease: false
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: hirb
50
+ prerelease: false
50
51
  requirement: &id003 !ruby/object:Gem::Requirement
51
52
  none: false
52
53
  requirements:
@@ -58,10 +59,10 @@ dependencies:
58
59
  - 2
59
60
  version: 0.3.2
60
61
  type: :development
61
- prerelease: false
62
62
  version_requirements: *id003
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: rake
65
+ prerelease: false
65
66
  requirement: &id004 !ruby/object:Gem::Requirement
66
67
  none: false
67
68
  requirements:
@@ -73,10 +74,10 @@ dependencies:
73
74
  - 7
74
75
  version: 0.8.7
75
76
  type: :development
76
- prerelease: false
77
77
  version_requirements: *id004
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: rcov
80
+ prerelease: false
80
81
  requirement: &id005 !ruby/object:Gem::Requirement
81
82
  none: false
82
83
  requirements:
@@ -88,10 +89,10 @@ dependencies:
88
89
  - 8
89
90
  version: 0.9.8
90
91
  type: :development
91
- prerelease: false
92
92
  version_requirements: *id005
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: rspec
95
+ prerelease: false
95
96
  requirement: &id006 !ruby/object:Gem::Requirement
96
97
  none: false
97
98
  requirements:
@@ -103,10 +104,10 @@ dependencies:
103
104
  - 0
104
105
  version: 1.3.0
105
106
  type: :development
106
- prerelease: false
107
107
  version_requirements: *id006
108
108
  - !ruby/object:Gem::Dependency
109
109
  name: rr
110
+ prerelease: false
110
111
  requirement: &id007 !ruby/object:Gem::Requirement
111
112
  none: false
112
113
  requirements:
@@ -118,10 +119,10 @@ dependencies:
118
119
  - 0
119
120
  version: 1.0.0
120
121
  type: :development
121
- prerelease: false
122
122
  version_requirements: *id007
123
123
  - !ruby/object:Gem::Dependency
124
124
  name: wirble
125
+ prerelease: false
125
126
  requirement: &id008 !ruby/object:Gem::Requirement
126
127
  none: false
127
128
  requirements:
@@ -133,7 +134,6 @@ dependencies:
133
134
  - 3
134
135
  version: 0.1.3
135
136
  type: :development
136
- prerelease: false
137
137
  version_requirements: *id008
138
138
  description: Rein adds bunch of methods to your ActiveRecord migrations so you can easily tame your database.
139
139
  email: josh.bassett@gmail.com
@@ -167,7 +167,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
167
  requirements:
168
168
  - - ">="
169
169
  - !ruby/object:Gem::Version
170
- hash: 1241107723212078290
171
170
  segments:
172
171
  - 0
173
172
  version: "0"