drysql 0.1.6 → 0.1.7
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/lib/associations.rb +9 -9
- data/lib/base.rb +4 -4
- data/lib/dependencies.rb +2 -2
- data/lib/validations.rb +6 -6
- metadata +1 -1
data/lib/associations.rb
CHANGED
|
@@ -18,7 +18,7 @@ module ActiveRecord
|
|
|
18
18
|
|
|
19
19
|
def clear_cached_associations
|
|
20
20
|
@associations = nil
|
|
21
|
-
logger.info("Cleared cached schema for: #{self}")
|
|
21
|
+
logger.info("DRYSQL >> Cleared cached schema for: #{self}")
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def is_associated_with(class_name_symbol)
|
|
@@ -31,9 +31,9 @@ module ActiveRecord
|
|
|
31
31
|
def generate_belongs_to_associations
|
|
32
32
|
foreign_keys = table_constraints.select {|constraint| constraint.foreign_key?}
|
|
33
33
|
foreign_keys.each do |foreign_key|
|
|
34
|
-
belongs_to_class_name = (class_name(foreign_key.referenced_table_name
|
|
34
|
+
belongs_to_class_name = (class_name(foreign_key.referenced_table_name)).downcaseFirstLetter
|
|
35
35
|
self.send(:belongs_to, :"#{belongs_to_class_name}", :foreign_key=>foreign_key.column_name)
|
|
36
|
-
logger.info("GENERATED ASSOCIATION: #{self.name} belongs_to :#{belongs_to_class_name}, :foreign_key=>#{foreign_key.column_name}")
|
|
36
|
+
logger.info("DRYSQL >> GENERATED ASSOCIATION: #{self.name} belongs_to :#{belongs_to_class_name}, :foreign_key=>#{foreign_key.column_name}")
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -42,19 +42,19 @@ module ActiveRecord
|
|
|
42
42
|
def generate_has_many_associations
|
|
43
43
|
foreign_constraints.each do |foreign_constraint|
|
|
44
44
|
if foreign_constraint_column_is_unique?(foreign_constraint)
|
|
45
|
-
has_one_class_name = (class_name(foreign_constraint.table_name
|
|
45
|
+
has_one_class_name = (class_name(foreign_constraint.table_name)).downcaseFirstLetter
|
|
46
46
|
self.send(:has_one, :"#{has_one_class_name}", :foreign_key=>foreign_constraint.referenced_column_name)
|
|
47
|
-
logger.info("GENERATED ASSOCIATION: #{self.name} has_one :#{has_one_class_name}, :foreign_key=>#{foreign_constraint.referenced_column_name}")
|
|
47
|
+
logger.info("DRYSQL >> GENERATED ASSOCIATION: #{self.name} has_one :#{has_one_class_name}, :foreign_key=>#{foreign_constraint.referenced_column_name}")
|
|
48
48
|
else
|
|
49
|
-
has_many_class_name = (class_name(foreign_constraint.table_name
|
|
49
|
+
has_many_class_name = (class_name(foreign_constraint.table_name)).downcaseFirstLetter.pluralize
|
|
50
50
|
self.send(:has_many, :"#{has_many_class_name}", :foreign_key=>foreign_constraint.referenced_column_name)
|
|
51
|
-
logger.info("GENERATED ASSOCIATION: #{self.name} has_many :#{has_many_class_name}, :foreign_key=>#{foreign_constraint.referenced_column_name}")
|
|
51
|
+
logger.info("DRYSQL >> GENERATED ASSOCIATION: #{self.name} has_many :#{has_many_class_name}, :foreign_key=>#{foreign_constraint.referenced_column_name}")
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def foreign_constraint_column_is_unique?(constraint)
|
|
57
|
-
class_name = class_name(constraint.table_name
|
|
57
|
+
class_name = class_name(constraint.table_name)
|
|
58
58
|
klass = instance_eval(class_name)
|
|
59
59
|
constraints_on_given_column = klass.table_constraints.select {|current| current.column_name == constraint.column_name}
|
|
60
60
|
constraints_on_given_column.any? {|current| current.unique_key?}
|
|
@@ -83,7 +83,7 @@ module ActiveRecord
|
|
|
83
83
|
eligible_foreign_keys.select {|key| !self.is_associated_with(symbolized_class_name_from_table_name(key.referenced_table_name))}.each do |fk|
|
|
84
84
|
has_many_class_name = pluralized_symbolized_class_name_from_table_name(fk.referenced_table_name)
|
|
85
85
|
self.send(:has_many, has_many_class_name, :through=>association[0])
|
|
86
|
-
logger.info("GENERATED ASSOCIATION: #{self.name} has_many #{has_many_class_name}, :through=>#{association[0]}")
|
|
86
|
+
logger.info("DRYSQL >> GENERATED ASSOCIATION: #{self.name} has_many #{has_many_class_name}, :through=>#{association[0]}")
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
89
|
end
|
data/lib/base.rb
CHANGED
|
@@ -48,17 +48,17 @@ module ActiveRecord
|
|
|
48
48
|
# ---------------------------------------------------------------------------------------------------
|
|
49
49
|
def primary_key
|
|
50
50
|
primary = table_constraints.detect {|constraint| constraint.primary_key?}
|
|
51
|
-
if primary.nil? then logger.error("No primary key defined for table #{table_name}") end
|
|
51
|
+
if primary.nil? then logger.error("DRYSQL >> No primary key defined for table #{table_name}") end
|
|
52
52
|
primary_name = primary.column_name
|
|
53
53
|
set_primary_key(primary_name)
|
|
54
|
-
logger.info("Identified PRIMARY KEY for #{self}: #{primary_name}")
|
|
54
|
+
logger.info("DRYSQL >> Identified PRIMARY KEY for #{self}: #{primary_name}")
|
|
55
55
|
primary_name
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
alias :base_class_name :class_name
|
|
60
60
|
def class_name(table_name = table_name) # :nodoc:
|
|
61
|
-
#Attempt to retrieve class name from cache before attempting to generate it
|
|
61
|
+
#Attempt to retrieve class name from cache before attempting to generate it
|
|
62
62
|
name = @@class_name_hash[table_name.upcase]
|
|
63
63
|
if !name
|
|
64
64
|
return base_class_name(table_name)
|
|
@@ -112,7 +112,7 @@ module ActiveRecord
|
|
|
112
112
|
primary = table_constraints.detect {|constraint| constraint.primary_key?}
|
|
113
113
|
primary_name = primary.column_name
|
|
114
114
|
set_primary_key(primary_name)
|
|
115
|
-
logger.info("Reset PRIMARY KEY for #{self}: #{primary_name}")
|
|
115
|
+
logger.info("DRYSQL >> Reset PRIMARY KEY for #{self}: #{primary_name}")
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
|
data/lib/dependencies.rb
CHANGED
|
@@ -19,9 +19,9 @@ class Module #:nodoc:
|
|
|
19
19
|
end_class_def
|
|
20
20
|
if ActiveRecord::Base.table_exists?(class_id)
|
|
21
21
|
eval(class_def, TOPLEVEL_BINDING)
|
|
22
|
-
ActiveRecord::Base.logger.info("GENERATED CLASS: #{class_id} < ActiveRecord::Base")
|
|
22
|
+
ActiveRecord::Base.logger.info("DRYSQL >> GENERATED CLASS: #{class_id} < ActiveRecord::Base")
|
|
23
23
|
else
|
|
24
|
-
ActiveRecord::Base.logger.error("No matching table could be found for class: #{class_id}")
|
|
24
|
+
ActiveRecord::Base.logger.error("DRYSQL >> No matching table could be found for class: #{class_id}")
|
|
25
25
|
raise NameError
|
|
26
26
|
end
|
|
27
27
|
end
|
data/lib/validations.rb
CHANGED
|
@@ -77,21 +77,21 @@ module ActiveRecord
|
|
|
77
77
|
|
|
78
78
|
if !(column.null || column.default_specified? || column.generated?)
|
|
79
79
|
self.validates_nullability_of column.name
|
|
80
|
-
logger.info("GENERATED VALIDATION: #{self.name} validates_nullability_of #{column.name}")
|
|
80
|
+
logger.info("DRYSQL >> GENERATED VALIDATION: #{self.name} validates_nullability_of #{column.name}")
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
if column.type == :integer
|
|
84
84
|
self.validates_numericality_of column.name, :allow_nil => true, :only_integer => true
|
|
85
|
-
logger.info("GENERATED VALIDATION: #{self.name} validates_numericality_of #{column.name}, :allow_nil=>true, :only_integer=>true")
|
|
85
|
+
logger.info("DRYSQL >> GENERATED VALIDATION: #{self.name} validates_numericality_of #{column.name}, :allow_nil=>true, :only_integer=>true")
|
|
86
86
|
elsif column.number?
|
|
87
87
|
self.validates_numericality_of column.name, :allow_nil => true
|
|
88
|
-
logger.info("GENERATED VALIDATION: #{self.name} validates_numericality_of #{column.name}, :allow_nil=>true")
|
|
88
|
+
logger.info("DRYSQL >> GENERATED VALIDATION: #{self.name} validates_numericality_of #{column.name}, :allow_nil=>true")
|
|
89
89
|
elsif column.text? && column.limit
|
|
90
90
|
self.validates_length_of column.name, :allow_nil => true, :maximum => column.limit
|
|
91
|
-
logger.info("GENERATED VALIDATION: #{self.name} validates_length_of #{column.name}, :allow_nil=>true, :maximum=>#{column.limit}")
|
|
91
|
+
logger.info("DRYSQL >> GENERATED VALIDATION: #{self.name} validates_length_of #{column.name}, :allow_nil=>true, :maximum=>#{column.limit}")
|
|
92
92
|
elsif column.type == :boolean
|
|
93
93
|
self.validates_inclusion_of column.name, :in => [true, false], :allow_nil =>true, :message => ActiveRecord::Errors.default_error_messages[:inclusion]
|
|
94
|
-
logger.info("GENERATED VALIDATION: #{self.name} validates_inclusion_of #{column.name}, :in=>[true, false], \
|
|
94
|
+
logger.info("DRYSQL >> GENERATED VALIDATION: #{self.name} validates_inclusion_of #{column.name}, :in=>[true, false], \
|
|
95
95
|
:allow_nil=>true, :message=>ActiveRecord::Errors.default_error_messages[:inclusion]")
|
|
96
96
|
end
|
|
97
97
|
end
|
|
@@ -101,7 +101,7 @@ module ActiveRecord
|
|
|
101
101
|
|
|
102
102
|
def clear_cached_validations
|
|
103
103
|
@validations = nil
|
|
104
|
-
logger.info("Cleared cached validations for: #{self}")
|
|
104
|
+
logger.info("DRYSQL >> Cleared cached validations for: #{self}")
|
|
105
105
|
end
|
|
106
106
|
|
|
107
107
|
end # end of class methods
|
metadata
CHANGED