lib/generators/rom/form_generator.rb in rom-rails-0.3.0 vs lib/generators/rom/form_generator.rb in rom-rails-0.3.1
- old
+ new
@@ -3,37 +3,46 @@
module ROM
module Generators
class FormGenerator < Base
class_option :command,
banner: "--command=command",
- desc: "specify command to use", required: true
+ desc: "specify command to use"
- def create_command
- type = edit_or_new
+ def create_base_form
+ template "base_form.rb.erb",
+ File.join("app", "forms", "#{file_name.singularize}_form.rb")
+ end
+ def create_new
+ create(:new) if create_new_form?
+ end
+
+ def create_edit
+ create(:edit) if create_edit_form?
+ end
+
+ private
+
+ def create(type)
template "#{type}_form.rb.erb",
File.join("app", "forms", "#{type}_#{file_name.singularize}_form.rb")
end
- private
+ def create_new_form?
+ options[:command].blank? || %w(new create).include?(options[:command].to_s.downcase)
+ end
+ def create_edit_form?
+ options[:command].blank? || %w(edit update).include?(options[:command].to_s.downcase)
+ end
+
def model_name
class_name.singularize.camelcase
end
def relation
class_name.pluralize.underscore
end
- def edit_or_new
- case options[:command].downcase
- when 'edit', 'update'
- :edit
- when 'new', 'create'
- :new
- else
- raise "Unknown command"
- end
- end
end
end
end