Closed rmarronnier closed 5 years ago
Ahh I know the problem. The problem isn't that the path is hardcoded so much as it is that the file isn't being loaded into the binary like I thought it was. Should be an easy fix, so I'll get back to you soon.
Wow, that was fast ! Thanks :-D
I try! So currently files are being read in as Strings, I just need to make it so they get read in as StringLiterals using the read_file
macro. I should have it fixed by this evening.
Yeah, I saw the gitter chat :-) No stress mate. I'm heading for bed now. But I'll sure be telling this tale (in an article or to my grand children) of how crazy fast this bug was fixed :-p
Should be all good now. I also added the ability to set custom sentiment data just in case you want to use your own.
I tried compiling again, and now it fails on compilation with the same error :
in lib/cadmium/src/cadmium/sentiment.cr:42: Error opening file './data/sentiment.txt' with mode 'r': No such file or directory
@@data ||= {{ read_file("./data/sentiment.txt") }}
You can try a
crystal spec
It seems you made a typo in the data path :
@@data ||= {{ read_file("./data/sentiment.txt") }}
Instead of the old one :
@@data = File.read(File.join(__DIR__, "../../data/sentiment.txt"))
@@data ||= {{ read_file("#{__DIR__}/../../data/sentiment.txt") }}
This works. Do you want me to do a PR ?
@rmarronnier yes please. I thought removing the __DIR__
would be fine, but I forgot that when you include Cadmium in another project your cwd changes.
Great job job on this fantastic lib !
I'm developing a web app deployed on Heroku and after the crystal binary is compiled all librairies / shards are discarded.
My app compiles fine with cadmium but crashes because it can't find files inside the data folder :
Should binaries compiled against Cadmium be dependent on Cadmium being present on the target computer ?
I think not, but there are several solutions to this problem :
1 - Put all data inside .cr files in arrays / hashes / tuples
2 - Make the path to data files configurable (via a yml config file or ENV variables)
3 - ??? I can't think of more :-)
If I missed something in the docs, feel free to close this issue ;-)