<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>rdoc/.tmp_index.html.72103~</filename>
    </added>
    <added>
      <filename>rdoc/classes/ActsAsRandomId.html</filename>
    </added>
    <added>
      <filename>rdoc/classes/ActsAsRandomId/ClassMethods.html</filename>
    </added>
    <added>
      <filename>rdoc/classes/ActsAsRandomId/InstanceMethods.html</filename>
    </added>
    <added>
      <filename>rdoc/created.rid</filename>
    </added>
    <added>
      <filename>rdoc/files/README.html</filename>
    </added>
    <added>
      <filename>rdoc/files/lib/acts_as_random_id_rb.html</filename>
    </added>
    <added>
      <filename>rdoc/fr_class_index.html</filename>
    </added>
    <added>
      <filename>rdoc/fr_file_index.html</filename>
    </added>
    <added>
      <filename>rdoc/fr_method_index.html</filename>
    </added>
    <added>
      <filename>rdoc/index.html</filename>
    </added>
    <added>
      <filename>rdoc/rdoc-style.css</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -7,8 +7,16 @@ Generating unique random id for ActiveRecord models
 Example
 =======
 
-class Comment &lt; ActiveRecord::Base
-  acts_as_random_id
-end
+  class Comment &lt; ActiveRecord::Base
+    acts_as_random_id
+  end
+  
+  class Group &lt; ActiveRecord::Base
+    acts_as_random_id :generator =&gt; :auto_increment
+  end
+  
+  class Article &lt; ActiveRecord::Base
+    acts_as_random_id :generator =&gt; Proc.new { Time.now.to_i }
+  end
 
 Copyright (c) 2009 hashtrain.com, released under the MIT license</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -20,7 +20,7 @@ end
 desc 'Generate documentation for the acts_as_random_id plugin.'
 Rake::RDocTask.new(:rdoc) do |rdoc|
   rdoc.rdoc_dir = 'rdoc'
-  rdoc.title    = 'ActAsRandomId'
+  rdoc.title    = 'ActsAsRandomId'
   rdoc.options &lt;&lt; '--line-numbers' &lt;&lt; '--inline-source'
   rdoc.rdoc_files.include('README')
   rdoc.rdoc_files.include('lib/**/*.rb')
