Module: DataMapper::Is::Temporal
- Included in:
- Model
- Defined in:
- lib/dm-is-temporal/is/temporal.rb
Defined Under Namespace
Modules: Migration Classes: PropertyHelper, TemporalListProxy, TemporalProxy
Constant Summary collapse
- @@__temporal_classes__ =
[]
Instance Method Summary collapse
Instance Method Details
#is_temporal(*args, &block) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/dm-is-temporal/is/temporal.rb', line 58 def is_temporal(*args, &block) extend(Migration) if respond_to?(:auto_migrate!) version_model = DataMapper::Model.new do def has(*args) #ignore all end end if block_given? version_model.instance_eval <<-RUBY def self.default_repository_name :#{default_repository_name} end RUBY version_model.property(:id, DataMapper::Property::Serial) version_model.property(:updated_at, DataMapper::Property::DateTime) version_model.before(:save) { self.updated_at ||= DateTime.now } version_model.instance_eval(&block) const_set(:TemporalVersion, version_model) @@__temporal_classes__ << self::TemporalVersion h = PropertyHelper.new(self) h.instance_eval(&block) has n, :temporal_versions #, :accessor => :protected create_methods h.__properties__.each do |a| create_temporal_reader(a[0]) create_temporal_writer(a[0]) end h.__has__.each do |a| has_args = a[2] plural_name = a[1] if has_args.any? and has_args[0].is_a?(String) clazz = has_args[0] table = DataMapper::Inflector.tableize(clazz) singular_name = DataMapper::Inflector.singularize(table) else singular_name = DataMapper::Inflector.singularize(plural_name.to_s) end list_model = DataMapper::Model.new list_model.instance_eval <<-RUBY def self.default_repository_name :#{default_repository_name} end RUBY list_model.property(:id, DataMapper::Property::Serial) list_model.property(:updated_at, DataMapper::Property::DateTime) list_model.property(:deleted_at, DataMapper::Property::DateTime) list_model.before(:save) { self.updated_at ||= DateTime.now } list_model.belongs_to singular_name #, :accessor => :protected temporal_list_name = "temporal_#{plural_name}".to_sym list_model_name = Inflector.classify("temporal_#{singular_name}") const_set(list_model_name.to_sym, list_model) @@__temporal_classes__ << eval("self::#{list_model_name}") has n, temporal_list_name, list_model_name create_temporal_list_reader(plural_name, singular_name, temporal_list_name, list_model_name) # create_temporal_list_writer(a[1], temporal_list) end else raise "Temporal Property pattern not supported yet" end end |