Class: Ninny::UserConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/ninny/user_config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUserConfig

Returns a new instance of UserConfig.



7
8
9
10
11
12
13
# File 'lib/ninny/user_config.rb', line 7

def initialize
  @config = TTY::Config.new
  @config.filename = '.ninny'
  @config.extname = '.yml'
  @config.prepend_path Dir.home
  @read = false
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/ninny/user_config.rb', line 5

def config
  @config
end

Class Method Details

.configObject



41
42
43
# File 'lib/ninny/user_config.rb', line 41

def self.config
  new
end

Instance Method Details

#gitlab_private_tokenObject



23
24
25
26
27
# File 'lib/ninny/user_config.rb', line 23

def gitlab_private_token
  with_read do
    config.fetch(:gitlab_private_token)
  end
end

#readObject



29
30
31
32
33
# File 'lib/ninny/user_config.rb', line 29

def read
  config.read unless @read
rescue TTY::Config::ReadError
  raise MissingUserConfig, 'User config not found, run `ninny setup`'
end

#set(*args) ⇒ Object



19
20
21
# File 'lib/ninny/user_config.rb', line 19

def set(*args)
  config.set(*args)
end

#with_readObject



35
36
37
38
39
# File 'lib/ninny/user_config.rb', line 35

def with_read
  read
  @read = true
  yield
end

#write(*args) ⇒ Object



15
16
17
# File 'lib/ninny/user_config.rb', line 15

def write(*args)
  config.write(*args)
end