Class: Nv::Config
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Nv::Config
- Defined in:
- lib/nv/config.rb
Instance Method Summary collapse
-
#initialize(config_path) ⇒ Config
constructor
A new instance of Config.
- #save ⇒ Object
- #verify_for_authentication ⇒ Object
- #verify_for_authentication!(cmd) ⇒ Object
Constructor Details
#initialize(config_path) ⇒ Config
Returns a new instance of Config.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/nv/config.rb', line 13 def initialize(config_path) # Initialize config file @config_path = config_path config_dir = File.dirname(@config_path) Dir.mkdir(config_dir) unless Dir.exist?(config_dir) FileUtils.touch(@config_path) unless File.exist?(@config_path) @config = YAML.load(open(@config_path).read) || {} super(@config) end |
Instance Method Details
#save ⇒ Object
25 26 27 28 29 |
# File 'lib/nv/config.rb', line 25 def save File.open(@config_path, 'w') do |f| f.print YAML.dump(transform_keys(self.to_h){|k| k.to_s}) end end |
#verify_for_authentication ⇒ Object
31 32 33 |
# File 'lib/nv/config.rb', line 31 def verify_for_authentication self.email && self.password end |
#verify_for_authentication!(cmd) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/nv/config.rb', line 35 def verify_for_authentication!(cmd) unless verify_for_authentication puts <<-EOD.undent `nv #{cmd}` should be given email and password. $ nv config email <email> $ nv config password <password> EOD exit end end |