Sha256: 5e8882c42199f810654699e7e62d5407eab57fa889e3aea0422dbe0577866131

Contents?: true

Size: 990 Bytes

Versions: 7

Compression:

Stored size: 990 Bytes

Contents

require 'generators/rom'

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

      class_option :gateway,
        banner: "--gateway=repo",
        desc: "specify a gateway to connect to",
        required: false

      class_option :register,
        banner: "--register=name",
        desc: "specify the registration identifier",
        required: false


      def create_relation_file
        template(
          'relation.rb.erb',
          File.join('app', 'relations', "#{file_name}_relation.rb")
        )
      end

      private

      def dataset
        class_name.underscore.pluralize
      end

      def adapter
        options[:adapter]
      end

      def register_as
        options[:register] || dataset
      end

      def gateway
        options[:gateway]
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rom-rails-0.6.0 lib/generators/rom/relation_generator.rb
rom-rails-0.6.0.rc1 lib/generators/rom/relation_generator.rb
rom-rails-0.6.0.beta1 lib/generators/rom/relation_generator.rb
rom-rails-0.5.0 lib/generators/rom/relation_generator.rb
rom-rails-0.5.0.rc1 lib/generators/rom/relation_generator.rb
rom-rails-0.5.0.beta1 lib/generators/rom/relation_generator.rb
rom-rails-0.4.0 lib/generators/rom/relation_generator.rb