Class: Twat::Config
- Inherits:
-
Object
show all
- Defined in:
- lib/twat/config.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth) ⇒ Object
43
44
45
|
# File 'lib/twat/config.rb', line 43
def method_missing(meth)
self[meth]
end
|
Class Method Details
.consumer_info ⇒ Object
56
57
58
59
60
61
|
# File 'lib/twat/config.rb', line 56
def self.consumer_info
{
consumer_key: "jtI2q3Z4NIJAehBG4ntPIQ",
consumer_secret: "H6vQOGGn9qVJJa9lWyTd2s8ZZRXG4kh3SMfvZ2uxOXE"
}
end
|
Instance Method Details
#[]=(k, v) ⇒ Object
63
64
65
|
# File 'lib/twat/config.rb', line 63
def []=(k, v)
config[k] = v
end
|
#accounts ⇒ Object
47
48
49
|
# File 'lib/twat/config.rb', line 47
def accounts
return config[:accounts]
end
|
#config ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/twat/config.rb', line 21
def config
begin
@config ||= YAML.load_file(config_path)
validate!(@config)
rescue Errno::ENOENT
raise NoConfigFile
end
end
|
#config_path ⇒ Object
17
18
19
|
# File 'lib/twat/config.rb', line 17
def config_path
@config_path ||= ENV['TWAT_CONFIG'] || "#{ENV['HOME']}/.twatrc"
end
|
#default_account ⇒ Object
51
52
53
54
|
# File 'lib/twat/config.rb', line 51
def default_account
raise NoDefaultAccount unless config.include?(:default)
return config[:default].to_sym
end
|
#save! ⇒ Object
36
37
38
39
40
41
|
# File 'lib/twat/config.rb', line 36
def save!
File.open(config_path, 'w') do |conf|
conf.chmod(0600)
conf.puts(@config.to_yaml)
end
end
|
#update! ⇒ Object
update! migrates an old config file to the current API it does this by calling a sequence of migration functions in order which rebuild the config in stages, saving and leaving it in a consistent step at each point
71
72
73
|
# File 'lib/twat/config.rb', line 71
def update!
Migrate.new.migrate!(config_path)
end
|
#validate!(conf) ⇒ Object
30
31
32
33
34
|
# File 'lib/twat/config.rb', line 30
def validate!(conf)
raise ConfigVersionIncorrect unless conf.include?(:accounts)
conf
end
|