Sha256: 6eea615ee800ea9995b8d245aed8eb236f671c9b4f67999b2593a5dbda637c02

Contents?: true

Size: 632 Bytes

Versions: 3

Compression:

Stored size: 632 Bytes

Contents

module Puffer
  class FieldSet < Array

    def field *args, &block
      push Puffer::Field.new(*args, &block)
      last
    end

    def searchable
      @searchable ||= map { |f| f if f.column && [:text, :string, :integer, :decimal, :float].include?(f.column.type) }.compact
    end

    def searches query
      searchable.map { |f| "#{f.query_column} like '%#{query}%'" if f.query_column.present? }.compact.join(' or ') if query
    end

    def boolean
      @boolean ||= reject { |f| f.type != :boolean }
    end

    def includes
      @includes ||= map {|f| f.path unless f.native?}.compact.to_includes
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
puffer-0.0.23 lib/puffer/field_set.rb
puffer-0.0.22 lib/puffer/field_set.rb
puffer-0.0.21 lib/puffer/field_set.rb