README.md in materialist-0.0.2 vs README.md in materialist-0.0.3

- old
+ new

@@ -6,12 +6,56 @@ materializing the remote resource (described by the event) in database. This library is a set of utilities that provide both the wiring and the DSL to painlessly do so. -### Configuration +### Install +In your `gemfile` + +```ruby +gem 'materialist' +``` + +Then do + +```bash +bundle +``` + +### Entity + +Your materialised entity need to have a **unique** `source_url` column, alongside any other field you wish to materialise. + +```ruby +class CreateZones < ActiveRecord::Migration[5.0] + def change + create_table :zones do |t| + t.integer :orderweb_id + t.string :code, null: false + t.string :name + t.string :timezone + t.string :country_name + t.string :country_iso_alpha2_code + t.string :source_url + + t.timestamps + + t.index :code, unique: true + t.index :source_url, unique: true + end + end +end +``` + +```ruby +class Zone < ApplicationRecord +end +``` + +### Routemaster Configuration + First you need an "event handler": ```ruby handler = Materialist::EventHandler.new({ ...options }) ``` @@ -100,11 +144,11 @@ #### `link <key>` describes materializing from a relation of the resource. This can be nested to any depth as shown above. When inside the block of a `link` any other part of DSL can be used and will be evaluated in the context of the relation resource. -#### `after_upsert <method>` +#### `after_upsert <method>` -- also `after_destroy` describes the name of the instance method to be invoked after a record was materialized. ```ruby class ZoneMaterializer include Materialist::Materializer @@ -131,12 +175,19 @@ source_link_reader :city source_link_reader :country, via: :city end ``` -Above will give you `.source`, `.city` and `.country` on any instances of `Rider`, allowing you to access remote keys. +#### DSL +- `source_link_reader <key>, via: <key> (default: none), allow_nil: true/false (default: false)`: Adds a method named `<key>` to the class giving access to the specified linked resource. If `allow_nil` is set to `false` (default) and error is raised if the resource is missing. + +The above example will give you `.source`, `.city` and `.country` on any instances of `Rider`, allowing you to access remote resources. + e.g. ```ruby -Rider.last.country.created_at +rider = Rider.last +rider.source.name +rider.city.code +rider.country.created_at ```