README.md in yaoc-0.0.6 vs README.md in yaoc-0.0.7

- old
+ new

@@ -1,8 +1,8 @@ # Yaoc [![Code Climate](https://codeclimate.com/github/slowjack2k/yaoc.png)](https://codeclimate.com/github/slowjack2k/yaoc) [![Build Status](https://travis-ci.org/slowjack2k/yaoc.png?branch=master)](https://travis-ci.org/slowjack2k/yaoc) [![Coverage Status](https://coveralls.io/repos/slowjack2k/yaoc/badge.png?branch=master)](https://coveralls.io/r/slowjack2k/yaoc?branch=master) [![Gem Version](https://badge.fury.io/rb/yaoc.png)](http://badge.fury.io/rb/yaoc) -Indentation of this gem is to learn and train a little ruby. +Converting one ruby object into another with some rules. ## Installation Add this line to your application's Gemfile: @@ -302,9 +302,60 @@ puts new_user5 #<struct OldUser5 id=1, name="my fullname"> #<struct RoleThing id=1, role="my_role"> #<struct User5 id=1, name="my fullname", role="my_role"> + +``` + +### How can I lazy load some expensive to convert attributes? + +```ruby +require 'yaoc' + +include Yaoc::Helper + +puts "\n" * 5 + + +OldUser6 = StructHE(:id) do + + def names=(new_names) + @names = new_names + end + + def names + puts 'some expensive operation in progress ...' + sleep 10 + @names + end + +end +User6 = StructHE(:id, :names) + + +user_mapper = Yaoc::ObjectMapper.new(User6, OldUser6).tap do |mapper| + mapper.add_mapping do + fetcher :public_send + rule to: [:id, :names], + lazy_loading: [false, true] + end +end + +old_user6 = OldUser6.new(id: 'my_id_1', names: ['one', 'two', 'three', 'four']) +new_user6 = user_mapper.load(old_user6) + +puts new_user6.id.inspect +puts new_user6.names.inspect +puts new_user6 + + +puts "\n" * 5 + +# "my_id_1" +# some expensive operation in progress ... +# ["one", "two", "three", "four"] +#<struct User6 id="my_id_1", names=["one", "two", "three", "four"]> ``` ## Contributing