Class: Voltron::Encrypt::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#copy_blacklistObject



51
52
53
54
55
# File 'lib/generators/voltron/encrypt/install_generator.rb', line 51

def copy_blacklist
  unless File.exist? Rails.root.join("config", "locales", "blacklist.txt")
    copy_file "config/locales/blacklist.txt", Rails.root.join("config", "locales", "blacklist.txt")
  end
end

#copy_migrationsObject



57
58
59
# File 'lib/generators/voltron/encrypt/install_generator.rb', line 57

def copy_migrations
  copy_migration "create_voltron_ids"
end

#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
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/voltron/encrypt/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 Encrypt Configuration ===/))
    inject_into_file(voltron_initialzer_path, after: "Voltron.setup do |config|\n") do
<<-CONTENT

  # === Voltron Encrypt Configuration ===

  # The offset used in generating base64 encoded ids. A higher number means larger ids (i.e. - "7feIds" instead of "6f"),
  # but can potentially produce large base64 encoded ids
  # DON'T change this number once records whose id's are being encoded exist in the database
  # as all decoded ids will be incorrect
  # config.encrypt.offset = 262144

  # The location of the blacklist, words that should NOT be permitted in the form of generated ids
  # Each word should be on it's own line, and only contain [A-Z], no spaces, dashes, underscores, or numbers
  # Each word is automatically matched against it's literal, case-insensitive, and l33t spellings, with dashes
  # and underscores optionally preceding/following each character.
  # i.e. - the blacklist word "toke" will match [toke, tOKE, 7oke, t0k3, t-o-k-e, -t0--k3--, etc...]
  # config.encrypt.blacklist = Rails.root.join("config", "locales", "blacklist.txt")

  # The seed used to randomize base 64 characters. Once set, it should NOT EVER be changed.
  # Doing so will result in incorrect decoded ids, followed by large crowds with pitchforks and torches
  # Running `rake secret` is a good way to generate a random seed for this config value
  # config.encrypt.seed = ""
CONTENT
    end
  end
end