mack-data_factory 0.6.1.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/README +22 -23
  2. data/doc/classes/Kernel.html +15 -15
  3. data/doc/classes/Mack.html +0 -6
  4. data/doc/classes/Mack/Data/Bridge.html +36 -36
  5. data/doc/classes/Mack/Data/Factory/ClassMethods.html +44 -16
  6. data/doc/classes/Mack/Data/Factory/FieldContentGenerator.html +324 -305
  7. data/doc/classes/Mack/Data/Field.html +81 -77
  8. data/doc/classes/Mack/Data/FieldMgr.html +23 -23
  9. data/doc/classes/Mack/Data/OrmBridge/ActiveRecord.html +36 -36
  10. data/doc/classes/Mack/Data/OrmBridge/DataMapper.html +36 -36
  11. data/doc/classes/Mack/Data/OrmBridge/Default.html +45 -45
  12. data/doc/created.rid +1 -1
  13. data/doc/files/README.html +1 -1
  14. data/doc/files/lib/mack-data_factory/content_generator_rb.html +8 -1
  15. data/doc/files/lib/mack-data_factory/core_extensions/kernel_rb.html +1 -1
  16. data/doc/files/lib/mack-data_factory/data_factory_rb.html +1 -1
  17. data/doc/files/lib/mack-data_factory/field_manager_rb.html +1 -1
  18. data/doc/files/lib/mack-data_factory/field_rb.html +1 -1
  19. data/doc/files/lib/mack-data_factory/orm_api_bridge/bridge_rb.html +1 -1
  20. data/doc/files/lib/mack-data_factory/orm_api_bridge/orm/default_rb.html +1 -1
  21. data/doc/fr_class_index.html +0 -5
  22. data/doc/fr_method_index.html +50 -49
  23. data/lib/mack-data_factory/content_generator.rb +22 -7
  24. data/lib/mack-data_factory/core_extensions/kernel.rb +1 -1
  25. data/lib/mack-data_factory/data_factory.rb +11 -4
  26. data/lib/mack-data_factory/field.rb +18 -14
  27. data/lib/mack-data_factory/field_manager.rb +3 -3
  28. data/lib/mack-data_factory/orm_api_bridge/bridge.rb +1 -1
  29. data/lib/mack-data_factory/orm_api_bridge/orm/default.rb +18 -18
  30. metadata +2 -2
@@ -22,20 +22,15 @@
22
22
  <div id="index-entries">
23
23
  <a href="classes/Kernel.html">Kernel</a><br />
24
24
  <a href="classes/Mack.html">Mack</a><br />
25
- <a href="classes/Mack/Data.html">Mack::Data</a><br />
26
25
  <a href="classes/Mack/Data/Bridge.html">Mack::Data::Bridge</a><br />
27
26
  <a href="classes/Mack/Data/Factory.html">Mack::Data::Factory</a><br />
28
27
  <a href="classes/Mack/Data/Factory/ClassMethods.html">Mack::Data::Factory::ClassMethods</a><br />
29
28
  <a href="classes/Mack/Data/Factory/FieldContentGenerator.html">Mack::Data::Factory::FieldContentGenerator</a><br />
30
- <a href="classes/Mack/Data/FactoryRegistryMap.html">Mack::Data::FactoryRegistryMap</a><br />
31
29
  <a href="classes/Mack/Data/Field.html">Mack::Data::Field</a><br />
32
30
  <a href="classes/Mack/Data/FieldMgr.html">Mack::Data::FieldMgr</a><br />
33
- <a href="classes/Mack/Data/OrmBridge.html">Mack::Data::OrmBridge</a><br />
34
31
  <a href="classes/Mack/Data/OrmBridge/ActiveRecord.html">Mack::Data::OrmBridge::ActiveRecord</a><br />
35
32
  <a href="classes/Mack/Data/OrmBridge/DataMapper.html">Mack::Data::OrmBridge::DataMapper</a><br />
36
33
  <a href="classes/Mack/Data/OrmBridge/Default.html">Mack::Data::OrmBridge::Default</a><br />
37
- <a href="classes/Mack/Data/OrmRegistry.html">Mack::Data::OrmRegistry</a><br />
38
- <a href="classes/Mack/Data/RegistryMap.html">Mack::Data::RegistryMap</a><br />
39
34
  </div>
40
35
  </div>
41
36
  </body>
