Class: AOJ::Conf
- Inherits:
-
Object
- Object
- AOJ::Conf
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/aoj/conf.rb
Constant Summary collapse
- RCFILE =
".aojrc"
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #has_credential? ⇒ Boolean
- #has_twitter_credential? ⇒ Boolean
-
#initialize ⇒ Conf
constructor
A new instance of Conf.
- #load_file ⇒ Object
- #rcfile_path ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize ⇒ Conf
13 14 15 |
# File 'lib/aoj/conf.rb', line 13 def initialize @data = load_file end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
11 12 13 |
# File 'lib/aoj/conf.rb', line 11 def data @data end |
Instance Method Details
#has_credential? ⇒ Boolean
33 34 35 |
# File 'lib/aoj/conf.rb', line 33 def has_credential? self['username'] and self['password'] end |
#has_twitter_credential? ⇒ Boolean
37 38 39 40 |
# File 'lib/aoj/conf.rb', line 37 def has_twitter_credential? (twitter = self['twitter']) and twitter['access_token'] and twitter['access_token_secret'] end |
#load_file ⇒ Object
21 22 23 24 25 |
# File 'lib/aoj/conf.rb', line 21 def load_file YAML.load_file rcfile_path rescue Errno::ENOENT {} end |
#rcfile_path ⇒ Object
17 18 19 |
# File 'lib/aoj/conf.rb', line 17 def rcfile_path File.join(Dir.home, RCFILE) end |
#save ⇒ Object
27 28 29 30 31 |
# File 'lib/aoj/conf.rb', line 27 def save open(rcfile_path, "w", 0600) do |file| file.write @data.to_yaml end end |