Class: FixtureToFactory::FixtureFileParser
- Inherits:
-
Object
- Object
- FixtureToFactory::FixtureFileParser
- Defined in:
- lib/fixture_to_factory/fixture_file_parser.rb
Class Method Summary collapse
- .get_file_names_in(folder) ⇒ Object
- .map_fixtures_to_hash(file_paths) ⇒ Object
- .parse_files(folder) ⇒ Object
Class Method Details
.get_file_names_in(folder) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/fixture_to_factory/fixture_file_parser.rb', line 16 def get_file_names_in(folder) file_names = [] if Dir.exists?(folder) Dir.foreach(folder) do |file_name| file_names << file_name end end file_names end |
.map_fixtures_to_hash(file_paths) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/fixture_to_factory/fixture_file_parser.rb', line 26 def map_fixtures_to_hash(file_paths) result = {} file_paths.each do |file_path| fixtures_to_yaml = YAML.load_file(file_path) result[file_path] = fixtures_to_yaml end result end |
.parse_files(folder) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fixture_to_factory/fixture_file_parser.rb', line 5 def self.parse_files(folder) file_names = get_file_names_in(folder) file_names = file_names.select{|file_name| file_name =~ /(\w+).yml/ } file_paths = file_names.map{|file_name| "#{folder}/#{file_name}"} map_fixtures_to_hash(file_paths) end |