@@ -20,58 +20,59 @@
20
20
  <div id="index">
21
21
  <h1 class="section-bar">Methods</h1>
22
22
  <div id="index-entries">
23
- <a href="classes/Mack/Data/FieldMgr.html#M000041">add (Mack::Data::FieldMgr)</a><br />
24
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000005">alpha_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
25
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000006">alpha_numeric_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
26
- <a href="classes/Mack/Data/OrmBridge/DataMapper.html#M000022">can_handle (Mack::Data::OrmBridge::DataMapper)</a><br />
27
- <a href="classes/Mack/Data/OrmBridge/Default.html#M000028">can_handle (Mack::Data::OrmBridge::Default)</a><br />
28
- <a href="classes/Mack/Data/OrmBridge/ActiveRecord.html#M000034">can_handle (Mack::Data::OrmBridge::ActiveRecord)</a><br />
29
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000018">city_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
30
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000016">company_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
31
- <a href="classes/Mack/Data/OrmBridge/Default.html#M000031">count (Mack::Data::OrmBridge::Default)</a><br />
32
- <a href="classes/Mack/Data/Bridge.html#M000049">count (Mack::Data::Bridge)</a><br />
33
- <a href="classes/Mack/Data/OrmBridge/DataMapper.html#M000025">count (Mack::Data::OrmBridge::DataMapper)</a><br />
34
- <a href="classes/Mack/Data/OrmBridge/ActiveRecord.html#M000037">count (Mack::Data::OrmBridge::ActiveRecord)</a><br />
23
+ <a href="classes/Mack/Data/FieldMgr.html#M000042">add (Mack::Data::FieldMgr)</a><br />
24
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000006">alpha_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
25
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000007">alpha_numeric_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
26
+ <a href="classes/Mack/Data/Factory/ClassMethods.html#M000004">association (Mack::Data::Factory::ClassMethods)</a><br />
27
+ <a href="classes/Mack/Data/OrmBridge/Default.html#M000029">can_handle (Mack::Data::OrmBridge::Default)</a><br />
28
+ <a href="classes/Mack/Data/OrmBridge/DataMapper.html#M000023">can_handle (Mack::Data::OrmBridge::DataMapper)</a><br />
29
+ <a href="classes/Mack/Data/OrmBridge/ActiveRecord.html#M000035">can_handle (Mack::Data::OrmBridge::ActiveRecord)</a><br />
30
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000019">city_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
31
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000017">company_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
32
+ <a href="classes/Mack/Data/OrmBridge/ActiveRecord.html#M000038">count (Mack::Data::OrmBridge::ActiveRecord)</a><br />
33
+ <a href="classes/Mack/Data/OrmBridge/Default.html#M000032">count (Mack::Data::OrmBridge::Default)</a><br />
34
+ <a href="classes/Mack/Data/OrmBridge/DataMapper.html#M000026">count (Mack::Data::OrmBridge::DataMapper)</a><br />
35
+ <a href="classes/Mack/Data/Bridge.html#M000050">count (Mack::Data::Bridge)</a><br />
35
36
  <a href="classes/Mack/Data/Factory/ClassMethods.html#M000002">create (Mack::Data::Factory::ClassMethods)</a><br />
36
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000008">date_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
37
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000009">date_time_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
38
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000012">domain_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
39
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000010">email_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
40
- <a href="classes/Kernel.html#M000051">factories (Kernel)</a><br />
37
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000013">domain_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
38
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000011">email_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
39
+ <a href="classes/Kernel.html#M000052">factories (Kernel)</a><br />
41
40
  <a href="classes/Mack/Data/Factory/ClassMethods.html#M000003">field (Mack::Data::Factory::ClassMethods)</a><br />
