Class: Sunrise::Controllers::ModelFilter
- Inherits:
-
Object
- Object
- Sunrise::Controllers::ModelFilter
show all
- Defined in:
- lib/sunrise/controllers/model_filter.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(controller, params = {}) ⇒ ModelFilter
Returns a new instance of ModelFilter.
9
10
11
12
13
|
# File 'lib/sunrise/controllers/model_filter.rb', line 9
def initialize(controller, params = {})
@params = params.symbolize_keys
@controller = controller
@order = (@params[:search] || {})
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/sunrise/controllers/model_filter.rb', line 15
def method_missing(method, *args, &block)
match_data = method.to_s.match(/^(.+)_before_type_cast$/)
method_name = (match_data ? match_data[1] : method).to_sym
if respond_to?(method_name)
@params[method_name]
else
super
end
end
|
Instance Attribute Details
#controller ⇒ Object
Returns the value of attribute controller.
7
8
9
|
# File 'lib/sunrise/controllers/model_filter.rb', line 7
def controller
@controller
end
|
#order ⇒ Object
Returns the value of attribute order.
7
8
9
|
# File 'lib/sunrise/controllers/model_filter.rb', line 7
def order
@order
end
|
#params ⇒ Object
Returns the value of attribute params.
7
8
9
|
# File 'lib/sunrise/controllers/model_filter.rb', line 7
def params
@params
end
|
Class Method Details
.model_name ⇒ Object
48
49
50
|
# File 'lib/sunrise/controllers/model_filter.rb', line 48
def model_name
@_model_name ||= OpenStruct.new(:singular => "search", :plural => "searches")
end
|
Instance Method Details
#current_order ⇒ Object
43
44
45
|
# File 'lib/sunrise/controllers/model_filter.rb', line 43
def current_order
"#{@order_column}_#{@order_type}"
end
|
#order?(method_name) ⇒ Boolean
35
36
37
|
# File 'lib/sunrise/controllers/model_filter.rb', line 35
def order?(method_name)
controller.orders_configuration.keys.include?(method_name.to_sym)
end
|
#respond_to?(method_name) ⇒ Boolean
26
27
28
29
|
# File 'lib/sunrise/controllers/model_filter.rb', line 26
def respond_to?(method_name)
return true if scope?(method_name) || @params.has_key?(method_name.to_sym)
super
end
|
#scope?(method_name) ⇒ Boolean
31
32
33
|
# File 'lib/sunrise/controllers/model_filter.rb', line 31
def scope?(method_name)
controller.scopes_configuration.values.collect { |v| v[:as] }.include?(method_name.to_sym)
end
|
#to_key ⇒ Object
39
40
41
|
# File 'lib/sunrise/controllers/model_filter.rb', line 39
def to_key
[]
end
|