Sha256: 15187667463eb88fe788c1ebdd7a90dc4d67706df53d5039adf442313fad6116
Contents?: true
Size: 1.99 KB
Versions: 3
Compression:
Stored size: 1.99 KB
Contents
# Neo::DCI [](http://travis-ci.org/neopoly/neo-dci) Simple DCI (Data Context Interaction). Includes Data, Roles and Context. [Gem](https://rubygems.org/gems/neo-dci) | [Source](https://github.com/neopoly/neo-dci) | [Documentation](http://rubydoc.info/github/neopoly/neo-dci/master/file/README.md) ## Installation Add this line to your application's Gemfile: gem 'neo-dci' And then execute: $ bundle Or install it yourself as: $ gem install neo-dci You can generate base classes for your roles and contexts with $ rake neo-dci:setup ## Usage ### Data ```ruby class User < ActiveRecord::Base include Neo::DCI::Data attr_accessible end ``` ### Context ```ruby class Context < Neo::DCI::Context end class RenameUserContext < Context # Define callbacks called inside a context. callbacks :success, :failure def initialize(user_id, new_name) @user = User.find(user_id) @new_name = new_name end def call @user.role_as(Renamer) if @user.rename_to(@new_name) callback.call :success, @new_name else callback.call :failure, "renaming failed" end end end ``` ### Interaction (Role) ```ruby module Renamer extend Neo::DCI::Role def rename_to(new_name) self.name = new_name save end end ``` ### Rails Controller ```ruby class UsersController < ApplicationController def rename RenameUserContext.call(current_user.id, params[:name]) do |callback| callback.on :success do |new_name| redirect_to users_path, :notice => "Renamed successfully to #{new_name}" end callback.on :failure do |error_message| render :alert => "Renaming failed: #{error_message}!" end end end end ``` ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Added some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
neo-dci-0.4.1 | README.md |
neo-dci-0.4.0 | README.md |
neo-dci-0.3.0 | README.md |