Class: Penman::SeedFileGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/penman/seed_file_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name, timestamp, seed_code) ⇒ SeedFileGenerator

Returns a new instance of SeedFileGenerator.



7
8
9
10
11
# File 'lib/penman/seed_file_generator.rb', line 7

def initialize(file_name, timestamp, seed_code)
  @seed_code = seed_code
  @file_name = file_name
  @timestamp = timestamp
end

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



4
5
6
# File 'lib/penman/seed_file_generator.rb', line 4

def file_name
  @file_name
end

#seed_codeObject (readonly)

Returns the value of attribute seed_code.



3
4
5
# File 'lib/penman/seed_file_generator.rb', line 3

def seed_code
  @seed_code
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



5
6
7
# File 'lib/penman/seed_file_generator.rb', line 5

def timestamp
  @timestamp
end

Instance Method Details

#write_seedObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/penman/seed_file_generator.rb', line 13

def write_seed
  erb = ERB.new(File.read(Penman.config.seed_template_file))
  seed_file_name = "#{@timestamp}_#{@file_name}.rb"
  full_seed_file_path = File.join(Penman.config.seed_path, seed_file_name)
  IO.write(full_seed_file_path, erb.result(binding))

  if Penman.config.after_generate.present?
    Penman.config.after_generate.call(@timestamp, @file_name)
  end

  full_seed_file_path
end