Class: Mygithub::Settings
- Inherits:
-
Object
- Object
- Mygithub::Settings
- Defined in:
- lib/mygithub/settings.rb
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(filename = Settings.default_filename) ⇒ Settings
constructor
A new instance of Settings.
- #save ⇒ Object
- #token ⇒ Object
- #token=(token) ⇒ Object
- #username ⇒ Object
- #username=(username) ⇒ Object
Constructor Details
#initialize(filename = Settings.default_filename) ⇒ Settings
Returns a new instance of Settings.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mygithub/settings.rb', line 25 def initialize(filename = Settings.default_filename) @filename = filename if File.exist?(@filename) open(@filename) do |f| @data = YAML.load(f.read) end else @data = { 'username' => '', 'token' => '' } @is_empty = true end end |
Class Method Details
.default_database ⇒ Object
21 22 23 |
# File 'lib/mygithub/settings.rb', line 21 def self.default_database File.join default_dir, 'database' end |
.default_dir ⇒ Object
13 14 15 |
# File 'lib/mygithub/settings.rb', line 13 def self.default_dir File.('~/.mygithub') end |
.default_filename ⇒ Object
17 18 19 |
# File 'lib/mygithub/settings.rb', line 17 def self.default_filename File.join default_dir, 'mygithub.yaml' end |
Instance Method Details
#empty? ⇒ Boolean
65 66 67 |
# File 'lib/mygithub/settings.rb', line 65 def empty? !@is_empty.nil? end |
#save ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/mygithub/settings.rb', line 41 def save FileUtils.mkdir_p File.dirname(@filename) open(@filename, "w") do |f| f.write YAML.dump(@data) end end |
#token ⇒ Object
57 58 59 |
# File 'lib/mygithub/settings.rb', line 57 def token @data['token'] end |
#token=(token) ⇒ Object
61 62 63 |
# File 'lib/mygithub/settings.rb', line 61 def token=(token) @data['token'] = token end |
#username ⇒ Object
49 50 51 |
# File 'lib/mygithub/settings.rb', line 49 def username @data['username'] end |
#username=(username) ⇒ Object
53 54 55 |
# File 'lib/mygithub/settings.rb', line 53 def username=(username) @data['username'] = username end |