42
- <a href="classes/Mack/Data/FieldMgr.html#M000042">fields (Mack::Data::FieldMgr)</a><br />
43
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000013">firstname_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
44
- <a href="classes/Mack/Data/OrmBridge/DataMapper.html#M000023">get (Mack::Data::OrmBridge::DataMapper)</a><br />
45
- <a href="classes/Mack/Data/Bridge.html#M000046">get (Mack::Data::Bridge)</a><br />
46
- <a href="classes/Mack/Data/OrmBridge/ActiveRecord.html#M000035">get (Mack::Data::OrmBridge::ActiveRecord)</a><br />
47
- <a href="classes/Mack/Data/OrmBridge/Default.html#M000029">get (Mack::Data::OrmBridge::Default)</a><br />
48
- <a href="classes/Mack/Data/Bridge.html#M000047">get_all (Mack::Data::Bridge)</a><br />
49
- <a href="classes/Mack/Data/OrmBridge/ActiveRecord.html#M000036">get_all (Mack::Data::OrmBridge::ActiveRecord)</a><br />
50
- <a href="classes/Mack/Data/OrmBridge/DataMapper.html#M000024">get_all (Mack::Data::OrmBridge::DataMapper)</a><br />
51
- <a href="classes/Mack/Data/OrmBridge/Default.html#M000030">get_all (Mack::Data::OrmBridge::Default)</a><br />
52
- <a href="classes/Mack/Data/OrmBridge/ActiveRecord.html#M000039">get_first (Mack::Data::OrmBridge::ActiveRecord)</a><br />
53
- <a href="classes/Mack/Data/OrmBridge/DataMapper.html#M000027">get_first (Mack::Data::OrmBridge::DataMapper)</a><br />
54
- <a href="classes/Mack/Data/Bridge.html#M000048">get_first (Mack::Data::Bridge)</a><br />
55
- <a href="classes/Mack/Data/OrmBridge/Default.html#M000033">get_first (Mack::Data::OrmBridge::Default)</a><br />
56
- <a href="classes/Mack/Data/Field.html#M000044">get_value (Mack::Data::Field)</a><br />
41
+ <a href="classes/Mack/Data/FieldMgr.html#M000043">fields (Mack::Data::FieldMgr)</a><br />
42
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000014">firstname_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
43
+ <a href="classes/Mack/Data/OrmBridge/Default.html#M000030">get (Mack::Data::OrmBridge::Default)</a><br />
44
+ <a href="classes/Mack/Data/OrmBridge/ActiveRecord.html#M000036">get (Mack::Data::OrmBridge::ActiveRecord)</a><br />
45
+ <a href="classes/Mack/Data/OrmBridge/DataMapper.html#M000024">get (Mack::Data::OrmBridge::DataMapper)</a><br />
46
+ <a href="classes/Mack/Data/Bridge.html#M000047">get (Mack::Data::Bridge)</a><br />
47
+ <a href="classes/Mack/Data/OrmBridge/DataMapper.html#M000025">get_all (Mack::Data::OrmBridge::DataMapper)</a><br />
48
+ <a href="classes/Mack/Data/Bridge.html#M000048">get_all (Mack::Data::Bridge)</a><br />
49
+ <a href="classes/Mack/Data/OrmBridge/ActiveRecord.html#M000037">get_all (Mack::Data::OrmBridge::ActiveRecord)</a><br />
50
+ <a href="classes/Mack/Data/OrmBridge/Default.html#M000031">get_all (Mack::Data::OrmBridge::Default)</a><br />
51
+ <a href="classes/Mack/Data/OrmBridge/ActiveRecord.html#M000040">get_first (Mack::Data::OrmBridge::ActiveRecord)</a><br />
52
+ <a href="classes/Mack/Data/Bridge.html#M000049">get_first (Mack::Data::Bridge)</a><br />
53
+ <a href="classes/Mack/Data/OrmBridge/DataMapper.html#M000028">get_first (Mack::Data::OrmBridge::DataMapper)</a><br />
54
+ <a href="classes/Mack/Data/OrmBridge/Default.html#M000034">get_first (Mack::Data::OrmBridge::Default)</a><br />
55
+ <a href="classes/Mack/Data/Field.html#M000045">get_value (Mack::Data::Field)</a><br />
57
56
  <a href="classes/Mack/Data/Factory.html#M000001">included (Mack::Data::Factory)</a><br />
