Sha256: 4ef6950de9110b8405a3e5a68f203874f27e734c4eef2d384c77c883e922950f

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

require 'generators/rom'

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

      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

      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

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rom-rails-0.6.0 lib/generators/rom/form_generator.rb
rom-rails-0.6.0.rc1 lib/generators/rom/form_generator.rb
rom-rails-0.6.0.beta1 lib/generators/rom/form_generator.rb
rom-rails-0.5.0 lib/generators/rom/form_generator.rb
rom-rails-0.5.0.rc1 lib/generators/rom/form_generator.rb
rom-rails-0.5.0.beta1 lib/generators/rom/form_generator.rb
rom-rails-0.4.0 lib/generators/rom/form_generator.rb
rom-rails-0.3.3 lib/generators/rom/form_generator.rb
rom-rails-0.3.2 lib/generators/rom/form_generator.rb
rom-rails-0.3.1 lib/generators/rom/form_generator.rb