Class: TestData::WebpackerYamlGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/test_data/webpacker_yaml_generator.rb

Constant Summary collapse

AFTER_DEVELOPMENT_WEBPACK_STANZA_REGEX =
/^development:/
AFTER_TEST_DATA_WEBPACK_STANZA_REGEX =
/^test_data:\n  <<: \*development/

Instance Method Summary collapse

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/test_data/webpacker_yaml_generator.rb', line 9

def call
  configurator = Configurators::WebpackerYaml.new
  webpacker_config = Wrap::WebpackerConfig.new

  if configurator.verify.looks_good?
    TestData.log.debug "'test_data' section looks good in `config/webpacker.yml'"
  else
    unless webpacker_config.user_config.key?("test_data")
      inject_into_file "config/webpacker.yml", after: AFTER_DEVELOPMENT_WEBPACK_STANZA_REGEX do
        " &development"
      end
      inject_into_file "config/webpacker.yml", before: BEFORE_TEST_STANZA_REGEX do
        "\n          # Used in conjunction with the test_data gem\n          test_data:\n            <<: *development\n\n        YAML\n      end\n    end\n\n    if (missing_entries = webpacker_config.required_entries_missing_from_test_data_config)\n      inject_into_file \"config/webpacker.yml\", after: /^test_data:\\n/ do\n        missing_entries.map { |(key, val)|\n          \"  \#{key}: \#{val.inspect}\\n\"\n        }.join\n      end\n    end\n  end\nend\n"