Class: WideEvents::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_agents_sectionObject



16
17
18
19
20
21
22
23
# File 'lib/generators/wide_events/install/install_generator.rb', line 16

def add_agents_section
  section = File.read(File.expand_path("templates/agents_md_section.md", __dir__))
  if File.exist?(File.join(destination_root, "AGENTS.md"))
    append_to_file "AGENTS.md", "\n#{section}"
  else
    create_file "AGENTS.md", section
  end
end

#create_initializerObject



8
9
10
# File 'lib/generators/wide_events/install/install_generator.rb', line 8

def create_initializer
  copy_file "initializer.rb", "config/initializers/wide_events.rb"
end

#create_registryObject



12
13
14
# File 'lib/generators/wide_events/install/install_generator.rb', line 12

def create_registry
  copy_file "registry.yml", "config/wide_event/registry.yml"
end

#wire_test_helperObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/wide_events/install/install_generator.rb', line 25

def wire_test_helper
  path = File.join(destination_root, "test/test_helper.rb")
  content = File.exist?(path) ? File.read(path) : ""
  if content.match?(%r{require "rails/test_help"\n}) && content.match?(/class TestCase\n/)
    inject_into_file "test/test_helper.rb", "require \"wide_event/test_helper\"\n",
      after: %r{require "rails/test_help"\n}
    inject_into_file "test/test_helper.rb", "    include WideEvent::TestHelper\n",
      after: /class TestCase\n/
  else
    say_status :skip, "test/test_helper.rb (not found or unrecognized) - wire the test helper manually:", :yellow
    say <<~MSG
          require "wide_event/test_helper"   # after rails/test_help
          include WideEvent::TestHelper      # inside ActiveSupport::TestCase
    MSG
  end
end