Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rosylilly/active_strategy
Extract the business logic from the model
https://github.com/rosylilly/active_strategy
Last synced: 5 days ago
JSON representation
Extract the business logic from the model
- Host: GitHub
- URL: https://github.com/rosylilly/active_strategy
- Owner: rosylilly
- License: mit
- Created: 2012-12-22T07:15:04.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2012-12-22T19:04:39.000Z (about 12 years ago)
- Last Synced: 2024-12-22T13:14:49.923Z (15 days ago)
- Language: Ruby
- Homepage: htts://github.com/rosylilly/active_strategy
- Size: 207 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.mkd
- License: MIT-LICENSE
Awesome Lists containing this project
README
# ActiveStrategy
[![Build Status](https://travis-ci.org/rosylilly/active_strategy.png?branch=master)](https://travis-ci.org/rosylilly/active_strategy)
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/rosylilly/active_strategy)
[![Dependency Status](https://gemnasium.com/rosylilly/active_strategy.png)](https://gemnasium.com/rosylilly/active_strategy)Extract the business logic from the model.
# Usage
1. bundle `active_strategy` gem
2. create a strategy class. For example, a strategy for a `login` method should be named `LoginStrategy`. You can use the generator for doing this (`$ rails generate strategy Login`)# Examples
```ruby
# app/models/user.rb
class User < ActiveRecord::Base
include ActiveStrategy::Contextstrategy :login, class_method: true
attr_accessible :email, :password
end# app/strategies/login_strategy.rb
class LoginStrategy
include ActiveStrategy::Strategydef login(email, password)
user = @class.where(:email => email).firstreturn user.try(:password) == password ? user : nil
end
end# app/controllers/authenticate_controller.rb
class AuthenticateController < ApplicationControlelr
def login
session[:user_id] = User.login(params[:email], params[:password])
end
end
```# Copyright
Copyright (c) 2012 Sho Kusano. See MIT-LICENSE for further details.