Class: Lessonly::Course
- Inherits:
-
Resource
- Object
- Sawyer::Resource
- Resource
- Lessonly::Course
show all
- Defined in:
- lib/lessonly/resource/course.rb
Instance Method Summary
collapse
Methods inherited from Resource
all, basename, client, #client, collection_path, create, define_has_many_getter, #destroy, find, find_by_href, has_many, has_one, #href, #reload, #update
Constructor Details
#initialize(agent, data = {}) ⇒ Course
Returns a new instance of Course.
5
6
7
8
9
|
# File 'lib/lessonly/resource/course.rb', line 5
def initialize(agent, data = {})
super(agent, data)
define_has_many_lessons if @attrs[:lessons]
end
|
Instance Method Details
#create_assignment(users, due_by = 1.year.from_now) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/lessonly/resource/course.rb', line 17
def create_assignment(users, due_by = 1.year.from_now)
users = [users] unless users.is_a? Array
new_assignments = users.map do |user|
Lessonly::Assignment.new(agent, assignee_id: user.id, due_by: due_by)
end
self.assignments = assignments + new_assignments
client.put "#{href}/assignments",
Resource.new(agent, assignments: new_assignments)
end
|
#define_has_many_lessons ⇒ Object
11
12
13
14
15
|
# File 'lib/lessonly/resource/course.rb', line 11
def define_has_many_lessons
self.lessons = @attrs[:lessons].map do |l|
Lessonly::Lesson.new(agent, l.attrs)
end
end
|
#destroy_assignment(user) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/lessonly/resource/course.rb', line 30
def destroy_assignment(user)
self.assignments = assignments.select { |a| a.assignee_id != user.id }
client.put "#{href}/assignments",
Resource.new(agent, assignments: assignments)
end
|