Sha256: 4e2759debab19f76a3ee871fbcf2ebe76a0f7051288027e50144368c7d75ce10

Contents?: true

Size: 588 Bytes

Versions: 1

Compression:

Stored size: 588 Bytes

Contents

# frozen_string_literal: true

require 'rails/generators'

module Rails
  class QueryGenerator < Rails::Generators::NamedBase

    source_root File.expand_path('../templates', __FILE__)
    check_class_collision suffix: 'Query'

    def copy_files
      path = File.join('app', 'queries', class_path, "#{file_name}_query.rb")
      empty_directory('app/queries')
      template('query.rb.tt', path)
    end

    private

    def file_name
      @_file_name ||= remove_possible_suffix(super)
    end

    def remove_possible_suffix(name)
      name.sub(/_?query$/i, '')
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lite-query-1.0.6 lib/generators/rails/query_generator.rb