Sha256: 6c7dca27090264bcbb413e0ea43e901bb0f9164d161127201a211bf32831195e
Contents?: true
Size: 1.4 KB
Versions: 1
Compression:
Stored size: 1.4 KB
Contents
# Yaoc Indentation of this gem is to learn and train a little ruby. ## Installation Add this line to your application's Gemfile: gem 'yaoc' And then execute: $ bundle Or install it yourself as: $ gem install yaoc ## Usage 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 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) 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 1. Fork it ( http://github.com/<my-github-username>/yaoc/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
yaoc-0.0.2 | README.md |