1 ManifestBase.require_modules "manifest/model/",
2 %w|attribute association|
5 class Model < ManifestBase::Base
8 attr :attributes, :associations, :table_name
12 @json['table_name'] ||= ::Manifest.manifest.pluralize(@name)
13 @json['attributes'] ||= {}
14 @json['associations'] ||= {}
15 @json['attributes']['id'] = {
22 @json['attributes']['created_at'] = {
25 @json['attributes']['updated_at'] = {
32 @table_name = @json['table_name']
33 @attributes = ManifestBase.load_name_values self, @json, 'attributes', Attribute
34 @associations = ManifestBase.load_value self, @json, 'associations', Association
42 ::Manifest.item_name_to_model @name
45 def valid_encode_columns
47 @attributes.each {|attribute_name, attribute|
48 next unless attribute.type == 'text'
55 return :author if @attributes['author_id']
56 return :artist if @attributes['artist_id']
61 return true if self.owner_type
65 def child_model_manifests
67 ::Manifest.manifest.items.each {|peta_name, peta_manifest|
68 next unless peta_manifest.element?
69 next unless peta_manifest.parent_item_name == @name
70 r << ::Manifest.manifest.models[peta_name]
76 self.child_model_manifests.map {|child_model_manifest|
77 child_model_manifest.classify
81 def child_element_names
82 self.child_models.map {|child_model|
83 self.associations.child_element_name(child_model)
87 def child_element_name item_name
88 self.associations.child_element_name(child_model_manifest)