Class: DataHandler::BaseHandler
- Inherits:
-
Object
- Object
- DataHandler::BaseHandler
- 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
Instance Attribute Summary collapse
-
#filename ⇒ String
readonly
private
The file name.
Instance Method Summary collapse
-
#add_person(person) ⇒ Object
abstract
method to add a person to the transient storage.
-
#add_task_to_person(person_id, task) ⇒ Object
abstract
method to add a task for a person to the transient storage.
-
#find_person_by_id(id) ⇒ Object
abstract
method to search for a person by its id.
-
#find_task_to_id(id) ⇒ Object
abstract
method to search for a person by its id.
-
#get_persons ⇒ Object
abstract
method to return all stored persons.
-
#get_tasks ⇒ Object
abstract
method to return all stored tasks.
-
#get_tasks_to_person(id) ⇒ Object
abstract
method to search for all tasks associated.
-
#initialize(filename) ⇒ BaseHandler
constructor
initialization.
-
#initialize_id_generators ⇒ Object
private
abstract
method to initialize the required id generators.
-
#persist_data ⇒ Object
abstract
method to save the content of the repository to the path specified by the filename and based on the used adapter.
-
#prepare_data ⇒ Object
private
abstract
method to prepare the child class for work and load or initialize relevant data or objects.
Constructor Details
#initialize(filename) ⇒ BaseHandler
initialization
12 13 14 15 |
# File 'lib/handler/base_handler.rb', line 12 def initialize(filename) @filename = filename prepare_data end |
Instance Attribute Details
#filename ⇒ String (readonly, private)
Returns 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
subclasses need to implement this method
method to add a person to the transient storage
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
subclasses need to implement this method
method to add a task for a person to the transient storage
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
subclasses need to implement this method
method to search for a person by its id
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
subclasses need to implement this method
method to search for a person by its id
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_persons ⇒ Object
subclasses need to implement this method
method to return all stored persons
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_tasks ⇒ Object
subclasses need to implement this method
method to return all stored tasks
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
subclasses need to implement this method
method to search for all tasks associated
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_generators ⇒ Object (private)
subclasses need to implement this method
method to initialize the required id generators
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_data ⇒ Object
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
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_data ⇒ Object (private)
subclasses need to implement this method
method to prepare the child class for work and load or initialize relevant data or objects
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 |