1 require 'active_support'
9 def doozer(name, opts={}, &block)
10 # Load up the settings from the alternate syntax
11 altdef = Doozer::AltDefinition.new(name, opts)
12 altdef.instance_eval(&block) if block_given?
14 # Redefine in official definition format... kinda
15 Doozer.define( name, opts )
16 obj_list = Doozer.object_list[name]
17 obj_list[:field_order] = altdef.field_definitions.field_list unless altdef.field_definitions.field_list.empty?
18 obj_list[:default_values] = altdef.field_definitions.field_defaults
19 obj_list[:block_affects] = altdef.block_affects unless altdef.block_affects.nil?
20 obj_list[:before_generate] = altdef.event_handlers[:generate] if altdef.event_handlers.has_key?(:generate)
21 obj_list[:target] = altdef.target_name unless altdef.target_name.nil?
26 attr_reader :name, :options, :field_definitions, :block_affects, :event_handlers, :target_name
28 def initialize(name, opts={})
31 @field_definitions = CleanFields.new
38 @field_definitions.instance_eval(&block)
42 if action == :belong_to
44 @block_affects << {:child=>:belongs_to}
45 elsif action == :act_as_tree or action == :parent_id
47 @block_affects << {:child=>:parent_id}
52 if action == :belongs_to
54 @block_affects << {:parent=>:belongs_to}
58 def target(target_name)
59 @target_name = target_name
63 @event_handlers[key] = block if block_given?
69 attr_reader :field_list, :field_defaults
74 def id(*args) method_missing(:id, *args); end
75 def name(*args) method_missing(:name, *args); end
76 def type(*args) method_missing(:type, *args); end
77 def method_missing(name, *args)
79 @field_list << name.to_sym
80 @field_defaults[name.to_sym] = args[0] if args.length > 0