Thor Reading config yaml file to override options
I think you are looking for a way to set configuration options via the command line and via a configuration file.
Here is an example from the foreman gem.
def options
original_options = super
return original_options unless File.exists?(".foreman")
defaults = ::YAML::load_file(".foreman") || {}
Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
end
It overrides the options
method and merges values from a configuration file into the original options hash.
In your case, the following might work:
def csv2strings(name)
# do something with options
end
private
def options
original_options = super
filename = original_options[:file] || '.csvconverter.yaml'
return original_options unless File.exists?(filename)
defaults = ::YAML::load_file(filename) || {}
defaults.merge(original_options)
# alternatively, set original_options[:langs] and then return it
end
(I recently wrote a post about Foreman on my blog that explains this in more detail.)
ruby 1.8.7 why .to_yaml converts some Strings to non-readable bytes
Whether YAML prefers to dump a string as text or binary is a matter of ratio between ASCII and non ASCII characters.
If you want to avoid !binary
as much as possible, you should use the ya2yaml gem. It tries hard to dump strings as ASCII + escaped UTF-8.
Evernote API Binary Error - Ruby on Rails - OAuth
I guess to_yml
makes your error message unreadable like:
--- !binary |-
U1NMX2Nvbm5lY3QgcmV0dXJuZWQ9MSBlcnJubz0wIHN0YXRlPVNTTHYzIHJl
YWQgc2VydmVyIGNlcnRpZmljYXRlIEI6IGNlcnRpZmljYXRlIHZlcmlmeSBm
YWlsZWQ=
Can you replace to_yml
with inspect
?
It seems simply your message is outputted as binary and you could figure out the cause of error from messages if it is outputted as text.
Related post:
Thor & YAML outputting as binary?
split files to key value pair
This works:
awk '
sub(/^[[:space:]]+- name: /, ""){n=$0}
sub(/^[[:space:]]+value: /, ""){print n": "$0}'
Match and remove the name:
/value:
labels, and print the remainder of both lines on a single line.
Cant run rails server, project is telling me i dont have node even though I do?
I think you need a webpacker.yml
file in your apps config
file. I also suggest running bundle install
and bundle update
commands before launching the rails server after you installed a gem. Here's a closed issue similar to your problem; https://github.com/rails/webpacker/issues/940
Related Topics
Rails - How to Check for Online Users
Ruby Google_Drive Gem Oauth2 Saving
Scraping/Parsing Google Search Results in Ruby
Ruby Conditional-Assignment and Private Methods
Rails Devise - Current_User Is Nil
Rspec 'Eq' VS 'Eql' in 'Expect' Tests
Pg::Invalidparametervalue: Error: Invalid Value for Parameter "Client_Min_Messages": "Panic"
Is There a Method to Limit/Clamp a Number
How to Get a List of Gems That Are Installed That Have Native Extensions
Could Not Find Rake-10.0.4 in Any of the Sources (Bundler::Gemnotfound)
Clicking a Button with Ruby Mechanize
Multiple Level Nesting in Yaml
How to Use Link_To to Link an Image and a Text
What's a Rails Plugin, or Ruby Gem, to Automatically Fix English Grammar