Class: SeedFu::Writer::Abstract

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

Direct Known Subclasses

Seed, SeedMany

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Abstract

Returns a new instance of Abstract.


8
9
10
11
12
13
14
15
# File 'lib/seed-fu/writer/abstract.rb', line 8

def initialize(options={})
  self.config = options
  self.number_of_seeds = 0

  self.seed_handle = File.new(self.config[:seed_file], 'w')

  write_header
end

Instance Attribute Details

#configObject

Returns the value of attribute config


6
7
8
# File 'lib/seed-fu/writer/abstract.rb', line 6

def config
  @config
end

#number_of_seedsObject

Returns the value of attribute number_of_seeds


6
7
8
# File 'lib/seed-fu/writer/abstract.rb', line 6

def number_of_seeds
  @number_of_seeds
end

#seed_handleObject

Returns the value of attribute seed_handle


6
7
8
# File 'lib/seed-fu/writer/abstract.rb', line 6

def seed_handle
  @seed_handle
end

Instance Method Details

#add_seed(hash) ⇒ Object


36
37
38
39
# File 'lib/seed-fu/writer/abstract.rb', line 36

def add_seed(hash)
  $stdout.puts "Added #{hash.inspect}" unless config[:quiet]
  self.number_of_seeds += 1
end

#finishObject


49
50
51
52
# File 'lib/seed-fu/writer/abstract.rb', line 49

def finish
  write_footer
  seed_handle.close
end

30
31
32
33
34
# File 'lib/seed-fu/writer/abstract.rb', line 30

def footer
  <<-END
# End auto-generated file.
  END
end

#headerObject


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/seed-fu/writer/abstract.rb', line 17

def header
  <<-END
# DO NOT MODIFY THIS FILE, it was auto-generated.
# 
# Date: #{DateTime.now}
# Using #{self.class} to seed #{config[:seed_model]}
# Written with the command:
#
#   #{$0} #{$*.join}
#
  END
end

45
46
47
# File 'lib/seed-fu/writer/abstract.rb', line 45

def write_footer
  seed_handle.syswrite footer
end

#write_headerObject


41
42
43
# File 'lib/seed-fu/writer/abstract.rb', line 41

def write_header
  seed_handle.syswrite header
end