Sha256: daf6c95a7f0c55c7dd9c7190329839282ae0262574b0b21af33983e0a9fa880e

Contents?: true

Size: 810 Bytes

Versions: 1

Compression:

Stored size: 810 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

    def copy_specs
      return unless defined?(RSpec)

      path = File.join('spec', 'queries', class_path, "#{file_name}_query_spec.rb")
      empty_directory('spec/queries')
      template('spec.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.4 lib/generators/rails/query_generator.rb