From f3518f57d2d180d48bc603cab5738d817682326e Mon Sep 17 00:00:00 2001 From: Zack Hobson Date: Wed, 24 Jun 2009 13:53:15 -0700 Subject: [PATCH] Removed fixtures2factories --- Manifest.txt | 2 - lib/fixture_converter.rb | 97 --------------------------------------- script/fixtures2factories | 18 -------- 3 files changed, 117 deletions(-) delete mode 100644 lib/fixture_converter.rb delete mode 100755 script/fixtures2factories diff --git a/Manifest.txt b/Manifest.txt index 4fb2e49..144d984 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -3,14 +3,12 @@ License.txt Manifest.txt README.txt Rakefile -lib/fixture_converter.rb lib/model_factory.rb lib/modelfactory.rb lib/modelfactory/factory.rb lib/modelfactory/legacy.rb lib/modelfactory/version.rb script/destroy -script/fixtures2factories script/generate script/txt2html setup.rb diff --git a/lib/fixture_converter.rb b/lib/fixture_converter.rb deleted file mode 100644 index 4b02696..0000000 --- a/lib/fixture_converter.rb +++ /dev/null @@ -1,97 +0,0 @@ -class FixtureConverter # :nodoc: - def initialize(opts = {}) - @body = [] - @header = [] - @indent_depth = opts[:indent_depth] || 0 - @output_style = opts[:output_style] - end - - def powder? - @output_style == :clay - end - - def convert_fixture(path) - fixture = YAML.load_file(path) - return if not fixture - - plural_model_name = path.basename.to_s.split('.').first - model_name = plural_model_name.singularize - header do - "#{plural_model_name} = {}" - end - - body 'before(:all) do' if powder? - indent(powder?) do - body "# Setup #{plural_model_name}" - body "# Generated from fixture in #{path.dirname.basename}/#{path.basename}" - body '#' - body '' - fixture.each do |name, record| - max_length = record.keys.collect {|key| key.length}.max - - body "#{plural_model_name}[:#{name}] = Factory.create_#{model_name}(" - indent do - body do - record.collect do |key,value| - value = "\"#{value}\"" if value.kind_of?(String) - key = key.ljust(max_length) - ":#{key} => #{value}" - end - end - end - body ')' - end - end - body 'end' if powder? - body '' - end - - def convert_scenario(path) - path.each_entry do |file| - next if file.extname != '.yml' - next if file.basename.to_s =~ /relationships/ - convert_fixture( path + file ) - end - end - - def out - puts @header.join("\n") - puts "\n" - puts @body.join("\n") - end - -private - INDENT = ' ' - - def indent(enabled = true) - @indent_depth += 1 if enabled - yield - @indent_depth -= 1 if enabled - end - - def body(*lines) - lines = yield if block_given? - lines = [lines].flatten - - lines.each do |line| - @body << indent_line(line, @indent_depth) - end - end - - def header(*lines) - lines = yield if block_given? - lines = [lines].flatten - - lines.each do |line| - @header << line - end - end - - def indent_line(line, indent_depth) - ws = '' - indent_depth.times do - ws += INDENT - end - ws + line - end -end diff --git a/script/fixtures2factories b/script/fixtures2factories deleted file mode 100755 index 05f20c3..0000000 --- a/script/fixtures2factories +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/ruby -require 'rubygems' -require 'active_support' -require 'pp' -require 'pathname' -require 'yaml' -require File.dirname(__FILE__) + '/../lib/fixture_converter' - -path = Pathname.new(ARGV[0]) - -fc = FixtureConverter.new -if path.file? - fc.convert_fixture(path) -else - fc.convert_scenario(path) -end -fc.out -