58
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000014">lastname_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
59
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000017">name_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
60
- <a href="classes/Mack/Data/Bridge.html#M000045">new (Mack::Data::Bridge)</a><br />
61
- <a href="classes/Mack/Data/FieldMgr.html#M000040">new (Mack::Data::FieldMgr)</a><br />
62
- <a href="classes/Mack/Data/Field.html#M000043">new (Mack::Data::Field)</a><br />
63
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000007">numeric_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
64
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000015">phone_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
65
- <a href="classes/Kernel.html#M000052">run_factories (Kernel)</a><br />
66
- <a href="classes/Mack/Data/OrmBridge/Default.html#M000032">save (Mack::Data::OrmBridge::Default)</a><br />
67
- <a href="classes/Mack/Data/OrmBridge/DataMapper.html#M000026">save (Mack::Data::OrmBridge::DataMapper)</a><br />
68
- <a href="classes/Mack/Data/Bridge.html#M000050">save (Mack::Data::Bridge)</a><br />
69
- <a href="classes/Mack/Data/OrmBridge/ActiveRecord.html#M000038">save (Mack::Data::OrmBridge::ActiveRecord)</a><br />
70
- <a href="classes/Mack/Data/Factory/ClassMethods.html#M000004">scope_for (Mack::Data::Factory::ClassMethods)</a><br />
71
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000020">state_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
72
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000019">streetname_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
73
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000011">username_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
74
- <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000021">zipcode_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
57
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000015">lastname_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
58
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000010">money_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
59
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000018">name_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
60
+ <a href="classes/Mack/Data/Field.html#M000044">new (Mack::Data::Field)</a><br />
61
+ <a href="classes/Mack/Data/Bridge.html#M000046">new (Mack::Data::Bridge)</a><br />
62
+ <a href="classes/Mack/Data/FieldMgr.html#M000041">new (Mack::Data::FieldMgr)</a><br />
63
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000008">numeric_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
64
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000016">phone_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
65
+ <a href="classes/Kernel.html#M000053">run_factories (Kernel)</a><br />
66
+ <a href="classes/Mack/Data/OrmBridge/ActiveRecord.html#M000039">save (Mack::Data::OrmBridge::ActiveRecord)</a><br />
67
+ <a href="classes/Mack/Data/OrmBridge/Default.html#M000033">save (Mack::Data::OrmBridge::Default)</a><br />
68
+ <a href="classes/Mack/Data/Bridge.html#M000051">save (Mack::Data::Bridge)</a><br />
69
+ <a href="classes/Mack/Data/OrmBridge/DataMapper.html#M000027">save (Mack::Data::OrmBridge::DataMapper)</a><br />
70
+ <a href="classes/Mack/Data/Factory/ClassMethods.html#M000005">scope_for (Mack::Data::Factory::ClassMethods)</a><br />
71
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000021">state_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
72
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000020">streetname_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
73
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000009">time_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
74
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000012">username_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
75
+ <a href="classes/Mack/Data/Factory/FieldContentGenerator.html#M000022">zipcode_generator (Mack::Data::Factory::FieldContentGenerator)</a><br />
75
76
  </div>
76
77
  </div>
77
78
  </body>
@@ -1,3 +1,5 @@
1
+ require 'bigdecimal'
2
+
1
3
  module Mack
2
4
  module Data
3
5
  module Factory
@@ -95,20 +97,33 @@ module Mack
95
97
  return @numeric_gen
96
98
  end
97
99
 
98
- def date_generator
100
+ def time_generator
99
101
  @date_gen = Proc.new do |def_value, rules, index|
100
- Time.now.to_s
102
+ start_time = rules[:start_time] || 1.day.ago
103
+ end_time = rules[:end_time] || 1.day.from_now
104
+
105
+ diff = (end_time - start_time).to_i
106
+ start_time + rand(diff).to_i
101
107
  end
102
108
  return @date_gen
103
109
  end
104
110
 
105
- def date_time_generator
106
- @date_time_gen = Proc.new do |def_value, rules, index|
107
- Time.now.to_s
111
+ # def date_time_generator
112
+ # @date_time_gen = Proc.new do |def_value, rules, index|
113
+ # Time.now.to_s
114
+ # end
115
+ # return @date_time_gen
116
+ # end
117
+
118
+ def money_generator
119
+ @money_gen = Proc.new do |def_value, rules, index|
120
+ min = rules[:min] || 0.00
121
+ max = rules[:max] || 500.75
122
+ diff = rand * (max - min)
123
+ BigDecimal((min + diff).to_s)
108
124
  end
109
- return @date_time_gen
125
+ return @money_gen
110
126
  end
111
-
112
127
 
113
128
  def email_generator
114
129
  @email_gen = Proc.new do |def_value, rules, index|
@@ -1,6 +1,6 @@
1
1
  module Mack
2
2
  module Data
3
- class FactoryRegistryMap < Mack::Utils::RegistryMap
3
+ class FactoryRegistryMap < Mack::Utils::RegistryMap # :nodoc:
4
4
  end
