Class: SeedFu::Writer::SeedMany

Inherits:
Abstract
  • Object
show all
Defined in:
lib/seed-fu/writer/seed_many.rb

Instance Attribute Summary

Attributes inherited from Abstract

#config, #number_of_seeds, #seed_handle

Instance Method Summary collapse

Methods inherited from Abstract

#finish, #footer, #header, #initialize

Constructor Details

This class inherits a constructor from SeedFu::Writer::Abstract

Instance Method Details

#add_seed(hash) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/seed-fu/writer/seed_many.rb', line 21

def add_seed(hash)
  seed_handle.syswrite( (<<-END
#{',' unless self.number_of_seeds == 0 or chunk_this_seed?}
  { #{hash.collect{|k,v| ":#{k} => '#{v.to_s.gsub("'", "\'")}'"}.join(', ')} }
  END
  ).chomp )
  super(hash)

  if chunk_this_seed?
    seed_handle.syswrite(
      self.seed_many_footer +
      "# BREAK EVAL\n" +
      self.seed_many_header
    )
  end
end

#chunk_this_seed?Boolean

Chunk in groups of 100 for performance

Returns:

  • (Boolean)

17
18
19
# File 'lib/seed-fu/writer/seed_many.rb', line 17

def chunk_this_seed?
  0 == (self.number_of_seeds % (config[:chunk_size] || 100))
end

11
12
13
# File 'lib/seed-fu/writer/seed_many.rb', line 11

def seed_many_footer
  "\n])\n"
end

#seed_many_headerObject


7
8
9
# File 'lib/seed-fu/writer/seed_many.rb', line 7

def seed_many_header
  "#{config[:seed_model]}.seed_many(#{config[:seed_by].collect{|s| ":#{s}"}.join(',')},["
end

43
44
45
46
# File 'lib/seed-fu/writer/seed_many.rb', line 43

def write_footer
  seed_handle.syswrite self.seed_many_footer
  super
end

#write_headerObject


38
39
40
41
# File 'lib/seed-fu/writer/seed_many.rb', line 38

def write_header
  super
  seed_handle.syswrite self.seed_many_header
end