Class: Gemical::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/gemical/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Singleton

included

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



8
9
10
# File 'lib/gemical/configuration.rb', line 8

def initialize
  @home = ENV['HOME']
end

Instance Attribute Details

#home=(value) ⇒ Object (writeonly)

Sets the attribute home

Parameters:

  • value

    the value to set the attribute home to.



6
7
8
# File 'lib/gemical/configuration.rb', line 6

def home=(value)
  @home = value
end

Instance Method Details

#create_root!Object

Create a configuration root directory



43
44
45
46
47
# File 'lib/gemical/configuration.rb', line 43

def create_root!
  return if root?
  FileUtils.mkdir_p root
  FileUtils.chmod_R 0700, root
end

#credentialsPathname

Returns credentials storage file.

Returns:

  • (Pathname)

    credentials storage file



18
19
20
# File 'lib/gemical/configuration.rb', line 18

def credentials
  root.join('credentials')
end

#credentials?Boolean

Returns true, if credentials are available.

Returns:

  • (Boolean)

    true, if credentials are available



33
34
35
# File 'lib/gemical/configuration.rb', line 33

def credentials?
  readable_file? credentials
end

#primary_vaultPathname

Returns primary vault storage file.

Returns:

  • (Pathname)

    primary vault storage file



23
24
25
# File 'lib/gemical/configuration.rb', line 23

def primary_vault
  root.join('primary_vault')
end

#primary_vault?Boolean

Returns true, if primary vault is available.

Returns:

  • (Boolean)

    true, if primary vault is available



38
39
40
# File 'lib/gemical/configuration.rb', line 38

def primary_vault?
  readable_file? primary_vault
end

#rootPathname

Returns credentials store.

Returns:

  • (Pathname)

    credentials store



13
14
15
# File 'lib/gemical/configuration.rb', line 13

def root
  @root ||= Pathname.new File.join(@home, ".gemical")
end

#root?Boolean

Returns true, if configuration root exists.

Returns:

  • (Boolean)

    true, if configuration root exists



28
29
30
# File 'lib/gemical/configuration.rb', line 28

def root?
  root.directory? && root.readable?
end

#write!(symbol, *lines) ⇒ Object

Write a file

Parameters:

  • symbol (Symbol)

    Either :credentials or :primary_vault

  • lines (Array)

    Lines to write



54
55
56
57
58
59
# File 'lib/gemical/configuration.rb', line 54

def write!(symbol, *lines)
  create_root!
  send(symbol).open "w", 0600 do |file|
    file << (lines + ['']).join("\n")
  end
end