7
8
9
10
11
12
13
14
15
16
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/netfira/web_connect/model/record/materialization.rb', line 7
def materialize(name, has_languages, props)
klass = begin
Models.const_get name
rescue NameError
Models.const_set name, Class.new(props.file ? FileRecord : self)
end
klass.instance_variable_set :@table_props, props
shop_relation = name.underscore.pluralize.to_sym
klass.belongs_to :shop,
class_name: 'Netfira::WebConnect::Models::Shop',
inverse_of: shop_relation
Models::Shop.has_many shop_relation, inverse_of: :shop
if has_languages
Model::Record::Translation.materialize klass
klass.include Model::Record::Translations
translated_attributes = klass::Translation.attribute_names.reject do |attribute|
(%w[id language] << "#{klass.single_name}_id").include? attribute
end
translated_attributes.each do |attribute|
klass.__send__ :define_method, :"#{attribute}" do
self.get_translated_string attribute.to_sym
end
klass.__send__ :define_method, :"#{attribute}=" do |value|
self.set_translated_string attribute.to_sym, value
end
end
end
klass.include Model::Record::Tree if klass.tree?
klass.include Model::Record::Sendable if klass.sendable?
if Netfira::WebConnect.paranoia?
klass.acts_as_paranoid
else
def klass.with_deleted; self end
end
if klass.has_file?
klass.has_attached_file :attachment, Netfira::WebConnect.file_store
klass.do_not_validate_attachment_file_type :attachment
end
end
|