mustmodify / valuable

quick ruby modeling -- basically attr_accessor with default values, light-weight casting, and a constructor
http://valuable.mustmodify.com/
MIT License
72 stars 3 forks source link

Model.new(a).to_hash.should == a #18

Open mustmodify opened 9 years ago

mustmodify commented 9 years ago

Implement the following test:

class Valuable
  def to_hash
    attributes.to_hash
  end
end

class Phone < Valuable
  has_value :area_code
  has_value :exchange
  has_value :last_four
end

class Person < Valuable
  has_value :name
  has_value :age
  has_collection :phones, :klass => Phone
end

a = {
  name: 'Dylan',
  age: 'teenager / rude',
  phones: [
    {
      area_code: '111',
      exchange: '234',
      last_four: '4567'
    },
  ]
}

Person.new(a).to_hash.should == a