Class: Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/test_fixture_boy/printer.rb

Constant Summary collapse

TMP_DIR =
'/tmp/tfboy'

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Printer

data is model - records hash



7
8
9
10
11
# File 'lib/test_fixture_boy/printer.rb', line 7

def initialize(data)
  @format = data.delete(:format) || :yaml
  @dir = data.delete(:dir) || TMP_DIR
  @data = data
end

Instance Method Details



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/test_fixture_boy/printer.rb', line 13

def print
  @data.each do |model, records|
    local_zip = File.open(file_name(model), mode = "wb") do |f|
      f.write("---\n")
      records.each do |record|
        attrs = record.split("\n")
        attrs.shift
        f.write("- #{attrs.shift}\n  ")
        f.write(attrs.join("\n  "))
        f.write("\n")
      end
    end
  end
end