lib/xeroizer/record/base.rb in xeroizer-float-2.15.3.16 vs lib/xeroizer/record/base.rb in xeroizer-float-2.15.5.1
- old
+ new
@@ -12,10 +12,11 @@
include ClassLevelInheritableAttributes
class_inheritable_attributes :fields, :possible_primary_keys, :primary_key_name, :summary_only, :validators
attr_reader :attributes
attr_reader :parent
+ attr_reader :model
attr_accessor :errors
attr_accessor :complete_record_downloaded
include ModelDefinitionHelper
include RecordAssociationHelper
@@ -34,26 +35,35 @@
end
end
public
-
+
def initialize(parent)
@parent = parent
+ @model = new_model_class(self.class.name.demodulize)
@attributes = {}
end
-
+
def new_model_class(model_name)
- Xeroizer::Record.const_get("#{model_name}Model".to_sym).new(parent.application, model_name.to_s)
+ if parent
+ Xeroizer::Record.const_get("#{model_name}Model".to_sym).new(parent.application, model_name.to_s)
+ else
+ Xeroizer::Record.const_get("#{model_name}Model".to_sym).new(nil, model_name.to_s)
+ end
end
def [](attribute)
self.send(attribute)
end
def []=(attribute, value)
parent.mark_dirty(self) if parent
self.send("#{attribute}=".to_sym, value)
+ end
+
+ def non_calculated_attributes
+ attributes.reject {|name| self.class.fields[name][:calculated] }
end
def attributes=(new_attributes)
return unless new_attributes.is_a?(Hash)
parent.mark_dirty(self) if parent