Class: Timelog::Book
- Inherits:
-
Object
- Object
- Timelog::Book
- Defined in:
- lib/timelog/book.rb,
lib/timelog/book/clients.rb,
lib/timelog/book/entries.rb,
lib/timelog/book/projects.rb
Defined Under Namespace
Classes: Clients, Entries, Projects
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
Class Method Summary collapse
-
.open(file, &block) ⇒ Object
open an existing book.
Instance Method Summary collapse
- #clients(&block) ⇒ Object
-
#entries(&block) ⇒ Object
get the entries controller.
-
#execute(arguments) ⇒ Object
execute a command.
-
#initialize(configuration) ⇒ Book
constructor
initialize a book.
- #projects(&block) ⇒ Object
-
#trigger(group, event, *args) ⇒ Object
trigger an event.
Constructor Details
#initialize(configuration) ⇒ Book
initialize a book
using a configuration object. have a look at the .open method for initializing a book from a configuration file
14 15 16 17 18 19 20 |
# File 'lib/timelog/book.rb', line 14 def initialize(configuration) @configuration = configuration @database = Database.new(@configuration) @entries = Entries.new(self) @clients = Clients.new(self) @projects = Projects.new(self) end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
7 8 9 |
# File 'lib/timelog/book.rb', line 7 def configuration @configuration end |
#database ⇒ Object (readonly)
Returns the value of attribute database.
7 8 9 |
# File 'lib/timelog/book.rb', line 7 def database @database end |
Class Method Details
.open(file, &block) ⇒ Object
open an existing book
using a configuration file and an optional block which will be evaluated in the book instance
84 85 86 87 88 |
# File 'lib/timelog/book.rb', line 84 def open(file, &block) book = Book.new(Configuration.open(file)) book.instance_eval(&block) if block_given? book end |
Instance Method Details
#clients(&block) ⇒ Object
68 69 70 71 |
# File 'lib/timelog/book.rb', line 68 def clients(&block) @clients.instance_eval(&block) if block_given? @clients end |
#entries(&block) ⇒ Object
get the entries controller
use this for manipulate entries in the book if a block is given, it will be evalulated in the controllers context
63 64 65 66 |
# File 'lib/timelog/book.rb', line 63 def entries(&block) @entries.instance_eval(&block) if block_given? @entries end |
#execute(arguments) ⇒ Object
execute a command
this finds and executes a command given from a string or an array of arguments
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/timelog/book.rb', line 26 def execute(arguments) arguments = arguments.split if arguments.is_a? String # we have arguments, so try to find the command if arguments.size > 0 name = "" # add one argument at a time, until (or never) a command matches command = while(argument = arguments.shift) name += " #{argument}" if obj = Command.get(name.strip, self, arguments) break obj end end # no arguments, use generic command else command = Command.new(self) end raise InvalidCommandError unless command # looking for command help? no? then execute! arguments.first.try(:downcase) == "help" ? command.help : command.execute end |
#projects(&block) ⇒ Object
73 74 75 76 |
# File 'lib/timelog/book.rb', line 73 def projects(&block) @projects.instance_eval(&block) if block_given? @projects end |
#trigger(group, event, *args) ⇒ Object
trigger an event
49 50 51 52 53 54 55 56 |
# File 'lib/timelog/book.rb', line 49 def trigger(group, event, *args) case group when :before @configuration.callbacks[group][event].each {|block| instance_exec(*args, &block)} if @configuration.callbacks[group][event] when :after @configuration.callbacks[group][event].each {|block| instance_exec(*args, &block)} if @configuration.callbacks[group][event] end end |