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.



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

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.



3
4
5
# File 'lib/ninny/user_config.rb', line 3

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



21
22
23
24
25
# File 'lib/ninny/user_config.rb', line 21

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

#readObject



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

def read
  begin
  config.read unless @read
  rescue TTY::Config::ReadError
    raise MissingUserConfig.new("User config not found, run `ninny setup`")
  end
end

#set(*args) ⇒ Object



17
18
19
# File 'lib/ninny/user_config.rb', line 17

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



13
14
15
# File 'lib/ninny/user_config.rb', line 13

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