lib/koine/attributes.rb in koine-attributes-0.2.3 vs lib/koine/attributes.rb in koine-attributes-0.3.0

- old
+ new

@@ -73,14 +73,13 @@ # attributes initializer: true do # attribute :name, :string # attribute :birthday, :date # end # -# def initializ(attributes = {}) +# def initialize(attributes = {}) # @foo = attributes.delete(:foo) -# -# initialize_attributes(attributes) # protected +# self.attributes.set_values(attributes) # end # end # # person = Person.new(name: 'John Doe', birthday: '2001-01-31', foo: :bar) # person.foo # => :bar @@ -122,20 +121,24 @@ base.extend(Forwardable) base.extend(ClassMethods) end module ClassMethods + private + def attributes(options = {}, &block) @builder = true @_attributes_factory ||= AttributesFactory.new(options) class_eval(&block) instance_eval do define_method :attributes do @_attributes ||= self.class.instance_variable_get(:@_attributes_factory).create(self) end + private :attributes + define_method(:initialize) { |*args| attributes.initialize_values(*args) } end @_attributes_factory.freeze @@ -152,10 +155,10 @@ instance_eval do def_delegators :attributes, name, "#{name}=", "with_#{name}" define_method :== do |other| - attributes == other.attributes + attributes == other.send(:attributes) end end end def array_of(item_adapter)