0.0
No commit activity in last 3 years
No release in over 3 years
Adds the DSL for ANAF for Ripple, an ORM for Riak
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
~> 2.0.0.beta.19

Runtime

= 0.8.0
 Project Readme

ripple-anaf¶ ↑

This is inspired and similar implementation to the ‘accepts_nested_attributes` functionality found in AR. This allows the use update attributes and create new child records through the parent. It also allows the use of the `fields_for` form view helper, using a presenter pattern.

To enable in the model, call the class method, using the same relationship as defined in the ‘one` or `many`.

class Shipment
  include Ripple::Document
  property :identifier, String

  one :box
  many :addresses
  many :checkpoints

  accepts_nested_attributes_for :box, :addresses
  accepts_nested_attributes_for :checkpoints, :allow_destroy => true, :reject_if => proc{|attrs| attrs['signed_off'].blank? }
end

Now, you can do things like this:

Shipment.create(
  :identifier => '1Z0001', 
  :box_attributes => { :weight => 1.4 }, 
  :addresses_attributes => [ { :street => "Main Street" } ] 
)

And in your views you can use fields_for:

<%= form_for(@shipment) do |f| %>

  <%= f.text_field :identifier %>

  <%=  f.fields_for :box do |ff| %>
    <%= ff.text_field :weight %>
  <% end %>

<% end %>

Installation¶ ↑

Currently in pre-release for testing.

gem install ripple-anaf --pre

Supported Features¶ ↑

  • Same DSL for linked and embedded documents

  • :reject_if

  • :allow_destroy

Note on Patches/Pull Requests¶ ↑

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Brian Kaney. See LICENSE for details.