Class: DurableStreams::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/durable_streams/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_binstubObject



23
24
25
26
# File 'lib/generators/durable_streams/install/install_generator.rb', line 23

def create_binstub
  template "bin/durable-streams", "bin/durable-streams"
  chmod "bin/durable-streams", 0755, verbose: false
end

#create_initializerObject



15
16
17
# File 'lib/generators/durable_streams/install/install_generator.rb', line 15

def create_initializer
  template "initializer.rb", "config/initializers/durable_streams.rb"
end

#create_server_configObject



19
20
21
# File 'lib/generators/durable_streams/install/install_generator.rb', line 19

def create_server_config
  template "durable_streams.yml", "config/durable_streams.yml"
end

#show_instructionsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/generators/durable_streams/install/install_generator.rb', line 52

def show_instructions
  say ""
  say "  Durable Streams installed!", :green
  say ""
  say "  Configuration: config/durable_streams.yml"
  say "  Server binary: bin/durable-streams (auto-downloads on first run)"
  say ""
  say "  Start development:"
  say "    bin/dev"
  say ""
  say "  Stream endpoint: http://localhost:4437/v1/streams/*"
  say ""
  say "  Power users: set DURABLE_STREAMS_CONFIG to use a raw server config file."
  say ""
end

#update_gitignoreObject



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

def update_gitignore
  gitignore_path = File.join(destination_root, ".gitignore")

  if File.exist?(gitignore_path) && !File.read(gitignore_path).match?(/^bin\/dist/)
    append_file ".gitignore", "\n# Durable Streams server binary\nbin/dist/\n"
  end
end

#update_procfileObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/generators/durable_streams/install/install_generator.rb', line 28

def update_procfile
  return if options[:skip_procfile]

  procfile = "Procfile.dev"
  procfile_path = File.join(destination_root, procfile)
  entry = "streams: bin/durable-streams\n"

  if File.exist?(procfile_path)
    contents = File.read(procfile_path)
    return if contents.match?(/^streams:/)

    entry = "\n#{entry}" unless contents.end_with?("\n")
    append_file procfile, entry
  end
end