adelevie/parse_resource — pull request #70 by chytreg (2013-04-19 15:38:25+00:00)
Title: misleading implementation of attributes writer

Hi,

look here:
https://github.com/adelevie/parse_resource/blob/master/lib/parse_resource/base.rb#L48
and
https://github.com/adelevie/parse_resource/blob/master/lib/parse_resource/base.rb#L498

This does nothing than setting @attributes hash and it's misleading.
Example:
```ruby
class Note < ParseResource::Base
fields :body
validates :body, :presence => true
end

# 1) OK
n = Note.new(:body => "some text")
n.body => "some text"
n.save => true

# 2) OK
n = Note.new
n.body = "some text"
n.body => "some text"
n.save => true

# 3) FAIL
n = Note.new
n.attributes = {:body => "some text" }
n.body => nil
n.save => false

# it should set the value of body attribute as in AR

# my hackish solution for now:
class ParseResource::Base
def unsaved_attributes=(value)
if value.is_a?(Hash) && value.present?
value.each do |k, v|
send "#{k}=", v
end
end
@unsaved_attributes
end
end

# I use unsaved_attributes= instead of attributes= assignment
# 4) OK
n = Note.new
n. unsaved_attributes = {:body => "some text" }
n.body => "some text"
n.save => true
```

The question is why attributes writer has been written like this?