Skip to content
Simple DCI
Ruby
Branch: master
Clone or download
Peter Suschlik
Peter Suschlik Release 0.5.1
Latest commit 0b0fb6f Aug 9, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Release 0.5.1 Aug 9, 2016
test Travis: Add more Ruby versions Feb 12, 2015
.gitignore Initial commit. Aug 9, 2012
.simplecov Add simplecov. Aug 9, 2012
.travis.yml Drop support for Ruby 1.9.3 and 2.0 supporting 2.3.1 Jul 26, 2016
Gemfile Travis: Add more Ruby versions Feb 12, 2015
LICENSE Initial commit. Aug 9, 2012
README.md Travis: Add more Ruby versions Feb 12, 2015
Rakefile
neo-dci.gemspec

README.md

Neo::DCI

Simple DCI (Data Context Interaction). Includes Data, Roles and Context.

Travis Gem Version Code Climate Test Coverage Inline docs

Gem | Source | Documentation

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

class User < ActiveRecord::Base
  include Neo::DCI::Data

  attr_accessible
end

Context

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)

module Renamer
  extend Neo::DCI::Role

  def rename_to(new_name)
    self.name = new_name
    save
  end
end

Rails Controller

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 ( https://github.com/neopoly/neo-dci/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
You can’t perform that action at this time.