Class: Imageomatic::KeyGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/imageomatic/key_generator.rb

Overview

Generates random keys for environments.

Constant Summary collapse

LENGTH =
14
DELIMITER =
"_".freeze
ENVIRONMENT =
:development

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment: ENVIRONMENT) ⇒ KeyGenerator

Returns a new instance of KeyGenerator.



12
13
14
# File 'lib/imageomatic/key_generator.rb', line 12

def initialize(environment: ENVIRONMENT)
  @environment = environment
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



10
11
12
# File 'lib/imageomatic/key_generator.rb', line 10

def environment
  @environment
end

Instance Method Details

#env_varsObject



24
25
26
27
28
29
# File 'lib/imageomatic/key_generator.rb', line 24

def env_vars
  <<~ENVARS
  IMAGEOMATIC_SECRET_KEY=#{secret_key}
  IMAGEOMATIC_PUBLIC_KEY=#{public_key}
  ENVARS
end

#generate(*scopes) ⇒ Object



31
32
33
34
35
36
# File 'lib/imageomatic/key_generator.rb', line 31

def generate(*scopes)
  scopes
    .prepend(environment)
    .append(random)
    .join(DELIMITER)
end

#public_keyObject



16
17
18
# File 'lib/imageomatic/key_generator.rb', line 16

def public_key
  generate :public
end

#secret_keyObject



20
21
22
# File 'lib/imageomatic/key_generator.rb', line 20

def secret_key
  generate :secret
end