Sha256: c331042171bbfad16a629d72b84e09cd1cb2aa92642ab6bd6b9df54d1ed73b68

Contents?: true

Size: 791 Bytes

Versions: 3

Compression:

Stored size: 791 Bytes

Contents

require 'generators/rom'

module ROM
  module Generators
    class FormGenerator < Base
      class_option :command,
        banner: "--command=command",
        desc: "specify command to use", required: true

      def create_command
        type = edit_or_new

        template "#{type}_form.rb.erb",
          File.join("app", "forms", "#{type}_#{file_name.singularize}_form.rb")
      end

      private

      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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-rails-0.3.0 lib/generators/rom/form_generator.rb
rom-rails-0.3.0.rc1 lib/generators/rom/form_generator.rb
rom-rails-0.3.0.beta1 lib/generators/rom/form_generator.rb