@@ -38,7 +38,7 @@ PKG_FILES = FileList[
 
 spec = Gem::Specification.new do |s| 
    s.name             = &quot;acts_as_random_id&quot; 
-   s.version          = &quot;0.0.1&quot;
+   s.version          = &quot;0.1.2&quot;
    s.author           = &quot;hashtrain.com and author idea Stanislav Pogrebnyak&quot;
    s.email            = &quot;mail@hashtrain.com&quot;
    s.homepage         = &quot;http://hashtrain.com/&quot;</diff>
      <filename>Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -1,19 +1,3 @@
-# ActsAsRandomId
-# Generate unique ID: XXXXXXYYYYY
-#
-# where
-# - XXXXXX - result returned on request SELECT max (primary_key) FROM table_name minus 5 right numbers (YYYYY) plus rand (20) - get the next increment value
-# - YYYYY - the result of the function rand (first 5 or last 5 numbers)
-#
-# So we will always have 1 extra SQL and a unique id of the object
-# The model will look like this:
-#
-# class Comment &lt;ActiveRecord:: Base
-#   Act_as_random_id # this plugin
-# end
-#
-# When a pattern is not broken at the connection object and it will work with all known me DB
-
 module ActsAsRandomId
   def self.included(base)
     base.send :extend, ClassMethods 
@@ -21,36 +5,34 @@ module ActsAsRandomId
 
   module ClassMethods 
     def acts_as_random_id(options = {})
-      cattr_accessor :random_id_type, :random_id_step
+      cattr_accessor :random_id_generator 
       before_create  :generate_random_id
 
-      self.random_id_type = (options[:type] || :auto_increment)
-      self.random_id_step = (options[:step] || 10).to_i
-      self.random_id_step = 1 if self.random_id_step &lt;= 0
+      self.random_id_generator = (options[:generator] || :random_id)
 
       def generate_random_id
-        case self.random_id_type
-        when :auto_increment
-          auto_increment
+        if self.random_id_generator.is_a?(Proc)
+          self.random_id_generator.call
+        elsif self.random_id_generator == :auto_increment
+          self.auto_increment
         else
-          indentation_right
+          self.random_id
         end
       end
-      
+
+      protected
       def auto_increment
-        max_id = ActiveRecord::Base.connection.select_value(&quot;SELECT max(#{self.primary_key}) FROM #{self.table_name}&quot;).to_i
-        max_id + self.random_id_step
+        current_id  = ActiveRecord::Base.connection.select_value(&quot;SELECT max(#{self.primary_key}) FROM #{self.table_name}&quot;).to_i
+        current_id += rand(10) + 1
       end
-      
-      def indentation_right
-        max_id                 = ActiveRecord::Base.connection.select_value(&quot;SELECT max(#{self.primary_key}) FROM #{self.table_name}&quot;)
-        max_id_size            = max_id.to_s.size
-        current_auto_incriment = (max_id_size &gt; 5) ? max_id.to_s.first(max_id_size - 5).to_i : max_id.to_i
-        new_auto_incriment     = (current_auto_incriment + rand(self.random_id_step) + 1).to_i
-        new_id                 = (new_auto_incriment.to_s + rand.to_s.last(5).to_s).to_i
-        new_id
+
+      def random_id
+        begin
+          rand_id = rand(2_147_483_647) + 1 #- mysql type &quot;int 4 bytes&quot;
+        end until ActiveRecord::Base.connection.select_value(&quot;SELECT #{self.primary_key} FROM #{self.table_name} WHERE #{self.primary_key} = #{rand_id}&quot;).blank?
+        rand_id
       end
-      
+
       send :include, InstanceMethods
     end
   end</diff>
      <filename>lib/acts_as_random_id.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
 # desc &quot;Explaining what the task does&quot;
-# task :act_as_random_id do
+# task :acts_as_random_id do
 #   # Task goes here
 # end</diff>
      <filename>tasks/acts_as_random_id_tasks.rake</filename>
    </modified>
    <modified>
      <diff>@@ -7,20 +7,35 @@ class ActsAsRandomIdTest &lt; Test::Unit::TestCase
   class Comment &lt; ActiveRecord::Base
     acts_as_random_id
   end
+  
+  class Group &lt; ActiveRecord::Base
+    acts_as_random_id :generator =&gt; :auto_increment
+  end
+  
+  class Article &lt; ActiveRecord::Base
+    acts_as_random_id :generator =&gt; Proc.new { Time.now.to_i }
+  end
 
   def test_should_empty
     assert_equal [], Comment.all
   end
-
-  def test_shouul_create_with_rundom_id
-    last_id = 0
+  
+  def test_type_random_id
+    assert Comment.generate_random_id
+    assert Comment.create
+  end
+  
+  def test_type_auto_incriment
+    assert Group.generate_random_id
+    g1 = Group.create
+    g2 = Group.create
     
-    9.times do |i|
-      c = Comment.create(:comment =&gt; &quot;comment_text_#{i}&quot;)
-      assert false unless c.id &gt; last_id
-      last_id = c.id
-    end
-    assert true
+    assert g1.id &lt; g2.id 
+  end
+  
+  def test_generator_proc
+    puts Article.generate_random_id
+    assert Article.generate_random_id
   end
 
 end</diff>
      <filename>test/acts_as_random_id_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,18 @@ ActiveRecord::Schema.define(:version =&gt; 20090217091952) do
 
   create_table &quot;comments&quot;, :force =&gt; true do |t|
     t.text     &quot;comment&quot;
-    t.integer  &quot;user_id&quot;
+    t.datetime &quot;created_at&quot;
+    t.datetime &quot;updated_at&quot;
+  end
+  
+  create_table &quot;groups&quot;, :force =&gt; true do |t|
+    t.string   &quot;name&quot;
+    t.datetime &quot;created_at&quot;
+    t.datetime &quot;updated_at&quot;
+  end
+  
+  create_table &quot;articles&quot;, :force =&gt; true do |t|
+    t.text     &quot;content&quot;
     t.datetime &quot;created_at&quot;
     t.datetime &quot;updated_at&quot;
   end</diff>
      <filename>test/schema.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>pkg/act_as_random_id-0.0.1.gem</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>61b04d4811367ef005e162364032ba7984927bb9</id>
    </parent>
  </parents>
  <author>
    <name>Shaliko Usubov</name>
    <email>shaliko@ezid.ru</email>
  </author>
  <url>http://github.com/hashtrain/acts_as_random_id/commit/83b5637b0c245985c85c08776e57a8c37e8a03f1</url>
  <id>83b5637b0c245985c85c08776e57a8c37e8a03f1</id>
  <committed-date>2009-04-26T03:12:05-07:00</committed-date>
  <authored-date>2009-04-26T03:12:05-07:00</authored-date>
  <message>Version 0.1.2</message>
  <tree>8fd67353b2312a6630ef81ab322013e55c6eed30</tree>
  <committer>
    <name>Shaliko Usubov</name>
    <email>shaliko@ezid.ru</email>
  </committer>
</commit>
