lib/datev/base.rb in datev-0.2.3 vs lib/datev/base.rb in datev-0.3.0
- old
+ new
@@ -1,15 +1,18 @@
require 'datev/field'
module Datev
class Base
class << self
- attr_accessor :fields
+ attr_accessor :fields, :default_attributes
+
+ def inherited(subclass)
+ subclass.fields = self.fields
+ subclass.default_attributes = self.default_attributes
+ end
end
- attr_accessor :attributes
-
def self.field(name, type, options={}, &block)
self.fields ||= []
# Check if there is already a field with the same name
if field_by_name(name)
@@ -21,11 +24,13 @@
def self.field_by_name(name)
self.fields.find { |f| f.name == name }
end
+ attr_accessor :attributes
+
def initialize(attributes)
- self.attributes = {}
+ self.attributes = self.class.default_attributes || {}
raise ArgumentError.new('Hash required') unless attributes.is_a?(Hash)
# Check existing names and set value (if valid)
attributes.each_pair do |name,value|