<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -16,7 +16,6 @@ Let's say that I have 2 models: Item and User, and Item belongs to user.  So the
     class ItemFactory
         include Mack::Data::Factory
         
-        field :id, 10, :content =&gt; :numeric, :num_start =&gt; 0, :num_end =&gt; 100000
         field :title, &quot;MyItem&quot;
         field :owner_id, {:user =&gt; 'id'}
     end
@@ -24,7 +23,6 @@ Let's say that I have 2 models: Item and User, and Item belongs to user.  So the
     class UserFactory
         include Mack::Data::Factory
         
-        field :id, 10, :content =&gt; :numeric, :num_start =&gt; 10, :num_end =&gt; 100000
         field :username, &quot;planters&quot;, :length =&gt; 25, :content =&gt; :alpha
         field :password, &quot;roastedPeanuts&quot;, :immutable =&gt; true
     end
@@ -61,7 +59,7 @@ you want to create.
 Note that if your factory has dependencies to other model (like the ItemFactory in the example), then make sure you
 have created the model that it's depending on first.
 
-** Creating Factory Chains
+** Creating Factories Execution Chain
 In some instances, you may want to create an execution chain of a bunch of factories.  In the above example: the UserFactory
 has to be run before the ItemFactory.  
 If that's the case, you can create factory chain that you can execute later.
@@ -82,7 +80,6 @@ the following:
     class UserFactory
         include Mack::Data::Factory
     
-        field :id, 10, :content =&gt; :numeric, :num_start =&gt; 10, :num_end =&gt; 100000
         field :username, &quot;planters&quot;, :length =&gt; 25, :content =&gt; :alpha
         field :password, &quot;roastedPeanuts&quot;, :immutable =&gt; true
         
@@ -97,6 +94,23 @@ The above example defined a scoping for &quot;long_username&quot;, which you can use by ca
 When a scope is defined and called, the field defined in the block will overwrite the default field listing 
 in that class.  Scopes in the factory is independent to each other, and one scope cannot affect the others.
 
+** Custom content generator
+In some cases, the default content generators that are provided by this framework don't fit your needs.
+To accommodate this situation, you can provide a custom content generator for each field you defined by 
+passing in a proc.  
+
+Example:
+I'm creating a users, but I don't want the username be totally random, instead I want it to use the default
+name I provide, and append 0-n at the end of the string to represent the Nth user in the list.  Here's how to
+accomplish that:
+    class UserFactory
+        include Mack::Data::Factory
+        
+        field :username, &quot;planters&quot; { |def_value, rules, index| &quot;#{def_value}#{index}&quot; }
+        field :password, &quot;roastedPeanuts&quot;, :immutable =&gt; true
+        
+    end
+
 == Contact
 Please mail bugs, suggestions, and patches to darsono.sutedja@gmail.com
 </diff>
      <filename>mack-data_factory/README</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ module Mack
       class FieldContentGenerator
         class &lt;&lt; self
           def alpha_generator
-            @alpha_gen = Proc.new do |def_value, rules|
+            @alpha_gen = Proc.new do |def_value, rules, index|
               words = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat)
 
               length = 128
@@ -45,7 +45,7 @@ module Mack
           end
 
           def alpha_numeric_generator
-            @alpha_numeric_gen = Proc.new do |def_value, rules|
+            @alpha_numeric_gen = Proc.new do |def_value, rules, index|
               words = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat)
 
               length = 128
@@ -85,7 +85,7 @@ module Mack
           end
 
           def numeric_generator
-            @numeric_gen = Proc.new do |def_value, rules|
+            @numeric_gen = Proc.new do |def_value, rules, index|
               n_start = rules[:start_num] || 0
               n_end   = rules[:end_num] || 1000
 
@@ -96,49 +96,49 @@ module Mack
           end
 
           def date_generator
-            @date_gen = Proc.new do |def_value, rules|
+            @date_gen = Proc.new do |def_value, rules, index|
               Time.now.to_s
             end
             return @date_gen
           end
 
           def date_time_generator
-            @date_time_gen = Proc.new do |def_value, rules|
+            @date_time_gen = Proc.new do |def_value, rules, index|
               Time.now.to_s
             end
             return @date_time_gen
           end
 
           def email_generator
