Class: Pomo::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/pomo/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Initialize configuration.



31
32
33
34
35
# File 'lib/pomo/configuration.rb', line 31

def initialize(options = {})
  @notifier = options[:notifier]
  @progress = options[:progress]
  @tmux     = options[:tmux]
end

Instance Attribute Details

#notifierObject (readonly)

Notification library.

values: notification_center | libnotify | growl | quicksilver



12
13
14
# File 'lib/pomo/configuration.rb', line 12

def notifier
  @notifier
end

#progressObject

Run with progress bar.

values: true | false



19
20
21
# File 'lib/pomo/configuration.rb', line 19

def progress
  @progress
end

#tmuxObject

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_fileObject

Helpers



71
72
73
# File 'lib/pomo/configuration.rb', line 71

def self.config_file
  File.join(ENV['HOME'],'.pomorc')
end

.default_notifierObject



83
84
85
86
87
88
89
90
91
# File 'lib/pomo/configuration.rb', line 83

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_optionsObject



75
76
77
78
79
80
81
# File 'lib/pomo/configuration.rb', line 75

def self.default_options
  {
    :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(options = {})
  options.reject!{|k,v| ![:notifier, :progress, :tmux].include? k}

  if !(File.exists? config_file)
    File.open(config_file, 'w') { |file| YAML::dump(default_options, file) }
    say "Initialized default config file in #{config_file}. See 'pomo help initconfig' for options."
  end

  config_file_options = YAML.load_file(config_file)
  new(config_file_options.merge(options))
end

.save(options = {}) ⇒ Object

Save configuration. Passed options take precendence over default_options.



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/pomo/configuration.rb', line 55

def self.save(options = {})
  force_save = options.delete :force
  options.reject!{|k,v| ![:notifier, :progress, :tmux].include? k}

  options = default_options.merge(options)

  if !(File.exists? config_file) || force_save
    File.open(config_file, 'w') { |file| YAML::dump(options, 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