Class: WideEvents::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- WideEvents::Generators::InstallGenerator
show all
- Includes:
- SkillInstaller
- Defined in:
- lib/generators/wide_events/install/install_generator.rb
Constant Summary
SkillInstaller::SKILLS_ROOT
Instance Method Summary
collapse
#copy_wide_events_skills
Instance Method Details
#add_agents_section ⇒ Object
Idempotent: a second run of this generator must not duplicate the
section in an AGENTS.md it already added it to.
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/generators/wide_events/install/install_generator.rb', line 25
def add_agents_section
section = File.read(File.expand_path("templates/agents_md_section.md", __dir__))
path = File.join(destination_root, "AGENTS.md")
if File.exist?(path)
if File.read(path).include?(section.strip)
say_status :identical, "AGENTS.md"
else
append_to_file "AGENTS.md", "\n#{section}"
end
else
create_file "AGENTS.md", section
end
end
|
#create_initializer ⇒ Object
11
12
13
|
# File 'lib/generators/wide_events/install/install_generator.rb', line 11
def create_initializer
copy_file "initializer.rb", "config/initializers/wide_events.rb"
end
|
#create_registry ⇒ Object
15
16
17
|
# File 'lib/generators/wide_events/install/install_generator.rb', line 15
def create_registry
copy_file "registry.yml", "config/wide_event/registry.yml"
end
|
#install_skills ⇒ Object
19
20
21
|
# File 'lib/generators/wide_events/install/install_generator.rb', line 19
def install_skills
copy_wide_events_skills
end
|
#wire_test_helper ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/generators/wide_events/install/install_generator.rb', line 39
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", <<~RUBY.indent(4),
include WideEvent::TestHelper
teardown { assert_registered_wide_event_attributes }
RUBY
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
teardown { assert_registered_wide_event_attributes }
MSG
end
end
|