20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/polytag/tag_group.rb', line 20
def search_by_hash(hash = {})
return self if hash.empty?
conditions = {}
if hash[:owner]
conditions.merge!(owner_type: "#{hash[:owner].class}")
conditions.merge!(owner_id: hash[:owner].id)
else
if hash[:owner_type]
conditions.merge!(owner_type: "#{hash[:owner_type]}")
conditions.merge!(owner_id: hash[:owner_id]) if hash[:owner_id]
end
end
conditions.merge!(name: "#{hash[:name]}") if hash[:name]
conditions.merge!(id: hash[:id]) if hash[:id]
where(conditions)
end
|