class TheFox::Timr::Model::ForeignIdDb

Holds the Task IDs for each Foreign Task ID.

Basically it's a Hash with structure:

foreign_id => task_id

Attributes

foreign_ids[R]

Holds all Foreign Task IDs.

@foreign_ids[foreign_id] = task.id

Public Class Methods

new() click to toggle source
Calls superclass method TheFox::Timr::Model::BasicModel.new
# File lib/timr/model/foreign_id_db.rb, line 24
def initialize
    super()
    
    @foreign_ids = Hash.new
end

Public Instance Methods

add_task(task, foreign_id) click to toggle source
# File lib/timr/model/foreign_id_db.rb, line 30
def add_task(task, foreign_id)
    task_id = task.id
    foreign_id = foreign_id.strip # needs clone
    
    if @foreign_ids[foreign_id]
        if @foreign_ids[foreign_id] == task_id
            # Foreign ID has already a match.
            false
        else
            raise ForeignIdError, "Want to add Foreign ID '#{foreign_id}' for Task '#{task.short_id}', but Foreign ID '#{foreign_id}' is already used by Task '#{@foreign_ids[foreign_id]}'."
        end
    else
        @foreign_ids[foreign_id] = task_id
        
        task.foreign_id = foreign_id
        
        # Mark ForeignIdDb as changed.
        changed
        
        true
    end
end
get_task_id(foreign_id) click to toggle source
# File lib/timr/model/foreign_id_db.rb, line 53
def get_task_id(foreign_id)
    foreign_id = foreign_id.strip # needs clone
    
    @foreign_ids[foreign_id]
end
remove_task(task) click to toggle source
# File lib/timr/model/foreign_id_db.rb, line 59
def remove_task(task)
    @foreign_ids.delete(task.foreign_id)
    
    task.foreign_id = nil
    
    # Mark ForeignIdDb as changed.
    changed
end