Sha256: 27195de672463ecdc170e74d7b1edb7df8071dd53659d3c573131c8434462288
Contents?: true
Size: 1.16 KB
Versions: 2
Compression:
Stored size: 1.16 KB
Contents
class Parelation::Criteria::Query < Parelation::Criteria # @return [Regexp] the query format. # QUERY_FORMAT = /^query$/ # @param param [String] # @return [TrueClass, FalseClass] # def self.match?(param) !!param.match(QUERY_FORMAT) end # @return [ActiveRecord::Relation] # def call chain.where(*criteria) end private # @return [Array] containing {#chain} criteria. # def criteria [sql] + args end # @return [String] an SQL statement based on the selected {#attributes}. # def sql template = ->(field) { %Q{"#{chain.arel_table.name}"."#{field}" LIKE ?} } attributes.map(&template).join(" OR ") end # @return [Array] containing the query, one for each field in {#attributes}. # def args attributes.count.times.map { "%#{query}%" } end # @return [String] the "search" query to perform. # def query @query ||= parts.first end # @return [Array<String>] an array of attributes to search in. # def attributes @attributes ||= parts.last end # @return [Array] containing the query and attributes. # def parts @parts ||= [value.keys.first, [value.values.first].flatten] end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
parelation-1.0.0 | lib/parelation/criteria/query.rb |
parelation-0.2.0 | lib/parelation/criteria/query.rb |