Class: FixtureBackground::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/fixture_background/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(fixture_name, version, background_dir, blocks, test_unit_class) ⇒ Generator

Returns a new instance of Generator.



3
4
5
# File 'lib/fixture_background/generator.rb', line 3

def initialize(fixture_name, version, background_dir, blocks, test_unit_class)
  @fixture_name, @version, @background_dir, @blocks, @test_unit_class = fixture_name, version, background_dir, blocks, test_unit_class
end

Instance Method Details

#generate!Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fixture_background/generator.rb', line 7

def generate!
  remove_background_dir
  create_background_dir
  
  transaction_with_rollback do
    
    bm = Benchmark.realtime do
      dump_ivars do |klass|
        @blocks.each do |block|
          klass.instance_eval(&block)
        end
      end
      dump_fixtures
    end
    
    File.open("#{@background_dir}/.version", 'w+') do |f| 
      f.write @version
    end
    
    puts "Instanciating #{@fixture_name} took #{bm}ms"
  end
rescue Exception
  remove_background_dir
  raise
end