-            @email_gen = Proc.new do |def_value, rules|
+            @email_gen = Proc.new do |def_value, rules, index|
               Faker::Internet.free_email
             end
             return @email_gen
           end
 
           def firstname_generator
-            @fn_gen = Proc.new do |def_value, rules|
+            @fn_gen = Proc.new do |def_value, rules, index|
               Faker::Name.first_name
             end
             return @fn_gen
           end
 
           def lastname_generator
-            @ln_gen = Proc.new do |def_value, rules|
+            @ln_gen = Proc.new do |def_value, rules, index|
               Faker::Name.last_name
             end
             return @ln_gen
           end
 
           def phone_generator
-            @phone_gen = Proc.new do |def_value, rules|
+            @phone_gen = Proc.new do |def_value, rules, index|
               Faker::PhoneNumber.phone_number
             end
             return @phone_gen
           end
 
           def company_generator
-            @company_gen = Proc.new do |def_value, rules|
+            @company_gen = Proc.new do |def_value, rules, index|
               str = Faker::Company.name
 
               if rules[:include_bs]
@@ -151,7 +151,7 @@ module Mack
           end
 
           def name_generator
-            @name_gen = Proc.new do |def_value, rules|
+            @name_gen = Proc.new do |def_value, rules, index|
               Faker::Name.name
             end
             return @name_gen</diff>
      <filename>mack-data_factory/lib/mack-data_factory/content_generator.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,17 @@
 module Mack
   module Data
+    #
+    # Add factory capability to a class.
+    # 
+    # A factory is able to define which field it want to generate content for,
+    # define a scope for different situation, and set a custom content generator 
+    # for field that doesn't want to use the default content generator.
+    #
+    # For more information and usage, please read README file
+    #
+    # author: Darsono Sutedja
+    # July 2008
+    #
     module Factory      
       
       # make sure the data factory API is available to the class that includes it
@@ -9,20 +21,39 @@ module Mack
       
       module ClassMethods
         
+        #
+        # Run the factory to produce n number of objects.
+        #
+        # Example:
+        # class CarFactory
+        #    include Mack::Data::Factory
+        #    field :name, &quot;honda&quot; { |def_value, rules, index| &quot;#{def_value} #{['civic', 'accord', 'pilot'].randomize[0]}&quot;}
+        # end
+        #
+        # CarFactory.create(100) #=&gt; will produce 100 cars whose name is &quot;honda xxx&quot; where xxx is a random item from ['civic', 'accord', 'pilot']
+        #
+        # params:
+        # * num - how many objects to produce
+        # * scope - run the factory in a named scope
+        #
         def create(num, scope = :default)
           factory_name = self.name.underscore
+          
+          # retrieve the model name from the factory class. 
           model_name = factory_name.gsub('_factory', '')
-          #puts &quot;creating #{num} instances of #{model_name.camelcase}&quot;
           
+          # if user is running custom scope, then merge the fields 
+          # defined for that scope with the default one, before we run the factory
           scoped_fields = field_manager.scopes[scope]
           fields = field_manager.scopes[:default].merge(scoped_fields)
           
           num.times do |i|
+            #puts &quot;Creating #{model_name} ##{i+1}&quot;
             obj = model_name.camelcase.constantize.new
             
             fields.each_pair do |k, v|
               field_name = k.to_s
