Sha256: eea6f39b7013af7329bbe597d2a4af965bedd884d6675a64215e8ed515cce71f

Contents?: true

Size: 1013 Bytes

Versions: 15

Compression:

Stored size: 1013 Bytes

Contents

# frozen_string_literal: true

module Rails
  # rails g api_client
  class ApiClientGenerator < Rails::Generators::NamedBase
    source_root File.expand_path('templates', __dir__)
    check_class_collision suffix: 'ApiClient'

    argument :endpoint,
             type: :string,
             default: 'https://example.com',
             banner: '{schema and hostname}'
    argument :requests,
             type: :array,
             default: %w[get_resource:get:path/to/resource post_resource:post:path/to/resource],
             banner: '{action}:{method}:{path} {action}:{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

15 entries across 15 versions & 1 rubygems

Version Path
my_api_client-0.6.2 lib/generators/rails/api_client_generator.rb
my_api_client-0.6.1 lib/generators/rails/api_client_generator.rb
my_api_client-0.6.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.5.3 lib/generators/rails/api_client_generator.rb
my_api_client-0.5.2 lib/generators/rails/api_client_generator.rb
my_api_client-0.5.1 lib/generators/rails/api_client_generator.rb
my_api_client-0.5.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.4.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.3.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.2.0 lib/generators/rails/api_client_generator.rb
my_api_client-0.1.4 lib/generators/rails/api_client_generator.rb
my_api_client-0.1.3 lib/generators/rails/api_client_generator.rb
my_api_client-0.1.2 lib/generators/rails/api_client_generator.rb
my_api_client-0.1.1 lib/generators/rails/api_client_generator.rb
my_api_client-0.1.0 lib/generators/rails/api_client_generator.rb