Class: Presenting::Search

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/presenting/search.rb

Defined Under Namespace

Classes: Field, FieldSet

Instance Method Summary collapse

Methods included from Configurable

#initialize

Instance Method Details

#fieldsObject



32
33
34
# File 'lib/presenting/search.rb', line 32

def fields
  @fields ||= FieldSet.new
end

#fields=(obj) ⇒ Object

I want to support three configuration formats:

Search.new(:fields => [:first_name, :last_name, :email])

Search.new(:fields => {
 'first_name' => :equals,
 'last_name' => :begins_with,
 'email' => :not_null
})

Search.new(:fields => {
 'fname' => {:sql => 'first_name', :pattern => :equals},
 'lname' => {:sql => 'last_name', :pattern => :begins_with},
 'email' => {:sql => 'email', :pattern => :not_null}
})


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/presenting/search.rb', line 20

def fields=(obj)
  case obj
  when Array
    obj.each do |name| fields << name end
    
  when Hash
    obj.each do |k, v|
      fields << {k => v}
    end 
  end
end

#to_sql(params, type = :simple) ⇒ Object



36
37
38
# File 'lib/presenting/search.rb', line 36

def to_sql(params, type = :simple)
  send("to_#{type}_sql", params) unless params.blank?
end