Class: LazyFixtures::FactoryGirl::FileManager
- Inherits:
-
Object
- Object
- LazyFixtures::FactoryGirl::FileManager
- Defined in:
- lib/lazy_fixtures/factory_girl/file_manager.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #check_existence? ⇒ Boolean
- #create_file ⇒ Object
- #get_file_name ⇒ Object
- #global_factory_directory ⇒ Object
-
#initialize(name, options) ⇒ FileManager
constructor
A new instance of FileManager.
- #write_file(text) ⇒ Object
Constructor Details
#initialize(name, options) ⇒ FileManager
Returns a new instance of FileManager.
5 6 7 8 9 |
# File 'lib/lazy_fixtures/factory_girl/file_manager.rb', line 5 def initialize(name, ) @name = name = @file_path = File.join(global_factory_directory, get_file_name) end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
4 5 6 |
# File 'lib/lazy_fixtures/factory_girl/file_manager.rb', line 4 def file_path @file_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/lazy_fixtures/factory_girl/file_manager.rb', line 4 def name @name end |
Instance Method Details
#check_existence? ⇒ Boolean
31 32 33 |
# File 'lib/lazy_fixtures/factory_girl/file_manager.rb', line 31 def check_existence? File.file?(file_path) end |
#create_file ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/lazy_fixtures/factory_girl/file_manager.rb', line 11 def create_file return unless [:create] if check_existence? && ![:overwrite] puts "There is a file already inside that folder with the same name #{get_file_name}" puts "Would you like to overwrite that file? (yes/no)" answer = gets.chomp if answer == 'yes' puts 'The generator is overwriting your file' File.new(file_path, "w") true else puts 'Exiting the program' false end end puts "creating new file under #{global_factory_directory}/#{get_file_name}" File.new(file_path, "w") true end |
#get_file_name ⇒ Object
45 46 47 |
# File 'lib/lazy_fixtures/factory_girl/file_manager.rb', line 45 def get_file_name "#{name}.rb" end |
#global_factory_directory ⇒ Object
41 42 43 |
# File 'lib/lazy_fixtures/factory_girl/file_manager.rb', line 41 def global_factory_directory LazyFixtures.configuration.factory_directory end |
#write_file(text) ⇒ Object
35 36 37 38 39 |
# File 'lib/lazy_fixtures/factory_girl/file_manager.rb', line 35 def write_file(text) File.open(file_path, 'w') do |f| f.write text end end |