Sha256: 9710aff1407a1e63b2c76830a806cb168768c9c5e62486a841538f7bf1150266

Contents?: true

Size: 876 Bytes

Versions: 23

Compression:

Stored size: 876 Bytes

Contents

module CloudSesame
	module Query
		module DSL
			module AppliedFilterQuery

				def included?(field, value = nil)
					applied?(field, value, true)
				end

				def excluded?(field, value = nil)
					applied?(field, value, false)
				end

				def applied?(field, value = nil, included = nil)
					field = field.to_sym
					applied = applied_filters(included)
					if value
						applied[field] && applied[field].include?(value)
					else
						applied[field] && !applied[field].empty?
					end
				end

				def applied_filters(included = nil)
					result = Hash.new { |hash, key| hash[key] = [] }

					(applied_fields = _scope.applied).flatten!
					applied_fields.compact!

					applied_fields.each do |field|
						if included.nil? || field[:included] == included
							result[field[:field]] << field[:value]
						end
					end

					result
				end

			end
		end
	end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
CloudSesame-1.0.1 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-1.0.0 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.9.4 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.9.3 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.9.2 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.9.1 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.9.0 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.8.3 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.8.2 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.8.1 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.8.0 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.7.13 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.7.12 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.7.11 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.7.10 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.7.9 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.7.8 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.7.7 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.7.5 lib/cloud_sesame/query/dsl/applied_filter_query.rb
CloudSesame-0.7.4 lib/cloud_sesame/query/dsl/applied_filter_query.rb