Class: Search

Inherits:
Object
  • Object
show all
Defined in:
app/models/search.rb

Overview

Originally from railscasts.com/episodes/111-advanced-search-form however, I have modified it heavily and made it quite abstract. Its still a bit muddy, but I’d like to replace it with rsolr.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attr_accessorsObject



21
22
23
# File 'app/models/search.rb', line 21

def attr_accessors
	@attr_accessors
end

.attr_accessors=(more_accessors) ⇒ Object

extend with += [ :something ] NOT << :something



24
25
26
27
# File 'app/models/search.rb', line 24

def attr_accessors=(more_accessors)	#	extend with += [ :something ] NOT << :something
	@attr_accessors = more_accessors
	attr_accessor *@attr_accessors
end

.searchable_attributesObject



15
16
17
# File 'app/models/search.rb', line 15

def searchable_attributes
	@searchable_attributes
end

.searchable_attributes=(more_attributes) ⇒ Object



18
19
20
# File 'app/models/search.rb', line 18

def searchable_attributes=(more_attributes)
	@searchable_attributes = more_attributes
end

.valid_ordersObject



9
10
11
# File 'app/models/search.rb', line 9

def valid_orders
	@valid_orders
end

.valid_orders=(more_orders) ⇒ Object



12
13
14
# File 'app/models/search.rb', line 12

def valid_orders=(more_orders)
	@valid_orders = more_orders
end

Instance Method Details

#attr_accessorsObject



41
42
43
# File 'app/models/search.rb', line 41

def attr_accessors
	self.class.attr_accessors
end

#search_orderObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/search.rb', line 45

def search_order
	if valid_orders.has_key?(@order)
		order_string = if valid_orders[@order].blank?
			@order
		else
			valid_orders[@order]
		end
		dir = case @dir.try(:downcase)
			when 'desc' then 'desc'
			else 'asc'
		end
		[order_string,dir].join(' ')
	else
		nil
	end
end

#searchable_attributesObject



37
38
39
# File 'app/models/search.rb', line 37

def searchable_attributes
	self.class.searchable_attributes
end

#valid_ordersObject



33
34
35
# File 'app/models/search.rb', line 33

def valid_orders
	self.class.valid_orders
end