7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/safe_params/cli.rb', line 7
def generate(model_name)
model_class = Object.const_get(model_name)
unless model_class.respond_to?(:columns)
warn "Model '#{model_name}' does not support .columns. Is it an ActiveRecord model?"
exit(1)
end
columns = model_class.columns.reject { |c| %w[id created_at updated_at].include?(c.name) }
if columns.empty?
puts "safe_params"
else
keys = columns.map { |c| c.name.to_sym }
puts "safe_params #{keys.map(&:inspect).join(', ')}"
end
rescue NameError
warn "Model '#{model_name}' not found. Please check the model name."
exit(1)
rescue => e
warn "Unexpected error: #{e.class}: #{e.message}"
exit(1)
end
|