voraz-dr_nic_magic_models 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -19,14 +19,12 @@ lib/module.rb
19
19
  lib/rails.rb
20
20
  scripts/txt2html
21
21
  scripts/txt2js
22
- test.db
23
22
  test/abstract_unit.rb
24
23
  test/connections/native_mysql/connection.rb
25
24
  test/connections/native_postgresql/connection.rb
26
25
  test/connections/native_sqlite/connection.rb
27
26
  test/dummy_test.rb
28
27
  test/env_test.rb
29
- test/fixtures/.DS_Store
30
28
  test/fixtures/adjectives.yml
31
29
  test/fixtures/adjectives_fun_users.yml
32
30
  test/fixtures/db_definitions/mysql.drop.sql
data/README.rdoc ADDED
@@ -0,0 +1,11 @@
1
+ = Magic Models
2
+ -Added the validates_associated (it´s fixed a object_daddy crash)
3
+ -fixed this bug: http://groups.google.com/group/magicmodels/browse_thread/thread/14e1d1fb2d
4
+ abfdf0
5
+
6
+ == Install
7
+ gem sources -a http://gems.github.com
8
+ gem install voraz-dr_nic_magic_models
9
+
10
+ == Readme
11
+ See http://magicmodels.rubyforge.org/dr_nic_magic_models for pretty README
@@ -14,27 +14,40 @@ module DrNicMagicModels
14
14
  # NOT NULL constraints
15
15
  self.columns.reject { |column| column.name =~ /(?i)^(((created|updated)_(at|on))|position|type|id)$/ }.each do |column|
16
16
 
17
- if column.type == :integer
18
- logger.debug "validates_numericality_of #{column.name}, :allow_nil => #{column.null.inspect}, :only_integer => true"
19
- self.validates_numericality_of column.name, :allow_nil => column.null, :only_integer => true
20
- elsif column.number?
21
- logger.debug "validates_numericality_of #{column.name}, :allow_nil => #{column.null.inspect}"
22
- self.validates_numericality_of column.name, :allow_nil => column.null
23
- elsif column.text? && column.limit
24
- logger.debug "validates_length_of #{column.name}, :allow_nil => #{column.null.inspect}, :maximum => #{column.limit}"
25
- self.validates_length_of column.name, :allow_nil => column.null, :maximum => column.limit
26
- end
17
+ inheritable = false
18
+ self.inheritable_attributes[:reflections].each_value{ |t|
19
+ if "#{t.name}_id" == column.name
20
+ inheritable = true
21
+ logger.debug "validates_associated #{t.name}"
22
+ self.validates_associated t.name, :allow_nil=>column.null, :allow_blank=>column.null
23
+ break
24
+ end
25
+ }rescue 0
27
26
 
28
- # Active record seems to interpolate booleans anyway to either true, false or nil...
29
- if column.type == :boolean
30
- logger.debug "validates_inclusion_of #{column.name}, :in => [true, false], :allow_nil => #{column.null}, :message => ActiveRecord::Errors.default_error_messages[:blank]"
31
- self.validates_inclusion_of column.name, :in => [true, false], :allow_nil => column.null, :message => ActiveRecord::Errors.default_error_messages[:blank]
32
- elsif !column.null
33
- logger.debug "validates_presence_of #{column.name}"
34
- self.validates_presence_of column.name
27
+ if !inheritable
28
+ if column.type == :integer
29
+ logger.debug "validates_numericality_of #{column.name}, :allow_nil => #{column.null.inspect}, :only_integer => true"
30
+ self.validates_numericality_of column.name, :allow_nil => column.null, :only_integer => true
31
+ elsif column.number?
32
+ logger.debug "validates_numericality_of #{column.name}, :allow_nil => #{column.null.inspect}"
33
+ self.validates_numericality_of column.name, :allow_nil => column.null
34
+ elsif column.text? && column.limit
35
+ logger.debug "validates_length_of #{column.name}, :allow_nil => #{column.null.inspect}, :maximum => #{column.limit}"
36
+ self.validates_length_of column.name, :allow_nil => column.null, :maximum => column.limit
37
+ end
38
+
39
+ # Active record seems to interpolate booleans anyway to either true, false or nil...
40
+ if column.type == :boolean
41
+ logger.debug "validates_inclusion_of #{column.name}, :in => [true, false], :allow_nil => #{column.null}, :message => ActiveRecord::Errors.default_error_messages[:blank]"
42
+ self.validates_inclusion_of column.name, :in => [true, false], :allow_nil => column.null, :message => ActiveRecord::Errors.default_error_messages[:blank]
43
+ elsif !column.null
44
+ #test if the column have a belongs_to association
45
+ logger.debug "validates_presence_of #{column.name}"
46
+ self.validates_presence_of column.name
47
+ end
35
48
  end
36
49
  end
37
-
50
+
38
51
  # Single-column UNIQUE indexes
39
52
  get_unique_index_columns.each do |col|
40
53
  logger.debug "validates_uniqueness_of #{col}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voraz-dr_nic_magic_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - nicwilliams
@@ -38,7 +38,7 @@ files:
38
38
  - CHANGELOG
39
39
  - History.txt
40
40
  - Manifest.txt
41
- - README
41
+ - README.rdoc
42
42
  - Rakefile
43
43
  - install.rb
44
44
  - lib/base.rb
@@ -63,7 +63,6 @@ files:
63
63
  - test/connections/native_sqlite/connection.rb
64
64
  - test/dummy_test.rb
65
65
  - test/env_test.rb
66
- - test/fixtures/.DS_Store
67
66
  - test/fixtures/adjectives.yml
68
67
  - test/fixtures/adjectives_fun_users.yml
69
68
  - test/fixtures/db_definitions/mysql.drop.sql
@@ -97,7 +96,7 @@ licenses:
97
96
  post_install_message:
98
97
  rdoc_options:
99
98
  - --main
100
- - README.txt
99
+ - README.rdoc
101
100
  require_paths:
102
101
  - lib
103
102
  required_ruby_version: !ruby/object:Gem::Requirement
data/README DELETED
File without changes
File without changes