module DodgyStalker::DataStore::Common
Public Instance Methods
add(attributes)
click to toggle source
# File lib/dodgy_stalker/data_store/common.rb, line 8 def add(attributes) model.where(attributes).first_or_create end
on_list(attributes)
click to toggle source
# File lib/dodgy_stalker/data_store/common.rb, line 4 def on_list(attributes) model.where(attributes_conditions(attributes)) end
remove(attr)
click to toggle source
# File lib/dodgy_stalker/data_store/common.rb, line 12 def remove(attr) conditions = attributes.with_indifferent_access.except(:id, :created_at, :updated_at).merge(attr) model.where(conditions).delete_all end
Private Instance Methods
arel_table()
click to toggle source
# File lib/dodgy_stalker/data_store/common.rb, line 26 def arel_table model.arel_table end
attributes_conditions(attributes)
click to toggle source
Build OR query from non-empty attributes
# File lib/dodgy_stalker/data_store/common.rb, line 20 def attributes_conditions(attributes) attributes.reject {|k,v| v.nil?}. map {|attribute, value| arel_table[attribute].eq(value) }. inject(:or) end
model()
click to toggle source
# File lib/dodgy_stalker/data_store/common.rb, line 30 def model self.class end