lib/moneta/api/data_mapper.rb in moneta-api-1.0.4 vs lib/moneta/api/data_mapper.rb in moneta-api-1.1.0

- old
+ new

@@ -45,17 +45,18 @@ end end end module ClassMethods - def property(name, base_type=nil) - attr_accessor(name) + def property(name, type: nil, read_only: false) + generate_accessors(name, read_only) + # Сохраняем свойста и перезаписываем instance метод current_properties = instance_variable_get('@properties') || {} properties = instance_variable_set('@properties', - current_properties.merge(name => base_type).merge(parents_properties) + current_properties.merge(parents_properties).merge(name => type) ) send(:define_method, :properties) { properties } end @@ -71,9 +72,14 @@ if klass.name.match(/Moneta::Api::(Types|Requests|Responses)/) hash.merge!(klass.instance_variable_get('@properties') || {}) end end ) + end + + def generate_accessors(name, read_only) + attr_reader(name) + attr_writer(name) unless read_only end end end end end