Class: Punchbowl::Fastory
- Inherits:
-
Object
- Object
- Punchbowl::Fastory
- Defined in:
- lib/fastory.rb
Constant Summary collapse
- @@fastories =
{}
- @@sql_inserts =
[]
- @@record_sql =
false
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ Fastory
constructor
A new instance of Fastory.
- #process! ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Fastory
Returns a new instance of Fastory.
32 33 34 35 |
# File 'lib/fastory.rb', line 32 def initialize(name, = {}) self.name = name self. = end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
25 26 27 |
# File 'lib/fastory.rb', line 25 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
25 26 27 |
# File 'lib/fastory.rb', line 25 def @options end |
Instance Method Details
#process! ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fastory.rb', line 37 def process! = transform_associations if template_available? cache = @@fastories[cache_key] cnt = cache[:templates_used] ||= 0 cache[:templates_used] += 1 fast_gen(cache[:templates][cnt][:sql]) obj = build_class.find cache[:templates][cnt][:id] else @@sql_inserts = [] @@record_sql = true obj = fg.build name, obj.id = fg.next(:fastory_id_generator) if obj.id.blank? obj.save! @@record_sql = false @@fastories[cache_key] ||= {} @@fastories[cache_key][:templates_available] ||= 0 @@fastories[cache_key][:templates_available] += 1 @@fastories[cache_key][:templates_used] = @@fastories[cache_key][:templates_available] res = @@fastories[cache_key][:templates] ||= [] = {:sql => @@sql_inserts.dup, :id => obj.id } res = @@fastories[cache_key][:templates] << end obj end |