Sha256: 905ad75a44aa322fe592ee2a3ffd04677e9ecc17ba267312582a3514dd9609f3

Contents?: true

Size: 703 Bytes

Versions: 1

Compression:

Stored size: 703 Bytes

Contents

module TaxonomyTermsHelper

  def search_term(params)
    taxonomy_terms = []
    # loop thru each parameter that matches one of the method signatures
    taxonomy_terms = params.keys.select do |pk|
      TaxonomyTerm.respond_to?("#{pk}_is".to_sym) or DigitalAsset.respond_to?("#{pk}_in".to_sym)
    end.reduce(TaxonomyTerm) do |sum, key|
      # for each key, call the 'named query' method with the value given and chain...
      method = TaxonomyTerm.respond_to?("#{key}_in".to_sym) ? "#{key}_in".to_sym : "#{key}_is".to_sym
      sum.send(method, method.to_s.end_with?('in') ? params[key].to_a : params[key]) # should return result of the send call for chaining
    end
    taxonomy_terms
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
daengine-0.2.8 app/helpers/taxonomy_terms_helper.rb