Class: EasyCreds::Configuration
- Inherits:
-
Object
- Object
- EasyCreds::Configuration
- Defined in:
- lib/easy_creds/configuration.rb
Instance Attribute Summary collapse
-
#default_provider ⇒ Object
Returns the value of attribute default_provider.
-
#default_template ⇒ Object
Returns the value of attribute default_template.
-
#default_vault ⇒ Object
Returns the value of attribute default_vault.
-
#editor ⇒ Object
Returns the value of attribute editor.
-
#global_dir ⇒ Object
Returns the value of attribute global_dir.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#schema_version ⇒ Object
Returns the value of attribute schema_version.
-
#templates_dir ⇒ Object
Returns the value of attribute templates_dir.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #resolved_templates_dir ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/easy_creds/configuration.rb', line 14 def initialize @global_dir = File.('~/.easy_creds') @default_provider = :onepassword @default_vault = nil @templates_dir = nil @default_template = :default @editor = ENV['VISUAL'] || ENV.fetch('EDITOR', nil) @log_level = :debug @schema_version = 1 end |
Instance Attribute Details
#default_provider ⇒ Object
Returns the value of attribute default_provider.
5 6 7 |
# File 'lib/easy_creds/configuration.rb', line 5 def default_provider @default_provider end |
#default_template ⇒ Object
Returns the value of attribute default_template.
5 6 7 |
# File 'lib/easy_creds/configuration.rb', line 5 def default_template @default_template end |
#default_vault ⇒ Object
Returns the value of attribute default_vault.
5 6 7 |
# File 'lib/easy_creds/configuration.rb', line 5 def default_vault @default_vault end |
#editor ⇒ Object
Returns the value of attribute editor.
5 6 7 |
# File 'lib/easy_creds/configuration.rb', line 5 def editor @editor end |
#global_dir ⇒ Object
Returns the value of attribute global_dir.
5 6 7 |
# File 'lib/easy_creds/configuration.rb', line 5 def global_dir @global_dir end |
#log_level ⇒ Object
Returns the value of attribute log_level.
5 6 7 |
# File 'lib/easy_creds/configuration.rb', line 5 def log_level @log_level end |
#schema_version ⇒ Object
Returns the value of attribute schema_version.
5 6 7 |
# File 'lib/easy_creds/configuration.rb', line 5 def schema_version @schema_version end |
#templates_dir ⇒ Object
Returns the value of attribute templates_dir.
5 6 7 |
# File 'lib/easy_creds/configuration.rb', line 5 def templates_dir @templates_dir end |
Class Method Details
.load_file(path) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/easy_creds/configuration.rb', line 29 def self.load_file(path) return Configuration.new unless File.exist?(path) raw = YAML.safe_load_file(path) || {} cfg = Configuration.new cfg.global_dir = raw['global_dir'] if raw['global_dir'] cfg.default_vault = raw['default_vault'] cfg.default_provider = (raw['default_provider']&.to_sym || :onepassword) cfg.default_template = (raw['default_template']&.to_sym || :default) cfg.templates_dir = raw['templates_dir'] cfg.editor = raw['editor'] || ENV['VISUAL'] || ENV.fetch('EDITOR', nil) cfg.log_level = (raw['log_level']&.to_sym || :debug) cfg.schema_version = raw['schema_version'] || 1 cfg end |
.write_file!(cfg, path) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/easy_creds/configuration.rb', line 45 def self.write_file!(cfg, path) data = { 'schema_version' => 2, 'global_dir' => cfg.global_dir, 'default_vault' => cfg.default_vault, 'default_provider' => cfg.default_provider.to_s, 'default_template' => cfg.default_template.to_s, 'templates_dir' => cfg.templates_dir, 'editor' => cfg.editor, 'log_level' => cfg.log_level.to_s }.compact FileUtils.mkdir_p(File.dirname(path)) File.write(path, data.to_yaml) FileUtils.chmod(0o600, path) end |
Instance Method Details
#resolved_templates_dir ⇒ Object
25 26 27 |
# File 'lib/easy_creds/configuration.rb', line 25 def resolved_templates_dir @templates_dir || File.join(global_dir, 'templates') end |