An ActiveModel interface to FleetDB
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Armada makes it simple and easy to combine ActiveModel and FleetDB together.


To install the gem:

gem install armada

Make sure to download FleetDB and run it:

java -cp fleetdb-standalone.jar fleetdb.server -f swan.fdb

Documentation for the FleetDB server can be found at the FleetDB website.


Begin by requiring Armada in your script or application.

require "armada"

Be sure to set the timezone, as Armada currently makes use of it. = "UTC"

To start Armada with the default settings, enter the following line:

# This is the same as Armada.setup!(:address => "", :port => 3400, :password => nil)

To change the address, port, or password, Armada.setup! accepts these as keys in an option hash.

Armada.setup!(:address => "", :port => 2342, :password => "dharma")

This sets up the basic fundamentals of Armada. The following sections will detail how to fully utilize Armada's power.


Creating models in Armada is very easy. The following code creates an Airplane model with a tail number attribute.

class Airplane < Armada::Model
  add_columns :tail_number

Armada models are fully compliant with ActiveModel.

plane = => 815)

plane.persisted? #=> false
plane.destroy #=> false
plane.valid? #=> true
plane.errors #=> [] #=> true
plane.persisted? #=> true

plane.destroy #=> true
plane.persisted? #=> false

Armada models can also enjoy the added benefits of validation and automatic timestamps.

class Airplane < Armada::Model
  add_columns :tail_number, :created_at, :updated_at
  validates :tail_number, :inclusion => {:in => [815, 316]}, :uniqueness => true

plane = => 816)
plane.valid? #=> false

plane.tail_number = 316 #=> true
plane.attributes #=> {"id"=>"b20e1cmt8mmjd7dzxu7wcjyg2", "tail_number"=>316,
                      "created_at"=>1272324264, "updated_at"=>1272324264}

All Armada models are given an id if none is specified during creation. This is a requirement of FleetDB. The default generation method is generate_unique_id in Armada::Model. Note that Armada models can be treated very similarly to ActiveRecord models.


All querying is handled through instances of Armada::Relation, which handle everything. Read the FleetDB query docs for more detailed information.

plane1 = => 815)
plane2 = => 316)

# Until specified, FleetDB has no order.
Airplane.all #=> [plane1, plane2] | [plane2, plane1]

Airplane.where(:tail_number => 815).all #=> [plane1]
Airplane.where(:tail_number => 815).first #=> plane1

# Using the FleetDB count command
Airplane.where(:tail_number => 815).count #=> 1

# Armada::Relation sets :order to :asc by default
Airplane.order(:tail_number).all #=> [plane2, plane1]
Airplane.order(:tail_number => :desc).all #=> [plane1, plane1]

# Armada::Relation supports offset and limit just like SQL
Airplane.order(:tail_number).limit(1).all #=> [plane2]
Airplane.order(:tail_number).offset(1).all #=> [plane1]

# The :only option allows choosing specific attributes
Airplane.order(:tail_number).only(:tail_number).all #=> [316, 815]



Copyright © 2010 Sam Aarons, released under the MIT license