Sha256: cf66a96cb25b3c69fc111c063a74a5554a5bf5af80cefc1dc07772ccc358dade

Contents?: true

Size: 958 Bytes

Versions: 6

Compression:

Stored size: 958 Bytes

Contents

require 'generators/rom'

if defined? ROM::Repository
  module ROM
    module Generators
      class RepositoryGenerator < Base
        class_option :namespace,
          banner: '--namespace=namespace',
          desc: "specify a struct namespace for the relation", required: true,
          default: ::Rails.application.class.name.split("::").first

        def create_repository_file
          template(
            'repository.rb.erb',
            File.join('app', 'repositories', "#{repository_name}_repository.rb")
          )
        end

      private

        def struct_namespace
          options[:namespace]
        end

        def relation
          class_name.pluralize.underscore
        end

        def model_name
          class_name.singularize.camelcase
        end

        def repository_name
          class_name.singularize.underscore
        end

        def mapper
          repository_name
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

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