Class: TinyZap::KeyGenerator
- Inherits:
-
Object
- Object
- TinyZap::KeyGenerator
- Defined in:
- lib/tinyzap/key_generator.rb
Overview
Generates random keys for environments.
Constant Summary collapse
- LENGTH =
14
- DELIMITER =
"_".freeze
- ENVIRONMENT =
:development
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
Instance Method Summary collapse
- #env_vars ⇒ Object
- #generate(*scopes) ⇒ Object
-
#initialize(environment: ENVIRONMENT) ⇒ KeyGenerator
constructor
A new instance of KeyGenerator.
- #public_key ⇒ Object
- #secret_key ⇒ Object
Constructor Details
#initialize(environment: ENVIRONMENT) ⇒ KeyGenerator
Returns a new instance of KeyGenerator.
12 13 14 |
# File 'lib/tinyzap/key_generator.rb', line 12 def initialize(environment: ENVIRONMENT) @environment = environment end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
10 11 12 |
# File 'lib/tinyzap/key_generator.rb', line 10 def environment @environment end |
Instance Method Details
#env_vars ⇒ Object
24 25 26 27 28 29 |
# File 'lib/tinyzap/key_generator.rb', line 24 def env_vars <<~ENVARS TINYZAP_SECRET_KEY=#{secret_key} TINYZAP_PUBLIC_KEY=#{public_key} ENVARS end |
#generate(*scopes) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/tinyzap/key_generator.rb', line 31 def generate(*scopes) scopes .prepend(environment) .append(random) .join(DELIMITER) end |
#public_key ⇒ Object
16 17 18 |
# File 'lib/tinyzap/key_generator.rb', line 16 def public_key generate :public end |
#secret_key ⇒ Object
20 21 22 |
# File 'lib/tinyzap/key_generator.rb', line 20 def secret_key generate :secret end |