Class: Github::UserConfig
- Inherits:
-
Object
- Object
- Github::UserConfig
show all
- Defined in:
- lib/gistdoit/github/user_config.rb
Instance Method Summary
collapse
Constructor Details
#initialize(file_path = File.expand_path('~') + '/.gistdoit') ⇒ UserConfig
Do we actually need an instance here. Do we require state at any point?
6
7
8
|
# File 'lib/gistdoit/github/user_config.rb', line 6
def initialize(file_path = File.expand_path('~') + '/.gistdoit')
@file_path = file_path
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
29
30
31
|
# File 'lib/gistdoit/github/user_config.rb', line 29
def method_missing(symbol, *args)
all[symbol.to_s]
end
|
Instance Method Details
#[](key) ⇒ Object
25
26
27
|
# File 'lib/gistdoit/github/user_config.rb', line 25
def [](key)
all[key]
end
|
#all ⇒ Object
20
21
22
23
|
# File 'lib/gistdoit/github/user_config.rb', line 20
def all
file = File.read(@file_path)
YAML.load(file)
end
|
#has_github_username? ⇒ Boolean
16
17
18
|
# File 'lib/gistdoit/github/user_config.rb', line 16
def has_github_username?
YAML.load(File.readlines(@file_path).select { |line| !line.include?('---') }.join).key?('github_username')
end
|
#set_github_username(username) ⇒ Object
10
11
12
13
14
|
# File 'lib/gistdoit/github/user_config.rb', line 10
def set_github_username(username)
File.open(@file_path, 'a') do |file|
file << YAML.dump({ 'github_username' => username })
end
end
|