Skip to content

Commit

Permalink
Improve naming
Browse files Browse the repository at this point in the history
  • Loading branch information
shioyama committed May 4, 2018
1 parent 8cc9af1 commit c73d0f1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/mobility/plugins/active_record/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@ def build(scope, opts, locale, invert: false)
keys = opts.keys.map &:to_s
predicates = []

maps = scope.mobility.modules.map { |attrs|
next unless attrs.options[:query]
next if (i18n_keys = attrs.names & keys).empty?
mods_map = scope.mobility.modules.map { |mod|
next unless mod.options[:query]
next if (mod_keys = mod.names & keys).empty?

attrs_opts = opts.slice(*i18n_keys)
mod_opts = opts.slice(*mod_keys)

predicates += i18n_keys.map do |key|
build_predicate(attrs, key, locale, opts.delete(key), invert)
predicates += mod_keys.map do |key|
build_predicate(mod, key, locale, opts.delete(key), invert)
end

[attrs, attrs_opts]
[mod, mod_opts]
}.compact

return yield if maps.empty?
return yield if mods_map.empty?

base = opts.empty? ? scope : yield(opts)

maps.inject(base) { |rel, (attrs, attr_opts)|
attrs.backend_class.add_scope(rel, attr_opts, locale, invert, attrs.options)
mods_map.inject(base) { |rel, (mod, mod_opts)|
mod.backend_class.add_scope(rel, mod_opts, locale, invert, mod.options)
}.where(predicates.inject(&:and))
end

Expand Down

0 comments on commit c73d0f1

Please sign in to comment.