lib/spontaneous/plugins/schema_hierarchy.rb in spontaneous-0.1.0.alpha1 vs lib/spontaneous/plugins/schema_hierarchy.rb in spontaneous-0.2.0.alpha1

- old
+ new

@@ -1,76 +1,75 @@ # encoding: UTF-8 module Spontaneous::Plugins module SchemaHierarchy + extend ActiveSupport::Concern + module ClassMethods def schema_validate if schema_id.nil? - Spontaneous::Schema.missing_id!(:type, self) + Spontaneous.schema.missing_id!(:type, self) else # only need to check internal consistency if class already existed fields.each do |field| - if field.schema_id.nil? - Spontaneous::Schema.missing_id!(:field, field) + if field.owner == self and field.schema_id.nil? + Spontaneous.schema.missing_id!(:field, field) end end # boxes don't have boxes if respond_to?(:boxes) boxes.each do |box| - if box.schema_id.nil? - Spontaneous::Schema.missing_id!(:box, box) + if box.owner == self and box.schema_id.nil? + Spontaneous.schema.missing_id!(:box, box) end end end styles.each do |style| - if style.schema_id.nil? - Spontaneous::Schema.missing_id!(:style, style) + if style.owner == self and style.schema_id.nil? + Spontaneous.schema.missing_id!(:style, style) end end if respond_to?(:layouts) layouts.each do |layout| - if layout.schema_id.nil? - Spontaneous::Schema.missing_id!(:layout, layout) + if layout.owner == self and layout.schema_id.nil? + Spontaneous.schema.missing_id!(:layout, layout) end end end end end + # TODO: Delete this? def schema_reset! - @subclasses = nil end - def subclasses - @subclasses ||= [] - end - def __source_file=(path) @__source_file = path end protected(:__source_file=) def __source_file @__source_file end + def subclasses + Spontaneous.schema.subclasses_of(self) + end + def descendents - subclasses.map{ |x| [x] + x.descendents}.flatten + Spontaneous.schema.descendents_of(self) end def inherited(subclass, real_caller = nil) subclass.__source_file = File.expand_path((real_caller || caller[0]).split(':')[0]) - Spontaneous::Schema.classes << subclass if subclass.schema_class? - subclasses << subclass + Spontaneous.schema.add_class(self, subclass)# if subclass.schema_class? super(subclass) end def schema_class? true end - end - end + end # ClassMethods + end # SchemaHierarchy end - -