Class: Batteries::Tasks::Secret
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Batteries::Tasks::Secret
- Defined in:
- lib/batteries/tasks/secret.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#generator ⇒ Object
Returns the value of attribute generator.
-
#name ⇒ Object
Returns the value of attribute name.
-
#secret_file ⇒ Object
Returns the value of attribute secret_file.
Instance Method Summary collapse
- #default_description ⇒ Object
- #default_generator ⇒ Object
- #define ⇒ Object
-
#initialize(name = :secret, options: {}) {|_self| ... } ⇒ Secret
constructor
A new instance of Secret.
Constructor Details
#initialize(name = :secret, options: {}) {|_self| ... } ⇒ Secret
Returns a new instance of Secret.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/batteries/tasks/secret.rb', line 10 def initialize(name = :secret, options: {}) @name = name @secret_file = .fetch(:secret_file) { ".session_secret" } @description = .fetch(:description) { default_description } @generator = .fetch(:generator) { method(:default_generator) } yield self if block_given? define end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/batteries/tasks/secret.rb', line 8 def description @description end |
#generator ⇒ Object
Returns the value of attribute generator.
8 9 10 |
# File 'lib/batteries/tasks/secret.rb', line 8 def generator @generator end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/batteries/tasks/secret.rb', line 8 def name @name end |
#secret_file ⇒ Object
Returns the value of attribute secret_file.
8 9 10 |
# File 'lib/batteries/tasks/secret.rb', line 8 def secret_file @secret_file end |
Instance Method Details
#default_description ⇒ Object
33 34 35 |
# File 'lib/batteries/tasks/secret.rb', line 33 def default_description "Generate a session secret in #{secret_file}" end |
#default_generator ⇒ Object
28 29 30 31 |
# File 'lib/batteries/tasks/secret.rb', line 28 def default_generator require "securerandom" File.write(secret_file, SecureRandom.random_bytes(40)) end |
#define ⇒ Object
21 22 23 24 25 26 |
# File 'lib/batteries/tasks/secret.rb', line 21 def define desc description task name do default_generator.call if default_generator.respond_to?(:call) end end |