| Path: | README |
| Last Update: | Mon Jun 26 08:52:42 Mountain Daylight Time 2006 |
This library adds a partitioned_id to ease the storage partitioning of lots of files in the file system. For an id of 1, a string "0000/0001" will be returned and for an id of 12345678, a string "1234/5678" will be returned.
The default number of digits is 8, the default number of partitions is 2, and the default separator is File::SEPARATOR. You can also set the following in your rails environment.rb -
Partitioned::Id::DEFAULT_DIGITS Partitioned::Id::DEFAULT_PARTITIONS Partitioned::Id::DEFAULT_SEPARATOR
You can also customize these defaults per model (see example 2 below).
Finally, there is a partitioned_id helper for both controllers and views which take at least one parameter an Id and then optionally an options hash specifying the number of digits, partitions, and/or separator to be used.
Giving credit where credit is due, this plugin was inspired by reading:
www.37signals.com/svn/archives2/id_partitioning.php
class Folder < ActiveRecord::Base
acts_as_partitioned_id
end
f = Folder.new => #<Folder:.…..> f.save => true f.id => 1 f.partitioned_id => "0000/0001" Folder.partitioned_id(123456) => "0012/3456"
class Folder < ActiveRecord::Base
acts_as_partitioned_id :digits => 9,
:partitions => 3,
:separator => '|'
end
f = Folder.new => #<Folder:.…..> f.save => true f.id => 1 f.partitioned_id => "000|000|001" Folder.partitioned_id(123456) => "000|123|456"
In your controller…
class MyController < ApplicationController
def index
@partitioned_id = partitioned_id(252525)
end
def other
@partitioned_id = partitioned_id(1234, :digits => 9, :partitions => 3)
end
end
In your view
<%= partitioned_id(65432) %>
Install
Rubyforge project
RDocs