Sha256: 94a1bbd1ac787d73b253f22164c2a3a84393ff6a76b3a9054fbc95c1d4ffbfbb

Contents?: true

Size: 701 Bytes

Versions: 13

Compression:

Stored size: 701 Bytes

Contents

module DigitalAssetsHelper

  def search_da(params)
    digital_assets = []
    # loop thru each parameter that matches one of the method signatures
    digital_assets = params.keys.select do |pk|
      DigitalAsset.respond_to?("#{pk}_is".to_sym) or DigitalAsset.respond_to?("#{pk}_in".to_sym)
    end.reduce(DigitalAsset) do |sum, key|
      # for each key, call the 'named query' method with the value given and chain...
      method = DigitalAsset.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
    digital_assets
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
daengine-0.2.15 app/helpers/digital_assets_helper.rb
daengine-0.2.14 app/helpers/digital_assets_helper.rb
daengine-0.2.13 app/helpers/digital_assets_helper.rb
daengine-0.2.12 app/helpers/digital_assets_helper.rb
daengine-0.2.11 app/helpers/digital_assets_helper.rb
daengine-0.2.10 app/helpers/digital_assets_helper.rb
daengine-0.2.9 app/helpers/digital_assets_helper.rb
daengine-0.2.8 app/helpers/digital_assets_helper.rb
daengine-0.2.7 app/helpers/digital_assets_helper.rb
daengine-0.2.5 app/helpers/digital_assets_helper.rb
daengine-0.2.4 app/helpers/digital_assets_helper.rb
daengine-0.2.3 app/helpers/digital_assets_helper.rb
daengine-0.2.2 app/helpers/digital_assets_helper.rb