class Graphiti::InstallGenerator

Public Instance Methods

install() click to toggle source
# File lib/generators/graphiti/install_generator.rb, line 16
    def install
      to = File.join("app/resources", "application_resource.rb")
      template("application_resource.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

      inject_into_file "config/application.rb", after: "Rails::Application\n" do
        <<-'RUBY'
    # In order for Graphiti to generate links, you need to set the routes host.
    # When not explicitly set, via the HOST env var, this will fall back to
    # the rails server settings.
    # Rails::Server is not defined in console or rake tasks, so this will only
    # use those defaults when they are available.
    routes.default_url_options[:host] = ENV.fetch('HOST') do
      if defined?(Rails::Server)
        argv_options = Rails::Server::Options.new.parse!(ARGV)
        "http://#{argv_options[:Host]}:#{argv_options[:Port]}"
      end
    end
        RUBY
      end

      inject_into_file "spec/rails_helper.rb", after: /RSpec.configure.+^end$/m do
        "\n\nGraphitiSpecHelpers::RSpec.schema!"
      end

      insert_into_file "config/routes.rb", after: "Rails.application.routes.draw do\n" do
        if defined?(VandalUi)
          <<-STR
  scope path: ApplicationResource.endpoint_namespace, defaults: { format: :jsonapi } do
    mount VandalUi::Engine, at: '/vandal'
    # your routes go here
  end
          STR
        else
          <<-STR
  scope path: ApplicationResource.endpoint_namespace, defaults: { format: :jsonapi } do
    # your routes go here
  end
          STR
        end
      end
    end

Private Instance Methods

app_controller_code() click to toggle source
# File lib/generators/graphiti/install_generator.rb, line 72
def app_controller_code
  str = ""
  if defined?(::Responders)
    str << "  include Graphiti::Rails::Responders\n"
  end
  str
end
omit_comments?() click to toggle source
# File lib/generators/graphiti/install_generator.rb, line 68
def omit_comments?
  @options["omit-comments"]
end