I'm creating the following ruby class generator:
class Template < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
argument :name, type: 'string', required: true
...
class_option :templates, type: 'array', default: [1, 2, 3, 4], aliases: '-t'
private
...
end
In the rails console I tried:
rails generate template test -t=1 2
rails generate template test -t 1 2
rails generate template test -t 1,2
rails generate template test -t=1,2
rails generate template test -t=[1,2]
rails generate template test -t [1,2]
but the generator is not working correctly. It seems that the input doesn't return an array, because the following private method is not working:
def should_be_template_rendered(param)
options.templates.include? param
end
Where param is simply a number. The result is that none of the templates are rendered at all. I have checked the Thor documentations here and here, but was not able to find an example on how the array is passed as argument.
The following work fine for me
rails generate template test -t=1 2
rails generate template test -t 1 2
Just notice that the result is a string array:
options["templates"]
#=> ["1", "2"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With