Module: Spreadhead::Page::ClassMethods

Defined in:
lib/spreadhead/page.rb

Instance Method Summary collapse

Instance Method Details

#to_fixtures(path = nil) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/spreadhead/page.rb', line 71

def to_fixtures(path=nil)
  path ||= File.expand_path("db/data/#{table_name}.yml", RAILS_ROOT)
  path = File.join(path, "#{table_name}.yml") if File.directory?(path)
  file = File.open(path, "w")
  file.puts(self.find(:all).inject({}) { |hash, record| 
    hash.merge("\"#{record.title}\"" => record.attributes) 
  }.to_yaml(:SortKeys => true))
  file.close
end