Simple DCI (Data Context Interaction). Includes Data, Roles and Context.
Gem | Source | Documentation
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
class User < ActiveRecord::Base
include Neo::DCI::Data
attr_accessible
end
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
module Renamer
extend Neo::DCI::Role
def rename_to(new_name)
self.name = new_name
save
end
end
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
- Fork it ( https://github.com/neopoly/neo-dci/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request