Class: Qcourses::CourseRepository
- Inherits:
-
Object
- Object
- Qcourses::CourseRepository
- 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
- .configure(instance = CourseRepository.new) ⇒ Object
- .destroy ⇒ Object
- .in_memory ⇒ Object
- .method_missing(method, *args) ⇒ Object
- .on_file_system(root_dir = nil) ⇒ Object
Instance Method Summary collapse
- #all ⇒ Object
- #find(course_id) ⇒ Object
-
#initialize(root_dir = nil, directory = Dir, file_opener = File) ⇒ CourseRepository
constructor
A new instance of CourseRepository.
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 |
.destroy ⇒ Object
27 28 29 |
# File 'lib/qcourses/models/course_repository.rb', line 27 def self.destroy @@instance = nil end |
.in_memory ⇒ Object
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
#all ⇒ Object
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 |