-              field_value = v.get_value
+              field_value = v.get_value(i)
               assert_method(obj, &quot;#{field_name}=&quot;, &quot;#{model_name.camelcase} doesn't have #{field_name}= method!&quot;) do
                 obj.send(&quot;#{field_name}=&quot;, field_value)
               end
@@ -34,10 +65,18 @@ module Mack
           end
         end
         
+        #
+        # Define a field with its default value and rules and an optional content generator
+        # for this factory
+        #
         def field(model_attrib_sym, default_value, options = {}, &amp;block)
           field_manager.add(scope, model_attrib_sym, default_value, options, &amp;block)
         end
         
+        # 
+        # Define a scope in the factory.
+        # Any field defined in a scope will overwrite its cousin in the default scope.
+        #
         def scope_for(tag)
           set_scope(tag)
           yield</diff>
      <filename>mack-data_factory/lib/mack-data_factory/data_factory.rb</filename>
    </modified>
    <modified>
      <diff>@@ -31,7 +31,7 @@ module Mack
         self.field_value_producer = Mack::Data::Factory::FieldContentGenerator.send(&quot;#{field_rules[:content]}_generator&quot;)
       end
       
-      def get_value
+      def get_value(index = 0)
         # return the field_value immediately if the rule states that it's immutable
         return field_value if field_rules[:immutable]
         
@@ -43,16 +43,15 @@ module Mack
           begin
             owner_model = owner.to_s.camelcase.constantize
             bridge = Mack::Data::Bridge.new
-            self.field_value = (bridge.get(owner_model, rand(bridge.count(owner_model)))).send(key)
-            return self.field_value
-            #self.field_value = owner_model.get(rand(owner_model.count)).send(key)
+            value = bridge.get_first(owner_model).send(key)
+            return value
           rescue Exception
             Mack.logger.warn &quot;WARNING: DataFactory: field_value for #{field_name} is not set properly because data relationship defined is not correct&quot;
           end
         end
         
         # must generate random string and also respect the rules
-        field_value_producer.call(field_value, field_rules)
+        field_value_producer.call(field_value, field_rules, index)
       end
     end
   end</diff>
      <filename>mack-data_factory/lib/mack-data_factory/field.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,6 +15,10 @@ module Mack
         handler(obj).get(obj, *args)
       end
       
+      def get_first(obj, *args)
+        handler(obj).get_first(obj, *args)
+      end
+      
       def count(obj, *args)
         handler(obj).count(obj, *args)
       end</diff>
      <filename>mack-data_factory/lib/mack-data_factory/orm_api_bridge/bridge.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ module Mack
         
         def can_handle(obj)
           return false if !Object.const_defined?('ActiveRecord')
-          return obj.is_a?(::ActiveRecord::Base)
+          return obj.ancestors.include?(::ActiveRecord::Base)
         end
         
         def get(obj, *args)
@@ -20,6 +20,10 @@ module Mack
           obj.save
         end
         
+        def get_first(obj, *args)
+          obj.find(:first, *args)
+        end
+        
       end
     end
   end</diff>
      <filename>mack-data_factory/lib/mack-data_factory/orm_api_bridge/orm/active_record.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ module Mack
         
         def can_handle(obj)
           return false if !Object.const_defined?('DataMapper')
-          return obj.is_a?(::DataMapper::Resource)
+          return obj.ancestors.include?(::DataMapper::Resource)
         end
         
         def get(obj, *args)
@@ -20,6 +20,10 @@ module Mack
           obj.save
         end
         
+        def get_first(obj, *args)
+          obj.first(*args)
+        end
+        
       end
     end
   end</diff>
      <filename>mack-data_factory/lib/mack-data_factory/orm_api_bridge/orm/data_mapper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -19,6 +19,11 @@ module Mack
           Mack.logger.warn &quot;Mack::Data::OrmBridge: You don't have supported orm api handler installed.&quot;
         end
         
+        def get_first(obj, *args)
+          Mack.logger.warn &quot;Mack::Data::OrmBridge: You don't have supported orm api handler installed.&quot;
+        end
+        
+        
       end
     end
   end</diff>
      <filename>mack-data_factory/lib/mack-data_factory/orm_api_bridge/orm/default.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>13fd05b1694d921fb72e75647e91bf5e2606a5e0</id>
    </parent>
  </parents>
  <author>
    <name>dsutedja</name>
    <email>dsutedja@helium.com</email>
  </author>
  <url>http://github.com/markbates/mack-more/commit/7c4fa2fa4bbb54aa24792c544e2a72cb47722ea7</url>
  <id>7c4fa2fa4bbb54aa24792c544e2a72cb47722ea7</id>
  <committed-date>2008-07-30T07:00:20-07:00</committed-date>
  <authored-date>2008-07-30T07:00:20-07:00</authored-date>
  <message>Mack Data Factory [#14 state:resolved]</message>
  <tree>d4632acc5017f96db4d1d0eaf49ab566dbc27041</tree>
  <committer>
    <name>dsutedja</name>
    <email>dsutedja@helium.com</email>
  </committer>
</commit>
