@@ -8,7 +8,28 @@ def self.exit_on_failure?
88 true
99 end
1010
11- desc "show DIR" , "Evaluate DIR/schema.rb and DIR/fixtures.rb, then print fixture YAML to stdout"
11+ desc "compile DIR" , "Compile DIR/schema.rb and DIR/fixtures.rb to YAML fixture files"
12+ def compile ( dir )
13+ schema_path = File . join ( dir , "schema.rb" )
14+ fixtures_path = File . join ( dir , "fixtures.rb" )
15+
16+ raise Thor ::Error , "Schema file not found: #{ schema_path } " unless File . exist? ( schema_path )
17+ raise Thor ::Error , "Fixtures file not found: #{ fixtures_path } " unless File . exist? ( fixtures_path )
18+
19+ schema = eval ( File . read ( schema_path ) , binding , schema_path , 1 )
20+ fixture_set = FixtureBot . define_from_file ( schema , fixtures_path )
21+
22+ output_dir = File . join ( dir , "fixtures" )
23+ Compiler . new ( fixture_set ) . compile ( output_dir )
24+
25+ say "Compiled fixtures to #{ output_dir } /"
26+ fixture_set . tables . each do |table_name , records |
27+ next if records . empty?
28+ say " #{ table_name } .yml (#{ records . size } records)"
29+ end
30+ end
31+
32+ desc "show DIR" , "Compile DIR/schema.rb and DIR/fixtures.rb, then print YAML to stdout"
1233 def show ( dir )
1334 schema_path = File . join ( dir , "schema.rb" )
1435 fixtures_path = File . join ( dir , "fixtures.rb" )
@@ -18,12 +39,12 @@ def show(dir)
1839
1940 schema = eval ( File . read ( schema_path ) , binding , schema_path , 1 )
2041 fixture_set = FixtureBot . define_from_file ( schema , fixtures_path )
21- dumper = FixtureBot ::YamlDumper . new ( fixture_set )
42+ compiler = FixtureBot ::Compiler . new ( fixture_set )
2243
2344 fixture_set . tables . each do |table_name , records |
2445 next if records . empty?
2546 puts "# #{ table_name } .yml"
26- puts dumper . dump_table ( table_name )
47+ puts compiler . compile_table ( table_name )
2748 end
2849 end
2950
0 commit comments