Class: Blueprints::FixturesConverter
- Inherits:
-
Object
- Object
- Blueprints::FixturesConverter
- Defined in:
- lib/blueprints/convertable/fixtures.rb
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(options = {}) ⇒ FixturesConverter
constructor
A new instance of FixturesConverter.
- #parameterize(object) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ FixturesConverter
Returns a new instance of FixturesConverter.
3 4 5 6 7 8 9 10 11 |
# File 'lib/blueprints/convertable/fixtures.rb', line 3 def initialize( = {}) @format = "fixtures" @source_files = [:source_files] @output_file = [:output_file] @blueprints_data = "" raise "No source files given" unless @source_files raise "No output file given" unless @output_file end |
Instance Method Details
#convert ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/blueprints/convertable/fixtures.rb', line 13 def convert @source_files.each do |fixture_file| klass = File.basename(fixture_file, '.yml').singularize.capitalize loaded_yaml = YAML.load(File.read(fixture_file)) @blueprints_data = loaded_yaml.collect do |title,yaml_obj| params = yaml_obj.collect do |k,v| ":#{k} => #{parameterize(v)}" end.join(', ') "#{klass}.blueprint(:#{title}, {#{params}})\n" end end @blueprints_data end |
#parameterize(object) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/blueprints/convertable/fixtures.rb', line 31 def parameterize(object) if object =~ /<%=\s+?(.+)\s+%>/ '('+$1+')' elsif object.is_a?(String) (%Q(#{object})).inspect elsif object.nil? 'nil' else object.to_s end end |