Showing posts with label plugin. Show all posts
Showing posts with label plugin. Show all posts

Friday, March 16, 2007

Acts As State Machine plugin

I just finished reading Bruce Tate article, Crossing borders: Extensions in Rails (The anatomy of an acts_as plug-in), where he mentioned the acts_as_state_machine plugin for Rails. If you ever have model with known transition paths between different states then this plugin will be a great help to you.

Here is an article, The Complete Guide to Rails Plugins: Part 1, on Nuby on Rails showing how to install and create Rails plugin.

And finally, you can go to the acts_as_state_machine plugin's author blog, Acts As State Machine, to see where to download and how to use the plugin.

Here is my example of how to use the plugin to keep track of a light fixture with three state (off, low, and high).

# The Migration class for light
class CreateLights < ActiveRecord::Migration
def self.up
create_table :lights do |t|
t.column :name, :string
t.column :status, :string
end
end

def self.down
drop_table :lights
end
end

# The Model for light

# A simple transition for a light with three states, (off, low, high)
#
# +---------+ switch +---------+ switch +---------+
# | off |-------->| low |-------->| high |
# +---------+ +---------+ +---------+
# ^ |
# |_________________________________________|
#
class Light < ActiveRecord::Base
acts_as_state_machine :initial => :off, :column => 'status'

state :off
state :low
state :high

event :switch do
transitions :from => :off, :to => :low
transitions :from => :low, :to => :high
transitions :from => :high, :to => :off
end
end

-------------------------
Here is a sample run:

>> l = Light.create
=> ...
>> l.current_state
=> :off
>> l.switch!
=> nil
>> l.current_state
=> :low
>> l.switch!
=> nil
>> l.current_state
=> :high
>> l.switch!
=> nil
>> l.current_state
=> :off

Sunday, February 11, 2007

GeoKit

Andre Lewis from Web 2.0 Technologies website has published a new plugin for Rails that does geocoding, location fingers, and distance calculation.

Description from website:
Geokit is a Rails plugin for building location-based apps. It provides geocoding, location finders, and distance calculation in one cohesive package. If you have any tables with latitude/longitude oolumns in your database, or if you every wanted to easily query for "all the stores within a 50 mile radius," then GeoKit is for you.

GeoKit: a plugin for location-based Rails apps
- Web 2.0 Technologies

In-memory and in-database distance calculations -Web 2.0 Technologies

Monday, February 05, 2007

Paging in Rails

The author of ERR THE BLOG finds paging in Rails not up to his standard so he wrote his own paging code. He packed it up as a plugin and now we all can enjoy the fruit of his labor. There are some interesting comments to his blog entry that you might want to take a look.

I Will Paginate - ERR THE BLOG

Sunday, February 04, 2007

Hpricot - HTML Parser for Ruby

Hpricot - HTML Parser for Ruby

Active Merchant

Active Merchant is a payment library extracted from Shopify. Here is an article, Processing Credit Cards with Ruby on Rails, on how to use it with Authorize.net payment gateway from OmniNerd.

The list of supported payment gateways from Active Merchant website.

Direct payment gateways:

  • Authorize.net
  • Moneris
  • TrustCommerce
  • LinkPoint
  • Psigate
  • Paypal Payments Pro
  • Eway
  • USA ePay
  • Paypal Payflow Pro (Testing)

Offsite payment gateways:

  • Paypal
  • Chronopay
  • Nochex

Friday, February 02, 2007

Piston

Piston

If you use svn:externals to manage plugins for your rails application then this utility will definitely make your life easier. It allows you to keep a copy of the plugin in your local repository and also allows you to update it with the external source.

What is the benefit of having a local copy of the plugin in your repository versus using svn:external? When you do svn update, it will be a lot faster since it doesn't need to go out to external repositories to check for updates.

When you want to sync the plugin with the external source, all you have to do is type:

$piston update vendor/rails

and then

$svn commit --message "sync up plugins with external source"

Life couldn't be easier.