Class: Rails::Generators::EncryptionKeyFileGenerator
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
| Class Chain: 
          self,
           Base,
          Thor::Group | |
| Instance Chain: | |
| Inherits: | Rails::Generators::Base 
 | 
| Defined in: | railties/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb | 
Class Attribute Summary
Base - Inherited
Class Method Summary
Base - Inherited
| .base_root | Returns the base root for a common set of generators. | 
| .default_source_root | Returns the default source root for a given generator. | 
| .desc | Tries to get the description from a USAGE file one folder above the source root otherwise uses a default description. | 
| .hide! | Convenience method to hide this generator from the available ones when running rails generator command. | 
| .hook_for | Invoke a generator based on the value supplied by the user to the given option named “name”. | 
| .namespace | Convenience method to get the namespace from the class name. | 
| .remove_hook_for | Remove a previously added hook. | 
| .source_root | Returns the source root for this generator using default_source_root as default. | 
| .add_shebang_option! | Small macro to add ruby as an option to the generator with proper default value plus an instance helper method called shebang. | 
| .banner | Use Rails default banner. | 
| .base_name | Sets the base_name taking into account the current class namespace. | 
| .default_aliases_for_option | Returns default aliases for the option name given doing a lookup in aliases. | 
| .default_for_option | Returns default for the option name given doing a lookup in config. | 
| .default_generator_root, | |
| .default_value_for_option | Returns the default value for the option name given doing a lookup in options. | 
| .generator_name | Removes the namespaces and get the generator name. | 
| .usage_path, | |
| .class_option | |
| .inherited | Cache source root and add lib/generators/base/generator/templates to source paths. | 
| .hooks | Keep hooks configuration that are used on prepare_for_invocation. | 
| .prepare_for_invocation | Prepare class invocation to search on  | 
Instance Attribute Summary
Base - Inherited
Instance Method Summary
- #add_key_file(key_path)
- #add_key_file_silently(key_path, key = nil)
- #ignore_key_file(key_path, ignore: key_ignore(key_path))
- #ignore_key_file_silently(key_path, ignore: key_ignore(key_path))
- #key_ignore(key_path) private
Base - Inherited
| #class_collisions | Check whether the given class names are already taken by user application or Ruby on  | 
| #extract_last_module | Takes in an array of nested modules and extracts the last module. | 
| #indent, | |
| #module_namespacing | Wrap block with namespace of current application if namespace exists and is not skipped. | 
| #namespace, #namespace_dirs, #namespaced_path, #wrap_with_namespace | |
Actions - Included
| #add_source | Add the given source to  | 
| #application | Alias for Actions#environment. | 
| #environment | Adds configuration code to a Rails runtime environment. | 
| #gem | Adds a  | 
| #gem_group | Wraps gem entries inside a group. | 
| #generate | Runs another generator. | 
| #git | Runs one or more git commands. | 
| #github, | |
| #initializer | Creates an initializer file in  | 
| #lib | Creates a file in  | 
| #rails_command | Runs the specified Rails command. | 
| #rake | Runs the specified Rake task. | 
| #rakefile | Creates a Rake tasks file in  | 
| #readme | Reads the given file at the source root and prints it in the console. | 
| #route | Make an entry in Rails routing file  | 
| #vendor | Creates a file in  | 
| #append_file_with_newline | Append string to a file with a newline if necessary. | 
| #execute_command | Runs the supplied command using either  | 
| #indentation | Returns a string corresponding to the current indentation level (i.e. 2 *  | 
| #log | Define log for backwards compatibility. | 
| #match_file, | |
| #optimize_indentation | Returns optimized string with indentation. | 
| #quote | Always returns value in double quotes. | 
| #rebase_indentation | Alias for Actions#optimize_indentation. | 
| #route_namespace_pattern, | |
| #with_indentation | Increases the current indentation indentation level for the duration of the given block, and decreases it after the block ends. | 
| #initialize | |
Instance Method Details
#add_key_file(key_path)
[ GitHub ]# File 'railties/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)
[ GitHub ]# File 'railties/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, perm: 0600 end
#ignore_key_file(key_path, ignore: key_ignore(key_path))
[ GitHub ]# File 'railties/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb', line 32
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))
[ GitHub ]# File 'railties/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb', line 47
def ignore_key_file_silently(key_path, ignore: key_ignore(key_path)) append_to_file ".gitignore", ignore if File.exist?(".gitignore") end
#key_ignore(key_path) (private)
[ GitHub ]# File 'railties/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb', line 52
def key_ignore(key_path) [ "", "/#{key_path}", "" ].join("\n") end