Class: Graphiti::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Graphiti::InstallGenerator
- Includes:
- GeneratorMixin
- Defined in:
- lib/generators/graphiti/install_generator.rb
Instance Method Summary collapse
Methods included from GeneratorMixin
#actions, #actions?, #api_namespace, #graphiti_config, #id_or_rawid, #prompt, #sort_raw_ids, #sort_raw_ids_descending, #update_config!
Instance Method Details
#install ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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 |