README.md in signal-0.2.2 vs README.md in signal-0.3.0

- old
+ new

@@ -170,17 +170,59 @@ ```ruby class UsersController < ApplicationController def create @user = User.new(user_params) + Signup.new(@user) .on(:success) { redirect_to login_path, notice: 'Welcome to MyApp!' } .on(:failure) { render :new } + .call end end ``` +If you're using plain ActiveRecord, just do something like the following: + +```ruby +class UsersController < ApplicationController + def create + @user = User.new(user_params) + @user + .on(:create) { redirect_to login_path, notice: 'Welcome to MyApp!' } + .on(:validation) { render :new } + .save + end +end +``` + +### Signal::Call + +You can include `Signal::Call` instead, so you can have a common interface for your observable object. This will add the `.call()` method to the target class, which will delegate attributes to the observable's `initialize` method and call its `call` method. + +```ruby +class Contact + include Signal.call + + attr_reader :name, :email + + def initialize(name, email) + @name, @email = name, email + end + + def call + emit(:output, self) + end +end + +Contact.call('John', 'john@example.com') do |o| + o.on(:output) {|contact| puts contact } +end +``` + +Notice that you don't have to explicit call the instance's `call` method; `Contact.call` will initialize the object with all the provided parameters and call `Contact#call` after the block has been executed. + ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) @@ -195,10 +237,10 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to +distribute, sub-license, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.