Sha256: 3958acf86cc8d8ce962037da481bc584011f2810f354d3941ccb43cdd1b52d61

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

class PowerApi::ExposedApiConfigGenerator < Rails::Generators::Base
  source_root File.expand_path('templates', __dir__)

  class_option(
    :authenticated_resources,
    type: 'array',
    default: [],
    desc: 'define which model or models will be token authenticatable'
  )

  def add_base_controller
    create_file(
      helper.exposed_base_controller_path,
      helper.exposed_base_controller_tpl
    )
  end

  def install_rswag
    generate "rswag:ui:install"
    generate "rswag:api:install"
    generate "rswag:specs:install"

    create_file(helper.rswag_ui_initializer_path, helper.rswag_ui_initializer_tpl, force: true)
    create_file(helper.swagger_helper_path, helper.swagger_helper_tpl, force: true)
    create_file(helper.spec_swagger_path)
    create_file(helper.spec_integration_path)
  end

  def install_first_version
    generate "power_api:version 1"
  end

  def install_simple_token_auth
    create_file(
      helper.simple_token_auth_initializer_path,
      helper.simple_token_auth_initializer_tpl,
      force: true
    )

    helper.authenticated_resources.each do |resource|
      generate resource.authenticated_resource_migration

      insert_into_file(
        resource.path,
        helper.simple_token_auth_method,
        after: resource.class_definition_line
      )
    end
  end

  private

  def helper
    @helper ||= PowerApi::GeneratorHelpers.new(
      authenticated_resources: options[:authenticated_resources]
    )
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
power_api-2.0.2 lib/generators/power_api/exposed_api_config/exposed_api_config_generator.rb
power_api-2.0.1 lib/generators/power_api/exposed_api_config/exposed_api_config_generator.rb
power_api-2.0.0 lib/generators/power_api/exposed_api_config/exposed_api_config_generator.rb