Class: ComposableFixtures::FixtureComposer
- Inherits:
-
Object
- Object
- ComposableFixtures::FixtureComposer
- Defined in:
- lib/composable_fixtures/fixture_composer.rb
Instance Method Summary collapse
- #as_filename_to_yaml ⇒ Object
- #extract_fixture_from(fixture_set_path, filename) ⇒ Object
-
#initialize(fixture_names) ⇒ FixtureComposer
constructor
A new instance of FixtureComposer.
Constructor Details
#initialize(fixture_names) ⇒ FixtureComposer
Returns a new instance of FixtureComposer.
3 4 5 6 |
# File 'lib/composable_fixtures/fixture_composer.rb', line 3 def initialize(fixture_names) @fixture_names = fixture_names @filename_to_concatd_fixtures = {} end |
Instance Method Details
#as_filename_to_yaml ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/composable_fixtures/fixture_composer.rb', line 8 def as_filename_to_yaml @fixture_names.each do |fixture_name| set_def = FixtureSetRepository.instance.fetch(fixture_name) set_def.each do |fixture_set_path| Dir.foreach(fixture_set_path) do |filename| next if filename =~ /^\./ extract_fixture_from(fixture_set_path, filename) end end end @filename_to_concatd_fixtures end |
#extract_fixture_from(fixture_set_path, filename) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/composable_fixtures/fixture_composer.rb', line 21 def extract_fixture_from(fixture_set_path, filename) File.open(File.join(fixture_set_path, filename), "r") do |f| contents = f.readlines if @filename_to_concatd_fixtures.has_key?(filename) # Remove "---" at top of YAML contents.shift else # We haven't loaded any of this file yet so initialize it with a string @filename_to_concatd_fixtures[filename] = "" end @filename_to_concatd_fixtures[filename] += contents.join("\n") end end |