Class: Gemical::Configuration
- Inherits:
-
Object
- Object
- Gemical::Configuration
- Includes:
- Singleton
- Defined in:
- lib/gemical/configuration.rb
Instance Attribute Summary collapse
-
#home ⇒ Object
writeonly
Sets the attribute home.
Instance Method Summary collapse
-
#create_root! ⇒ Object
Create a configuration root directory.
-
#credentials ⇒ Pathname
Credentials storage file.
-
#credentials? ⇒ Boolean
True, if credentials are available.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#primary_vault ⇒ Pathname
Primary vault storage file.
-
#primary_vault? ⇒ Boolean
True, if primary vault is available.
-
#root ⇒ Pathname
Credentials store.
-
#root? ⇒ Boolean
True, if configuration root exists.
-
#write!(symbol, *lines) ⇒ Object
Write a file.
Methods included from Singleton
Constructor Details
#initialize ⇒ Configuration
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
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 |
#credentials ⇒ Pathname
Returns 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.
33 34 35 |
# File 'lib/gemical/configuration.rb', line 33 def credentials? readable_file? credentials end |
#primary_vault ⇒ Pathname
Returns 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.
38 39 40 |
# File 'lib/gemical/configuration.rb', line 38 def primary_vault? readable_file? primary_vault end |
#root ⇒ Pathname
Returns 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.
28 29 30 |
# File 'lib/gemical/configuration.rb', line 28 def root? root.directory? && root.readable? end |
#write!(symbol, *lines) ⇒ Object
Write a file
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 |