Class: Qcourses::CourseRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/qcourses/models/course_repository.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

KEY_VALUE_SEPARATOR =
":"
@@instance =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_dir = nil, directory = Dir, file_opener = File) ⇒ CourseRepository

Returns a new instance of CourseRepository.



46
47
48
49
50
# File 'lib/qcourses/models/course_repository.rb', line 46

def initialize(root_dir = nil, directory = Dir, file_opener = File)
  @directory = directory
  @file_opener = file_opener
  @root_dir = root_dir
end

Class Method Details

.configure(instance = CourseRepository.new) ⇒ Object



23
24
25
# File 'lib/qcourses/models/course_repository.rb', line 23

def self.configure(instance = CourseRepository.new)
  @@instance = instance
end

.destroyObject



27
28
29
# File 'lib/qcourses/models/course_repository.rb', line 27

def self.destroy
  @@instance = nil
end

.in_memoryObject



31
32
33
# File 'lib/qcourses/models/course_repository.rb', line 31

def self.in_memory
  configure MemoryCourseRepository.new
end

.method_missing(method, *args) ⇒ Object



39
40
41
42
# File 'lib/qcourses/models/course_repository.rb', line 39

def self.method_missing(method, *args)
  raise Error.new "CourseRepository not configured while calling #{method}" unless @@instance
  @@instance.send(method, *args)
end

.on_file_system(root_dir = nil) ⇒ Object



35
36
37
# File 'lib/qcourses/models/course_repository.rb', line 35

def self.on_file_system(root_dir = nil)
  configure CourseRepository.new(root_dir)
end

Instance Method Details

#allObject



52
53
54
# File 'lib/qcourses/models/course_repository.rb', line 52

def all
  courses.values
end

#find(course_id) ⇒ Object



56
57
58
# File 'lib/qcourses/models/course_repository.rb', line 56

def find(course_id)
  courses[course_id]
end