Class: Timelog::Configuration

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



5
6
7
8
9
# File 'lib/timelog/configuration.rb', line 5

def initialize
  # defaults
  @database = "#{Dir.home}/.timelog.db"
  @callbacks = {before: {}, after: {}}
end

Instance Attribute Details

#callbacksObject

Returns the value of attribute callbacks.



3
4
5
# File 'lib/timelog/configuration.rb', line 3

def callbacks
  @callbacks
end

#databaseObject

Returns the value of attribute database.



3
4
5
# File 'lib/timelog/configuration.rb', line 3

def database
  @database
end

Class Method Details

.open(file = nil, &block) ⇒ Object



28
29
30
31
32
33
# File 'lib/timelog/configuration.rb', line 28

def open(file = nil, &block)
  instance = self.new
  instance.instance_eval(File.read(file), file) if file and File.exists?(file)
  instance.instance_eval(&block) if block_given?
  instance
end

Instance Method Details

#after(event, &block) ⇒ Object



21
22
23
24
25
# File 'lib/timelog/configuration.rb', line 21

def after(event, &block)
  @callbacks[:after][event.to_sym] ||= []
  @callbacks[:after][event.to_sym] << block if block_given?
  @callbacks[:after][event.to_sym]
end

#before(event, &block) ⇒ Object



15
16
17
18
19
# File 'lib/timelog/configuration.rb', line 15

def before(event, &block)
  @callbacks[:before][event.to_sym] ||= []
  @callbacks[:before][event.to_sym] << block if block_given?
  @callbacks[:before][event.to_sym]
end

#set(name, value) ⇒ Object



11
12
13
# File 'lib/timelog/configuration.rb', line 11

def set(name, value)
  send("#{name}=", value)
end