5
5
  end
6
6
  end
@@ -1,5 +1,5 @@
1
1
  module Mack
2
- module Data
2
+ module Data # :nodoc:
3
3
  #
4
4
  # Add factory capability to a class.
5
5
  #
@@ -27,7 +27,7 @@ module Mack
27
27
  # Example:
28
28
  # class CarFactory
29
29
  # include Mack::Data::Factory
30
- # field :name, "honda" { |def_value, rules, index| "#{def_value} #{['civic', 'accord', 'pilot'].randomize[0]}"}
30
+ # field :name, :default => "honda" { |def_value, rules, index| "#{def_value} #{['civic', 'accord', 'pilot'].randomize[0]}"}
31
31
  # end
32
32
  #
33
33
  # CarFactory.create(100) #=> will produce 100 cars whose name is "honda xxx" where xxx is a random item from ['civic', 'accord', 'pilot']
@@ -78,8 +78,15 @@ module Mack
78
78
  # Define a field with its default value and rules and an optional content generator
79
79
  # for this factory
80
80
  #
81
- def field(model_attrib_sym, default_value, options = {}, &block)
82
- field_manager.add(scope, model_attrib_sym, default_value, options, &block)
81
+ def field(model_attrib_sym, options = {}, &block)
82
+ field_manager.add(scope, model_attrib_sym, options, &block)
83
+ end
84
+
85
+ #
86
+ # Define an association rule for this field
87
+ #
88
+ def association(model_attrib_sym, assoc_map, assoc_rule = :spread)
89
+ field(model_attrib_sym, {:default => {:df_assoc_map => assoc_map}, :assoc => assoc_rule})
83
90
  end
84
91
 
85
92
  #
@@ -1,7 +1,7 @@
1
1
  module Mack
2
2
  module Data
3
3
 
4
- class RegistryMap < Mack::Utils::RegistryMap
4
+ class RegistryMap < Mack::Utils::RegistryMap # :nodoc:
5
5
  end
6
6
 
7
7
  class Field
@@ -19,6 +19,7 @@ module Mack
19
19
  end
20
20
 
21
21
  self.field_rules = {
22
+ :default => "",
22
23
  :immutable => false,
23
24
  :length => 256,
24
25
  :add_space => true,
@@ -26,29 +27,32 @@ module Mack
26
27
  :null_frequency => nil
27
28
  }.merge!(hash[:field_rules]) if hash[:field_rules] != nil
28
29
 
30
+ self.field_value = self.field_rules[:default]
31
+
29
32
  # transform the content type based on the given default value
30
- if field_value.is_a?(Fixnum) or field_value.is_a?(Integer)
31
- field_rules[:content] = :numeric
33
+ if self.field_value.is_a?(Fixnum) or self.field_value.is_a?(Integer)
34
+ self.field_rules[:content] = :numeric
32
35
  end
33
36
 
34
- self.field_value_producer = Mack::Data::Factory::FieldContentGenerator.send("#{field_rules[:content]}_generator")
37
+ self.field_value_producer = Mack::Data::Factory::FieldContentGenerator.send("#{self.field_rules[:content]}_generator")
35
38
  end
36
39
 
37
40
  def get_value(index = 0)
38
41
  # return the field_value immediately if the rule states that it's immutable
39
- return field_value if field_rules[:immutable]
42
+ return self.field_value if self.field_rules[:immutable]
40
43
 
41
44
  #
42
45
  # if the value is a hash, then it's a relationship mapping
43
- if field_value.is_a?(Hash)
44
- owner = field_value.keys[0]
45
- key = field_value[owner]
46
+ if self.field_value.is_a?(Hash) and self.field_value[:df_assoc_map]
47
+ map_data = self.field_value[:df_assoc_map]
48
+ owner = map_data.keys[0]
49
+ key = map_data[owner]
46
50
  begin
47
51
  owner_model = owner.to_s.camelcase.constantize
48
52
  bridge = Mack::Data::Bridge.new
49
53
 
50
- assoc_rules = field_rules[:assoc] || :spread
51
- assoc_rules = :random if !([:first, :last, :random, :spread].include?(assoc_rules))
54
+ assoc_rules = self.field_rules[:assoc] || :spread
55
+ assoc_rules = :spread if !([:first, :last, :random, :spread].include?(assoc_rules))
52
56
  # cache the query once
