README.md in rep-0.0.1 vs README.md in rep-0.0.2

- old
+ new

@@ -50,29 +50,23 @@ $ gem install rep ## Usage -`include Rep` into any class and it is endowed with a `#to_json` method, -among other things. You describe the top level keys you want for your -json with the `::fields` method. The values for the fields are expected -to be returned from methods on the object of the same name. +`include Rep` into any class. See [nathanherald.com/rep](http://nathanherald.com/rep) for complete docs on every method. -If a class has `fields :one => :default`, then `def one; 1; end` is -expected. - ## Examples ```ruby # imagine Photo is an ActiveRecord model with fields for title, exif, location, and user_id class PhotoRep include Rep initialize_with :photo - json_fields [:url, :title, :exif, :location, :user] => :default + fields [:url, :title, :exif, :location, :user] => :default forward [:title, :exif, :location] => :photo forward :user => :user_rep def url @@ -89,24 +83,23 @@ class UserRep include Rep initialize_with :user - json_fields [:name, :email, :location] => :default - json_fields [:id, :admin].concat(json_fields(:default)) => :admin + fields [:name, :email, :location] => :default + fields [:id, :admin].concat(fields(:default)) => :admin - forward json_fields(:admin) => :user + forward fields(:admin) => :user end # You can now do crazy stuff like - UserRep.new(user: User.first).to_hash.keys # => [:name, :email, :location] # To save from creating lots of objects, you can use a shared class that is reset fresh UserRep.shared(user: User.first).to_hash # => { name: "Nathan Herald:, ... -# You can use class to proc (that makes a hash using the shared class) +# You can use class to proc (that makes a hash using the shared instance) User.all.map(&UserRep) # => [{ name: "Nathan Herald" ... # or maybe find all photos which will embed all users (and only ever make one instance each of PhotoRep and UserRep) Photo.all.map(&PhotoRep).to_json ``` @@ -115,11 +108,12 @@ You don't have to have a Rep per model and Rep's can represent multiple objects at once. It's POROs. ```ruby class ProjectReport + include Rep initialize_with :project, :active_users, :orders - fields [:name, :date, :count, :total_gross_cost, :cost_per_active_user] + fields [:name, :date, :count, :total_gross_cost, :cost_per_active_user] => :default forward :date => :project forward :count => :orders def name "#{project.name} Report"