Class: FileSourceAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/repositories/adapters/file_source_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(data_transformer, file_path) ⇒ FileSourceAdapter

Returns a new instance of FileSourceAdapter.



4
5
6
7
8
# File 'lib/repositories/adapters/file_source_adapter.rb', line 4

def initialize(data_transformer, file_path)
  @file_path = file_path
  @file_source = FileDataSource.new(data_transformer)
  @file_source.load_from_file(file_path)
end

Instance Method Details

#add_student(student) ⇒ Object



18
19
20
21
22
# File 'lib/repositories/adapters/file_source_adapter.rb', line 18

def add_student(student)
  added_id = @file_source.add_student(student)
  @file_source.save_to_file(@file_path)
  added_id
end

#paginated_short_students(page, count, existing_data_list = nil) ⇒ Object



14
15
16
# File 'lib/repositories/adapters/file_source_adapter.rb', line 14

def paginated_short_students(page, count, existing_data_list = nil)
  @file_source.paginated_short_students(page, count, existing_data_list)
end

#remove_student(student_id) ⇒ Object



29
30
31
32
# File 'lib/repositories/adapters/file_source_adapter.rb', line 29

def remove_student(student_id)
  @file_source.remove_student(student_id)
  @file_source.save_to_file(@file_path)
end

#replace_student(student_id, student) ⇒ Object



24
25
26
27
# File 'lib/repositories/adapters/file_source_adapter.rb', line 24

def replace_student(student_id, student)
  @file_source.replace_student(student_id, student)
  @file_source.save_to_file(@file_path)
end

#student_by_id(student_id) ⇒ Object



10
11
12
# File 'lib/repositories/adapters/file_source_adapter.rb', line 10

def student_by_id(student_id)
  @file_source.student_by_id(student_id)
end

#student_countObject



34
35
36
# File 'lib/repositories/adapters/file_source_adapter.rb', line 34

def student_count
  @file_source.student_count
end