Class: Voltron::Flash::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#inject_initializerObject



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
# File 'lib/generators/voltron/flash/install_generator.rb', line 10

def inject_initializer

  voltron_initialzer_path = Rails.root.join("config", "initializers", "voltron.rb")

  unless File.exist? voltron_initialzer_path
    unless system("cd #{Rails.root.to_s} && rails generate voltron:install")
      puts "Voltron initializer does not exist. Please ensure you have the 'voltron' gem installed and run `rails g voltron:install` to create it"
      return false
    end
  end

  current_initiailzer = File.read voltron_initialzer_path

  unless current_initiailzer.match(Regexp.new(/# === Voltron Flash Configuration ===/))
    inject_into_file(voltron_initialzer_path, after: "Voltron.setup do |config|\n") do
"\n  # === Voltron Flash Configuration ===\n\n  # What http header the flash messages should be added to on ajax responses\n  config.flash.header = \"X-Flash\"\n\n  # Whether to group flash messages by type, or give each flash message it's own line, complete with close icon\n  config.flash.group = true\n"
    end
  end
end