Sha256: 40d10ea4d2962172c2f320b180914f6247de1224122a4de506dfde2e56a461f5

Contents?: true

Size: 908 Bytes

Versions: 18

Compression:

Stored size: 908 Bytes

Contents

# frozen_string_literal: true

require_relative '../generator_helper'

module Rails
  # rails g api_client
  class ApiClientGenerator < Rails::Generators::NamedBase
    include MyApiClient::GeneratorHelper

    source_root File.expand_path('templates', __dir__)
    check_class_collision suffix: 'ApiClient'

    argument :requests,
             type: :array,
             default: %w[get:path/to/resource post:path/to/resource],
             banner: '{method}:{path} {method}:{path}'

    def generate_root_class
      file_path = File.join('app/api_clients', 'application_api_client.rb')
      return if File.exist?(file_path)

      template 'application_api_client.rb.erb', file_path
    end

    def generate_api_client
      file_path = File.join('app/api_clients', "#{route_url.singularize}_api_client.rb")
      template 'api_client.rb.erb', file_path
    end

    hook_for :test_framework
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
my_api_client-0.17.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.16.1 lib/generators/rails/api_client_generator.rb
my_api_client-0.16.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.15.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.14.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.14.0.pre lib/generators/rails/api_client_generator.rb
my_api_client-0.13.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.12.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.11.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.10.3 lib/generators/rails/api_client_generator.rb
my_api_client-0.10.2 lib/generators/rails/api_client_generator.rb
my_api_client-0.10.1 lib/generators/rails/api_client_generator.rb
my_api_client-0.10.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.9.2 lib/generators/rails/api_client_generator.rb
my_api_client-0.9.1 lib/generators/rails/api_client_generator.rb
my_api_client-0.9.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.8.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.7.0 lib/generators/rails/api_client_generator.rb