Class: DataHandler::BaseHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/handler/base_handler.rb

Overview

This class serves as a abstract parent class to take care about the initialization of the repositories and the id generator. This class also provides abstract methods to save and load data from and to a repository which are implemented by child classes.

Direct Known Subclasses

FileHandler, SqliteHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ BaseHandler

initialization

Parameters:

  • filename (String)

    the filename from where the data should be loaded or to where the data should be saved



12
13
14
15
# File 'lib/handler/base_handler.rb', line 12

def initialize(filename)
  @filename = filename
  prepare_data
end

Instance Attribute Details

#filenameString (readonly, private)

Returns the file name.

Returns:

  • (String)

    the file name



93
94
95
# File 'lib/handler/base_handler.rb', line 93

def filename
  @filename
end

Instance Method Details

#add_person(person) ⇒ Object

This method is abstract.

subclasses need to implement this method

method to add a person to the transient storage

Raises:

  • (NotImplementedError)

    if the subclass does not have this method



75
76
77
78
79
# File 'lib/handler/base_handler.rb', line 75

def add_person(person)
  fail NotImplementedError, " Error: the subclass
    #{self.name.split('::').last} needs to implement the method:
    add_person from its base class".red
end

#add_task_to_person(person_id, task) ⇒ Object

This method is abstract.

subclasses need to implement this method

method to add a task for a person to the transient storage

Raises:

  • (NotImplementedError)

    if the subclass does not have this method



84
85
86
87
88
# File 'lib/handler/base_handler.rb', line 84

def add_task_to_person(person_id, task)
  fail NotImplementedError, " Error: the subclass
    #{self.name.split('::').last} needs to implement the method:
    add_task_to_person from its base class".red
end

#find_person_by_id(id) ⇒ Object

This method is abstract.

subclasses need to implement this method

method to search for a person by its id

Raises:

  • (NotImplementedError)

    if the subclass does not have this method



48
49
50
51
52
# File 'lib/handler/base_handler.rb', line 48

def find_person_by_id(id)
  fail NotImplementedError, " Error: the subclass
    #{self.name.split('::').last} needs to implement the method:
    find_person_by_id from its base class".red
end

#find_task_to_id(id) ⇒ Object

This method is abstract.

subclasses need to implement this method

method to search for a person by its id

Raises:

  • (NotImplementedError)

    if the subclass does not have this method



57
58
59
60
61
# File 'lib/handler/base_handler.rb', line 57

def find_task_to_id(id)
  fail NotImplementedError, " Error: the subclass
    #{self.name.split('::').last} needs to implement the method:
    find_task_to_id from its base class".red
end

#get_personsObject

This method is abstract.

subclasses need to implement this method

method to return all stored persons

Raises:

  • (NotImplementedError)

    if the subclass does not have this method



30
31
32
33
34
# File 'lib/handler/base_handler.rb', line 30

def get_persons
  fail NotImplementedError, " Error: the subclass
    #{self.name.split('::').last} needs to implement the method:
    get_persons from its base class".red
end

#get_tasksObject

This method is abstract.

subclasses need to implement this method

method to return all stored tasks

Raises:

  • (NotImplementedError)

    if the subclass does not have this method



39
40
41
42
43
# File 'lib/handler/base_handler.rb', line 39

def get_tasks
  fail NotImplementedError, " Error: the subclass
    #{self.name.split('::').last} needs to implement the method:
    get_tasks from its base class".red
end

#get_tasks_to_person(id) ⇒ Object

This method is abstract.

subclasses need to implement this method

method to search for all tasks associated

Raises:

  • (NotImplementedError)

    if the subclass does not have this method



66
67
68
69
70
# File 'lib/handler/base_handler.rb', line 66

def get_tasks_to_person(id)
  fail NotImplementedError, " Error: the subclass
    #{self.name.split('::').last} needs to implement the method:
    get_tasks_to_person from its base class".red
end

#initialize_id_generatorsObject (private)

This method is abstract.

subclasses need to implement this method

method to initialize the required id generators

Raises:

  • (NotImplementedError)

    if the subclass does not have this method



108
109
110
111
112
# File 'lib/handler/base_handler.rb', line 108

def initialize_id_generators
  fail NotImplementedError, " Error: the subclass
    #{self.name.split('::').last} needs to implement the method:
    initialize_id_generators from its base class".red
end

#persist_dataObject

This method is abstract.

subclasses need to implement this method

method to save the content of the repository to the path specified by the filename and based on the used adapter

Raises:

  • (NotImplementedError)

    if the subclass does not have this method



21
22
23
24
25
# File 'lib/handler/base_handler.rb', line 21

def persist_data
  fail NotImplementedError, " Error: the subclass
    #{self.name.split('::').last} needs to implement the method:
    save_repository from its base class".red
end

#prepare_dataObject (private)

This method is abstract.

subclasses need to implement this method

method to prepare the child class for work and load or initialize relevant data or objects

Raises:

  • (NotImplementedError)

    if the subclass does not have this method



99
100
101
102
103
# File 'lib/handler/base_handler.rb', line 99

def prepare_data
  fail NotImplementedError, " Error: the subclass
    #{self.name.split('::').last} needs to implement the method:
    load_repository from its base class".red
end