Skip to content

Commit

Permalink
Added remove from list.
Browse files Browse the repository at this point in the history
  • Loading branch information
treeder committed Dec 27, 2012
1 parent af2d37d commit c6d16e6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/ocm/iron_cache_orm.rb
Expand Up @@ -57,9 +57,9 @@ def get_list(key)
def update_in_list(key, item, comps)
messages = get_list(key)
Ocm.logger.debug "update_in_list: messages: #{messages.inspect}"
messages.each_with_index do |m,i|
messages.each_with_index do |m, i|
match = true
comps.each_pair do |k,v|
comps.each_pair do |k, v|
if m.is_a?(Hash)
if m[k.to_s] != v
match = false
Expand All @@ -73,7 +73,11 @@ def update_in_list(key, item, comps)
end
end
if match
messages[i] = item
if item
messages[i] = item
else
messages.delete_at(i)
end
put(key, messages)
return
end
Expand All @@ -95,6 +99,12 @@ def append_to_list(key, item)
put(key, messages)
end

# Warning, this is not a safe operation, be sure it is only being called once at a time
def remove_from_list(key, comps)
#id = item.is_a?(String) ? item : item.id
update_in_list(key, nil, comps)
end

def find(clazz, id)
get(key_for(clazz, id))
end
Expand Down

0 comments on commit c6d16e6

Please sign in to comment.