17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/active_record/custom_attributes.rb', line 17
def has_custom_attributes( = {}, &block)
field_types =
field_types = self.defined_custom_field_types.merge() if has_custom_attributes?
field_definitions = CustomAttributeDefinitionHelper.new field_types
yield field_definitions if block_given?
defined_custom_attributes = field_definitions.defined_attributes
defined_custom_validations = field_definitions.defined_validations
if has_custom_attributes?
write_inheritable_attribute(:defined_custom_attributes, self.defined_custom_attributes.deep_merge(defined_custom_attributes))
write_inheritable_attribute(:defined_custom_validations, self.defined_custom_validations.deep_merge(defined_custom_validations))
write_inheritable_attribute(:defined_custom_field_types, field_types)
else
write_inheritable_attribute(:defined_custom_attributes, defined_custom_attributes)
class_inheritable_reader(:defined_custom_attributes)
write_inheritable_attribute(:defined_custom_validations, defined_custom_validations)
class_inheritable_reader(:defined_custom_validations)
write_inheritable_attribute(:defined_custom_field_types, )
class_inheritable_reader(:defined_custom_field_types)
class_eval do
def self.has_custom_attributes?
true
end
include ActiveRecord::CustomAttributes::Core
end
end
end
|