README.md in yaoc-0.0.1 vs README.md in yaoc-0.0.2
- old
+ new
@@ -20,29 +20,53 @@
Uptodate doc's look into the specs.
```ruby
+require 'yaoc'
+
User = Struct.new(:id, :name) do
def initialize(params={})
super()
params.each do |attr, value|
self.public_send("#{attr}=", value)
end if params
end
end
-mapper = Yaoc::ObjectMapper.new(User).tap do |mapper|
+OldUser = Struct.new(:id, :fullname) do
+ def initialize(params={})
+ super()
+
+ params.each do |attr, value|
+ self.public_send("#{attr}=", value)
+ end if params
+ end
+end
+
+mapper = Yaoc::ObjectMapper.new(User, OldUser).tap do |mapper|
mapper.add_mapping do
+ fetcher :public_send
rule to: :name, from: :fullname
rule to: :id
end
end
+old_user = OldUser.new({id: 1, fullname: "myname" })
+new_user = mapper.load(old_user)
-user = mapper.load({id: 1, fullname: "myname" })
+puts old_user
+puts new_user
+
+new_user.name = "no name"
+
+puts mapper.dump(new_user)
+
+#<struct OldUser id=1, fullname="myname">
+#<struct User id=1, name="myname">
+#<struct OldUser id=1, fullname="no name">
```
## Contributing