Partitioned Id plugin

Plugin details

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

Websitehttp://actsaspartid.rubyforge.org/ Repositorysvn://rubyforge.org//var/svn/actsaspartid/trunk/partitioned_id Author Brent Beardsley Tags id LicenseUnknown

Documentation

Install the plugin:
ruby script/plugin install svn://rubyforge.org//var/svn/actsaspartid/trunk/partitioned_id

Example 1

Folder.rb model

class Folder < ActiveRecord::Base

  acts_as_partitioned_id

end


execute ruby script/console

f = Folder.new => # f.save => true f.id => 1 f.partitioned_id => "0000/0001" Folder.partitioned_id(123456) => "0012/3456"


Example 2

Folder.rb model

class Folder < ActiveRecord::Base

  acts_as_partitioned_id :digits => 9,
                         :partitions => 3,
                         :separator => '|'

end


execute ruby script/console

f = Folder.new => # f.save => true f.id => 1 f.partitioned_id => "000|000|001" Folder.partitioned_id(123456) => "000|123|456"


Example 3

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


Example 4

In your view

<%= partitioned_id(65432) %> 


Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 10 months ago