Class: Rails::Generators::EncryptionKeyFileGenerator
  
  
  
  
  
    - Inherits:
 
    - 
      Base
      
        
          - Object
 
          
            - Thor::Group
 
          
            - Base
 
          
            - Rails::Generators::EncryptionKeyFileGenerator
 
          
        
        show all
      
     
  
  
  
  
  
  
  
  
  
  
    - Defined in:
 
    - lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb
 
  
  
 
Overview
  
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  Methods inherited from Base
  base_root, class_option, default_source_root, desc, exit_on_failure?, hide!, hook_for, inherited, namespace, remove_hook_for, source_root
  
  
  
  
  
  
  
  
  Methods included from Actions
  #add_source, #environment, #gem, #gem_group, #generate, #git, #github, #initialize, #initializer, #lib, #rails_command, #rake, #rakefile, #readme, #route, #vendor
  
  
  
    Instance Method Details
    
      
  
  
    #add_key_file(key_path)  ⇒ Object 
  
  
  
  
    
      
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 
     | 
    
      # File 'lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb', line 10
def add_key_file(key_path)
  key_path = Pathname.new(key_path)
  unless key_path.exist?
    key = ActiveSupport::EncryptedFile.generate_key
    log "Adding #{key_path} to store the encryption key: #{key}"
    log ""
    log "Save this in a password manager your team can access."
    log ""
    log "If you lose the key, no one, including you, can access anything encrypted with it."
    log ""
    add_key_file_silently(key_path, key)
    log ""
  end
end
     | 
  
 
    
      
  
  
    #add_key_file_silently(key_path, key = nil)  ⇒ Object 
  
  
  
  
    
      
28
29
30
31 
     | 
    
      # File 'lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb', line 28
def add_key_file_silently(key_path, key = nil)
  create_file key_path, key || ActiveSupport::EncryptedFile.generate_key
  key_path.chmod 0600
end 
     | 
  
 
    
      
  
  
    #ignore_key_file(key_path, ignore: key_ignore(key_path))  ⇒ Object 
  
  
  
  
    
      
33
34
35
36
37
38
39
40
41
42
43
44
45
46 
     | 
    
      # File 'lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb', line 33
def ignore_key_file(key_path, ignore: key_ignore(key_path))
  if File.exist?(".gitignore")
    unless File.read(".gitignore").include?(ignore)
      log "Ignoring #{key_path} so it won't end up in Git history:"
      log ""
      append_to_file ".gitignore", ignore
      log ""
    end
  else
    log "IMPORTANT: Don't commit #{key_path}. Add this to your ignore file:"
    log ignore, :on_green
    log ""
  end
end
     | 
  
 
    
      
  
  
    #ignore_key_file_silently(key_path, ignore: key_ignore(key_path))  ⇒ Object 
  
  
  
  
    
      
48
49
50 
     | 
    
      # File 'lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb', line 48
def ignore_key_file_silently(key_path, ignore: key_ignore(key_path))
  append_to_file ".gitignore", ignore if File.exist?(".gitignore")
end
     |