Class: Heartcheck::Generator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/heartcheck/generators/generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



11
12
13
# File 'lib/heartcheck/generators/generator.rb', line 11

def self.source_root
  File.join(File.dirname(__FILE__), 'templates')
end

Instance Method Details

#generate_initializerObject



19
20
21
# File 'lib/heartcheck/generators/generator.rb', line 19

def generate_initializer
  template('config.rb', initializer_path)
end

#generate_routeObject



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
# File 'lib/heartcheck/generators/generator.rb', line 23

def generate_route
  case framework
  when 'rails'
    instructions(
      'config/routes.rb',
      [
        'mount Heartcheck::App.new, at: "/monitoring"',
        '',
        '# to mount a caching instance:',
        '# mount Heartcheck::CachingApp.new(HeartCheck::App.new, 300),',
        '#   at: "/cached-monitoring" # 300 is the optional cache TTL'
      ].join("\n")
    )
  when 'padrino', 'sinatra'
    instructions(
      'config.ru', [
        'require "heartcheck"',
        '',
        'map "/monitoring" do',
        '  use Heartcheck::App',
        'end',
        '',
        '# or a cached instance:',
        '# map "/cached/monitoring" do',
        '#   use Heartcheck::CachingApp, 300 # 300 is the optional ttl',
        '#   use Heartcheck::App',
        '# end',
      ].join("\n"))
  end
end

#include_empty_linesObject



54
55
56
# File 'lib/heartcheck/generators/generator.rb', line 54

def include_empty_lines
  puts "\n\n"
end

#show_frameworkObject



15
16
17
# File 'lib/heartcheck/generators/generator.rb', line 15

def show_framework
  box framework.capitalize, :green
end