Module: Renshuu::Schedulable
Overview
Mixin for items that can be added to study Schedules.
Interface
This mixin rely on the following interface:
-
#id: Identifier of the schedulable item; -
.base_route: Path part used in URL construction.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#add_to_schedule(schedule) ⇒ Void
Adds the item to the given schedule.
-
#remove_from_schedule(schedule) ⇒ Void
Removes the item from the given schedule.
Class Method Details
.included(base) ⇒ Object
14 15 16 17 18 |
# File 'lib/renshuu/models/mixins/schedulable.rb', line 14 def self.included(base) super base.extend(ClassMethods) end |
Instance Method Details
#add_to_schedule(schedule) ⇒ Void
Adds the item to the given schedule.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/renshuu/models/mixins/schedulable.rb', line 26 def add_to_schedule(schedule) sched_id = case schedule when Schedule then schedule.id else schedule end Renshuu.client.query( :put, "v1/#{self.class.base_route}/#{id}", params: { sched_id: } ) end |
#remove_from_schedule(schedule) ⇒ Void
Removes the item from the given schedule.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/renshuu/models/mixins/schedulable.rb', line 43 def remove_from_schedule(schedule) sched_id = case schedule when Schedule then schedule.id else schedule end Renshuu.client.query( :delete, "v1/#{self.class.base_route}/#{id}", params: { sched_id: } ) end |