53
57
  if Mack::Data::RegistryMap.registered_items[self.field_name.to_sym] == nil
54
58
  all_owner_models = bridge.get_all(owner_model)
@@ -59,7 +63,7 @@ module Mack
59
63
 
60
64
  case assoc_rules
61
65
  when :first
62
- value = all_owner_models[0].send(key)
66
+ value = all_owner_models[0].send(key.to_s)
63
67
  when :last
64
68
  value = all_owner_models[all_owner_models.size - 1].send(key)
65
69
  when :random
@@ -76,13 +80,13 @@ module Mack
76
80
  end
77
81
 
78
82
  return value
79
- rescue Exception
80
- Mack.logger.warn "WARNING: DataFactory: field_value for #{field_name} is not set properly because data relationship defined is not correct"
83
+ rescue Exception => ex
84
+ Mack.logger.warn "WARNING: DataFactory: id_map for #{field_name} is not set properly because data relationship defined is not correct"
81
85
  end
82
86
  end
83
87
 
84
88
  # must generate random string and also respect the rules
85
- field_value_producer.call(field_value, field_rules, index)
89
+ self.field_value_producer.call(self.field_value, self.field_rules, index)
86
90
  end
87
91
  end
88
92
  end
@@ -7,10 +7,10 @@ module Mack
7
7
  @scopes = {}
8
8
  end
9
9
 
10
- def add(scope, field_name, default_value, options = {}, &block)
10
+ def add(scope, field_name, options = {}, &block)
11
+ #default_value = options[:default] || ""
11
12
  field_list = fields(scope)
12
- field_list[field_name] = Field.new(:field_name => field_name,
13
- :field_value => default_value,
13
+ field_list[field_name] = Field.new( :field_name => field_name,
14
14
  :field_rules => options)
15
15
  field_list[field_name].field_value_producer = block if block_given?
16
16
  return field_list
@@ -1,7 +1,7 @@
1
1
  module Mack
2
2
  module Data
3
3
 
4
- class OrmRegistry < Mack::Utils::RegistryList
4
+ class OrmRegistry < Mack::Utils::RegistryList # :nodoc:
5
5
  end
6
6
 
7
7
  class Bridge
@@ -1,6 +1,6 @@
1
1
  module Mack
2
2
  module Data
3
- module OrmBridge
3
+ module OrmBridge # :nodoc:
4
4
  class Default
5
5
 
6
6
  def can_handle(obj)
@@ -8,23 +8,23 @@ module Mack
8
8
  end
9
9
 
10
10
  def get(obj, *args)
11
- Mack.logger.warn "Mack::Data::OrmBridge: You don't have supported orm api handler installed."
12
- end
13
-
14
- def get_all(obj, *args)
15
- Mack.logger.warn "Mack::Data::OrmBridge: You don't have supported orm api handler installed."
16
- end
17
-
18
- def count(obj, *args)
19
- Mack.logger.warn "Mack::Data::OrmBridge: You don't have supported orm api handler installed."
20
- end
21
-
22
- def save(obj, *args)
23
- Mack.logger.warn "Mack::Data::OrmBridge: You don't have supported orm api handler installed."
24
- end
25
-
26
- def get_first(obj, *args)
27
- Mack.logger.warn "Mack::Data::OrmBridge: You don't have supported orm api handler installed."
11
+ Mack.logger.warn "Mack::Data::OrmBridge: You don't have a supported orm api handler installed."
12
+ end
13
+
14
+ def get_all(obj, *args)
15
+ Mack.logger.warn "Mack::Data::OrmBridge: You don't have a supported orm api handler installed."
16
+ end
17
+
18
+ def count(obj, *args)
19
+ Mack.logger.warn "Mack::Data::OrmBridge: You don't have a supported orm api handler installed."
20
+ end
21
+
22
+ def save(obj, *args)
23
+ Mack.logger.warn "Mack::Data::OrmBridge: You don't have a supported orm api handler installed."
24
+ end
25
+
26
+ def get_first(obj, *args)
27
+ Mack.logger.warn "Mack::Data::OrmBridge: You don't have a supported orm api handler installed."
28
28
  end
29
29
 
30
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mack-data_factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darsono Sutedja
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-29 00:00:00 -04:00
12
+ date: 2008-08-25 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency