Class: Timelog::Configuration
- Inherits:
-
Object
- Object
- Timelog::Configuration
- Defined in:
- lib/timelog/configuration.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
Returns the value of attribute callbacks.
-
#database ⇒ Object
Returns the value of attribute database.
Class Method Summary collapse
Instance Method Summary collapse
- #after(event, &block) ⇒ Object
- #before(event, &block) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #set(name, value) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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
#callbacks ⇒ Object
Returns the value of attribute callbacks.
3 4 5 |
# File 'lib/timelog/configuration.rb', line 3 def callbacks @callbacks end |
#database ⇒ Object
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 |