Module: Renshuu::Listable

Included in:
Grammar, Kanji, Word
Defined in:
lib/renshuu/models/mixins/listable.rb

Overview

Mixin for items that can be added to study Lists.

Interface

This mixin rely on the following interface:

  • #id: Identifier of the listable item;

  • .base_route: Path part used in URL construction.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



14
15
16
17
18
# File 'lib/renshuu/models/mixins/listable.rb', line 14

def self.included(base) # :nodoc:
  super

  base.extend(ClassMethods)
end

Instance Method Details

#add_to_list(list) ⇒ Void

Adds the item to the given list.

Parameters:

  • list (List, String)

Returns:

  • (Void)


26
27
28
29
30
31
32
33
34
35
# File 'lib/renshuu/models/mixins/listable.rb', line 26

def add_to_list(list)
  list_id = case list
  when List then list.id
  else list
  end

  Renshuu.client.query(
    :put, "v1/#{self.class.base_route}/#{id}", params: { list_id: }
  )
end

#remove_from_list(list) ⇒ Void

Removes the item from the given list.

Parameters:

  • list (List, String)

Returns:

  • (Void)


43
44
45
46
47
48
49
50
51
52
# File 'lib/renshuu/models/mixins/listable.rb', line 43

def remove_from_list(list)
  list_id = case list
  when List then list.id
  else list
  end

  Renshuu.client.query(
    :delete, "v1/#{self.class.base_route}/#{id}", params: { list_id: }
  )
end