ruby on rails - Unable to read file from within rake task -
i have rake task reads file.
desc "dump images." task :dump_with_images => :environment yaml_path = rails.root + 'db/data.yml' # output: "" -- empty string puts file.open(yaml_path).read.inspect [...] end end
if read , inspect file outside of task,
yaml_path = rails.root + 'db/data.yml' puts file.open(yaml_path).read.inspect desc "dump images." task :dump_with_images => :environment
it gives me data:
zeromodulus@kosuna:~/projects/recipes$ rake dump_with_images "\n---\nphotos:\n columns:\n - id\n - created_at\n - updated_at\n - recipe_id\n - image_file_name\
i don't understand why can read exact same file outside of task, not in task.
when inspect yaml_path, they're both same, , file has data in it.
it looks opening file stream , not closing it, , later on in code attempting open same file stream again.
i've wrapped file reading code in block,
file.read(file_path, "r") |f| yaml.load_stream(f) end
which has solved problem.
update:
the problem has resurfaced, though have opened/closed file streams properly. problem lies elsewhere, couldn't figure out, decided abandoned yaml_db , use standard db/seeds.rb
Comments
Post a Comment