Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass array to class option of rails generator? #419

Open
gotqn opened this issue May 31, 2014 · 1 comment
Open

How to pass array to class option of rails generator? #419

gotqn opened this issue May 31, 2014 · 1 comment

Comments

@gotqn
Copy link

gotqn commented May 31, 2014

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 documentation, but was not able to find an example on how the array is passed as argument.

I am using Ruby 2.0, Rails 4.0 and Thor (0.18.1).

@begin29
Copy link

begin29 commented Mar 3, 2021

I did it successfully with

thor some_namespace:some_task --client_ids 1 2 3 4 5 6

and get params inside thor file as options[:client_ids]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants