Class: MrF::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/mrf/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Project

Returns a new instance of Project.



7
8
9
10
# File 'lib/mrf/project.rb', line 7

def initialize (opts={})
  @secrets_path   = opts.fetch(:secrets_path)
  @gpg_passphrase = opts.fetch(:gpg_passphrase, nil)
end

Instance Attribute Details

#gpg_passphraseObject

Returns the value of attribute gpg_passphrase.



4
5
6
# File 'lib/mrf/project.rb', line 4

def gpg_passphrase
  @gpg_passphrase
end

#secrets_pathObject

Returns the value of attribute secrets_path.



5
6
7
# File 'lib/mrf/project.rb', line 5

def secrets_path
  @secrets_path
end

Instance Method Details

#unpack_secretsObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mrf/project.rb', line 12

def unpack_secrets
  raise "File not found: #{secrets_path}" unless File.exists?(secrets_path)
  keyring = Keyring.new(
    path: secrets_path,
    gpg_passphrase: gpg_passphrase
  )

  keyring.data.reduce({}) do |acc, (filename, data)|
    content = StringIO.new(yaml_file?(filename) ? YAML.dump(data) : data)
    acc.merge(filename => content)
  end
end

#yaml_file?(path) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/mrf/project.rb', line 25

def yaml_file? (path)
  path =~ /\A.*\.yml\Z/
end