class JsonapiSuite::InstallGenerator

Public Instance Methods

create_initializer() click to toggle source
# File lib/generators/jsonapi_suite/install_generator.rb, line 12
def create_initializer
  to = File.join('config/initializers', 'jsonapi.rb')
  template('initializer.rb.erb', to)

  to = File.join('config/initializers', "strong_resources.rb")
  template('strong_resources.rb.erb', to)

  inject_into_file 'app/controllers/application_controller.rb', after: "class ApplicationController < ActionController::API\n" do
    app_controller_code
  end

  inject_into_file 'app/controllers/application_controller.rb', after: "class ApplicationController < ActionController::Base\n" do
    app_controller_code
  end
end

Private Instance Methods

app_controller_code() click to toggle source
# File lib/generators/jsonapi_suite/install_generator.rb, line 30
def app_controller_code
  str = ""
  unless omit_comments?
    str << "  # Bootstrap jsonapi_suite with relevant modules\n"
  end
  str << "  include JsonapiSuite::ControllerMixin\n"
  str << "\n"
  str << "  register_exception JsonapiCompliable::Errors::RecordNotFound,\n"
  str << "    status: 404\n"
  str << "\n"
  unless omit_comments?
    str << "  # Catch all exceptions and render a JSONAPI-compliable error payload\n"
    str << "  # For additional documentation, see https://jsonapi-suite.github.io/jsonapi_errorable\n"
  end
  str << "  rescue_from Exception do |e|\n"
  str << "    handle_exception(e)\n"
  str << "  end\n\n"
  str
end
omit_comments?() click to toggle source
# File lib/generators/jsonapi_suite/install_generator.rb, line 50
def omit_comments?
  !!@options['omit-comments']
end