Module: Liszt::InstanceMethods

Defined in:
lib/liszt.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



155
156
157
158
159
160
161
# File 'lib/liszt.rb', line 155

def self.included(base)
  base.class_eval do
    after_create :add_to_list
    after_update :update_list
    after_destroy :remove_from_list
  end
end

Instance Method Details

#add_to_listObject



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/liszt.rb', line 163

def add_to_list
  if ordered_list_initialized?
    if meets_list_conditions?
      if self.class.liszt_append_new_items
        ordered_list.push id
      else
        ordered_list.unshift id
      end
    end
  else
    if self.class.liszt_sort_by
      initialize_list! &self.class.liszt_sort_by
    else
      initialize_list!
    end
  end
  true
end

#move_down!Object



204
205
206
# File 'lib/liszt.rb', line 204

def move_down!
  ordered_list.move_down id
end

#move_to_bottom!Object



208
209
210
# File 'lib/liszt.rb', line 208

def move_to_bottom!
  ordered_list.move_to_bottom id
end

#move_to_top!Object



196
197
198
# File 'lib/liszt.rb', line 196

def move_to_top!
  ordered_list.move_to_top id
end

#move_up!Object



200
201
202
# File 'lib/liszt.rb', line 200

def move_up!
  ordered_list.move_up id
end

#remove_from_listObject



191
192
193
194
# File 'lib/liszt.rb', line 191

def remove_from_list
  ordered_list.remove id
  true
end

#update_listObject



182
183
184
185
186
187
188
189
# File 'lib/liszt.rb', line 182

def update_list
  if meets_list_conditions?
    add_to_list
  else
    remove_from_list
  end
  true
end