5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-06-02 07:04:17 +00:00

los artículos filtrados también tienen un sitio

This commit is contained in:
f 2020-11-27 20:54:29 -03:00
parent 227e48681e
commit 1fb53168e2

View file

@ -92,27 +92,30 @@ class PostRelation < Array
def where(**args)
return self if args.empty?
PostRelation[*select do |post|
result = args.map do |attr, value|
next unless post.attribute?(attr)
@where ||= {}
@where[args.hash.to_s] ||= begin
PostRelation.new(site: site).concat(select do |post|
result = args.map do |attr, value|
next unless post.attribute?(attr)
attribute = post.public_send(attr)
attribute = post[attr]
# TODO: Si el valor del atributo también es un Array deberíamos
# cruzar ambas.
case value
when Array then value.include? attribute.value
else
case attribute.value
when Array then attribute.value.include? value
else attribute.value == value
# TODO: Si el valor del atributo también es un Array deberíamos
# cruzar ambas.
case value
when Array then value.include? attribute.value
else
case attribute.value
when Array then attribute.value.include? value
else attribute.value == value
end
end
end
end.compact
end.compact
# Un Array vacío devuelve true para all?
!result.empty? && result.all?
end]
# Un Array vacío devuelve true para all?
result.present? && result.all?
end)
end
end
# Como Array#select devolviendo una relación
@ -120,7 +123,7 @@ class PostRelation < Array
# @return [PostRelation]
alias array_select select
def select(&block)
PostRelation[*array_select(&block)]
PostRelation.new(site: site).concat array_select(&block)
end
# Intenta guardar todos y devuelve true si pudo