Sha256: 24e085ad95e437f7113f2bee6a75c68ac2ad3cb24c1f6d63cf0f30a10672ab1c

Contents?: true

Size: 896 Bytes

Versions: 8

Compression:

Stored size: 896 Bytes

Contents

require 'generators/rom'

module ROM
  module Generators
    class CommandsGenerator < Base
      class_option :adapter,
        banner: "--adapter=adapter",
        desc: "specify an adapter to use", required: true,
        default: ROM.adapters.keys.first

      def create_create_command
        template 'create.rb.erb', command_file(:create)
      end

      def create_update_command
        template 'update.rb.erb', command_file(:update)
      end

      def create_delete_command
        template 'delete.rb.erb', command_file(:delete)
      end

      private

      def command_file(command)
        File.join('app', 'commands', "#{command}_#{model_name.downcase}.rb")
      end

      def relation
        class_name.pluralize.underscore
      end

      def model_name
        class_name.singularize
      end

      def adapter
        options[:adapter]
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rom-rails-1.1.1 lib/generators/rom/commands_generator.rb
rom-rails-1.1.0 lib/generators/rom/commands_generator.rb
rom-rails-1.0.1 lib/generators/rom/commands_generator.rb
rom-rails-1.0.0 lib/generators/rom/commands_generator.rb
rom-rails-1.0.0.rc1 lib/generators/rom/commands_generator.rb
rom-rails-1.0.0.beta1 lib/generators/rom/commands_generator.rb
rom-rails-0.9.0 lib/generators/rom/commands_generator.rb
rom-rails-0.9.0.beta1 lib/generators/rom/commands_generator.rb