Class: AOJ::Conf

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/aoj/conf.rb

Constant Summary collapse

RCFILE =
".aojrc"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConf



13
14
15
# File 'lib/aoj/conf.rb', line 13

def initialize
  @data = load_file
end

Instance Attribute Details

#dataObject

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_fileObject



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_pathObject



17
18
19
# File 'lib/aoj/conf.rb', line 17

def rcfile_path
  File.join(Dir.home, RCFILE)
end

#saveObject



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