Class: Pomo::Configuration
- Inherits:
-
Object
- Object
- Pomo::Configuration
- Defined in:
- lib/pomo/configuration.rb
Instance Attribute Summary collapse
-
#notifier ⇒ Object
readonly
Notification library.
-
#progress ⇒ Object
Run with progress bar.
-
#tmux ⇒ Object
Refresh tmux status bar.
Class Method Summary collapse
-
.config_file ⇒ Object
Helpers.
- .default_notifier ⇒ Object
- .default_options ⇒ Object
-
.load(options = {}) ⇒ Object
Load configuration file or default_options.
-
.save(options = {}) ⇒ Object
Save configuration.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Configuration
constructor
Initialize configuration.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Initialize configuration.
31 32 33 34 35 |
# File 'lib/pomo/configuration.rb', line 31 def initialize( = {}) @notifier = [:notifier] @progress = [:progress] @tmux = [:tmux] end |
Instance Attribute Details
#notifier ⇒ Object (readonly)
Notification library.
values: notification_center | libnotify | growl | quicksilver
12 13 14 |
# File 'lib/pomo/configuration.rb', line 12 def notifier @notifier end |
#progress ⇒ Object
Run with progress bar.
values: true | false
19 20 21 |
# File 'lib/pomo/configuration.rb', line 19 def progress @progress end |
#tmux ⇒ Object
Refresh tmux status bar.
values: true | false
26 27 28 |
# File 'lib/pomo/configuration.rb', line 26 def tmux @tmux end |
Class Method Details
.config_file ⇒ Object
Helpers
69 70 71 |
# File 'lib/pomo/configuration.rb', line 69 def self.config_file File.join(ENV['HOME'],'.pomorc') end |
.default_notifier ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/pomo/configuration.rb', line 81 def self.default_notifier if Pomo::OS.has_notification_center? return 'notification_center' elsif Pomo::OS.linux? return 'libnotify' else return 'growl' end end |
.default_options ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/pomo/configuration.rb', line 73 def self. { :notifier => default_notifier, :progress => false, :tmux => false } end |
.load(options = {}) ⇒ Object
Load configuration file or default_options. Passed options take precedence.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pomo/configuration.rb', line 40 def self.load( = {}) = .reject{|k,v| ![:notifier, :progress, :tmux].include? k} if !(File.exists? config_file) File.open(config_file, 'w') { |file| YAML::dump(, file) } say "Initialized default config file in #{config_file}. See 'pomo help initconfig' for options." end = YAML.load_file(config_file) new(.merge()) end |
.save(options = {}) ⇒ Object
Save configuration. Passed options take precendence over default_options.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pomo/configuration.rb', line 55 def self.save( = {}) = .reject{|k,v| ![:notifier, :progress, :tmux].include? k} force_save = .delete :force if !(File.exists? config_file) || force_save File.open(config_file, 'w') { |file| YAML::dump(.merge(), file) } say "Initialized config file in #{config_file}" else say_error "Not overwriting existing config file #{config_file}, use --force to override. See 'pomo help initconfig'." end end |