Class: Stoplight::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/stoplight/install/install_generator.rb,
sig/_private/generators/stoplight/install/install_generator.rbs

Overview

:nodoc:

Constant Summary collapse

ROUTES_PATH =

Returns:

  • (String)
"config/routes.rb"
STOPLIGHT_CONFIG_TEMPLATE =

Returns:

  • (String)
"stoplight.rb.erb"
INITIALIZERS_PATH =

Returns:

  • (String)
"config/initializers"
AFTER_INSTALL_NOTIFICATION =

Returns:

  • (String)
<<~TEXT
  \nThank you for using stoplight!
  Now to finish configuration:
  * Run `bundle` from the project root to install new gems
  * Go to 'config/initializers/stoplight.rb' to set up connection to Redis.\n
TEXT
STOPLIGHT_ADMIN_ROUTE =

Returns:

  • (String)
<<-RUBY
  mount Stoplight::Admin => '/stoplights'
RUBY
STOPLIGHT_AUTH =

Returns:

  • (String)
<<-RUBY
  Stoplight::Admin.use(Rack::Auth::Basic) do |username, password|
    username == ENV["STOPLIGHT_ADMIN_USERNAME"] && password == ENV["STOPLIGHT_ADMIN_PASSWORD"]
  end
RUBY

Instance Method Summary collapse

Instance Method Details

#copy_filevoid

This method returns an undefined value.

Parameters:

  • (String)
  • (String)


18
# File 'sig/_private/generators/stoplight/install/install_generator.rbs', line 18

def copy_file: (String, String) -> void

#generate_admin_panelvoid

This method returns an undefined value.



67
68
69
70
71
72
73
# File 'lib/generators/stoplight/install/install_generator.rb', line 67

def generate_admin_panel
  if options[:with_admin_panel]
    route_config = "#{STOPLIGHT_AUTH}#{STOPLIGHT_ADMIN_ROUTE}\n"

    inject_into_file ROUTES_PATH, route_config, after: ".application.routes.draw do\n"
  end
end

#generate_initializervoid

This method returns an undefined value.



62
63
64
65
# File 'lib/generators/stoplight/install/install_generator.rb', line 62

def generate_initializer
  initializer_template = STOPLIGHT_CONFIG_TEMPLATE
  copy_file initializer_template, "#{INITIALIZERS_PATH}/stoplight.rb"
end

#generate_redis_gemvoid

This method returns an undefined value.



44
45
46
47
48
49
# File 'lib/generators/stoplight/install/install_generator.rb', line 44

def generate_redis_gem
  if options[:with_admin_panel]
    conf = "\ngem 'redis'"
    inject_into_file "Gemfile", conf
  end
end

#generate_sinatra_depsvoid

This method returns an undefined value.



51
52
53
54
55
56
57
58
59
60
# File 'lib/generators/stoplight/install/install_generator.rb', line 51

def generate_sinatra_deps
  if options[:with_admin_panel]
    conf = <<~RUBY
      gem 'sinatra', require: false
      gem 'sinatra-contrib', require: false
    RUBY

    inject_into_file "Gemfile", "\n#{conf}"
  end
end

#inject_into_filevoid

This method returns an undefined value.

Parameters:

  • path (String)
  • what (String)
  • after: (String)


19
# File 'sig/_private/generators/stoplight/install/install_generator.rbs', line 19

def inject_into_file: (String path, String what, ?after: String) -> void

#optionsHash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


11
# File 'sig/_private/generators/stoplight/install/install_generator.rbs', line 11

def options: -> Hash[Symbol, untyped]

#redis_configuration_notificationvoid

This method returns an undefined value.



75
76
77
# File 'lib/generators/stoplight/install/install_generator.rb', line 75

def redis_configuration_notification
  print AFTER_INSTALL_NOTIFICATION
end