Sha256: c2d5659c25b5e4c14eb5e0c74013f1301f215e7b5787717c3e2e8488cc6edfea

Contents?: true

Size: 980 Bytes

Versions: 6

Compression:

Stored size: 980 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: default_adapter

      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

6 entries across 6 versions & 1 rubygems

Version Path
rom-rails-2.4.0 lib/generators/rom/relation_generator.rb
rom-rails-2.3.1 lib/generators/rom/relation_generator.rb
rom-rails-2.3.0 lib/generators/rom/relation_generator.rb
rom-rails-2.2.0 lib/generators/rom/relation_generator.rb
rom-rails-2.0.0 lib/generators/rom/relation_generator.rb
rom-rails-1.2.0 lib/generators/rom/relation_generator.rb