Class: FactoryBotFactory::FileWriter
- Inherits:
-
Object
- Object
- FactoryBotFactory::FileWriter
- Defined in:
- lib/factory_bot_factory/file_writer.rb
Instance Attribute Summary collapse
-
#file_paht ⇒ Object
readonly
Returns the value of attribute file_paht.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#initialize(file_path) ⇒ FileWriter
constructor
A new instance of FileWriter.
- #regroup_existing_lines(output) ⇒ Object
- #write(output) ⇒ Object
Constructor Details
#initialize(file_path) ⇒ FileWriter
Returns a new instance of FileWriter.
7 8 9 |
# File 'lib/factory_bot_factory/file_writer.rb', line 7 def initialize(file_path) @file_path = file_path end |
Instance Attribute Details
#file_paht ⇒ Object (readonly)
Returns the value of attribute file_paht.
5 6 7 |
# File 'lib/factory_bot_factory/file_writer.rb', line 5 def file_paht @file_paht end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
5 6 7 |
# File 'lib/factory_bot_factory/file_writer.rb', line 5 def output @output end |
Instance Method Details
#regroup_existing_lines(output) ⇒ Object
27 28 29 |
# File 'lib/factory_bot_factory/file_writer.rb', line 27 def regroup_existing_lines(output) File.read(@file_path) + LineWriter::NEW_LINE + LineWriter.wrap_definition { output } end |
#write(output) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/factory_bot_factory/file_writer.rb', line 11 def write(output) if File.file?(@file_path) output = regroup_existing_lines(output) = "New Factory successfully write to an existing file." else output = LineWriter.wrap_definition { output } = "New Factory successfully write to a new file." end FactoryBot.reload if Object.const_defined?("FactoryBot") File.open(@file_path, 'w') {|f| f.write(output) } Logger.alert( + "\nPlease check your file in #{@file_path}") output end |