Class: Resources::Manager
- Inherits:
-
Object
- Object
- Resources::Manager
show all
- Includes:
- Routes
- Defined in:
- lib/resources/manager.rb
Instance Method Summary
collapse
Methods included from Routes
#current_path, #current_route, #named_routes, #path_parameters, #router, #routes
Constructor Details
#initialize(controller, request, *args) ⇒ Manager
Returns a new instance of Manager.
5
6
7
8
9
|
# File 'lib/resources/manager.rb', line 5
def initialize controller, request, *args
@controller = controller
@request = request
@settings = @controller.class.resource_configuration
end
|
Instance Method Details
#build_resource ⇒ Object
75
76
77
|
# File 'lib/resources/manager.rb', line 75
def build_resource
resource_class.new()
end
|
28
29
30
|
# File 'lib/resources/manager.rb', line 28
def
settings..is_a?(Proc) ? settings..call(params, controller) : settings.
end
|
#params ⇒ Object
59
60
61
|
# File 'lib/resources/manager.rb', line 59
def params
controller.params
end
|
#params_page ⇒ Object
67
68
69
|
# File 'lib/resources/manager.rb', line 67
def params_page
@params_page ||= option_with_params(:params_page)
end
|
#params_resource ⇒ Object
71
72
73
|
# File 'lib/resources/manager.rb', line 71
def params_resource
@params_resource ||= option_with_params(:params_resource)
end
|
#params_search ⇒ Object
63
64
65
|
# File 'lib/resources/manager.rb', line 63
def params_search
@params_search ||= option_with_params(:params_search)
end
|
#resource ⇒ Object
45
46
47
48
49
50
51
52
53
|
# File 'lib/resources/manager.rb', line 45
def resource
@resource ||=
case controller.action_name
when "new", "create"
build_resource
else
resource_scope.where("#{resource_class.table_name}.id = ?",params[:id]).first rescue nil
end
end
|
#resource_class ⇒ Object
11
12
13
|
# File 'lib/resources/manager.rb', line 11
def resource_class
@resource_class_name ||= settings.resource_class_name.to_s.safe_constantize
end
|
#resource_scope ⇒ Object
32
33
34
|
# File 'lib/resources/manager.rb', line 32
def resource_scope
@resource_scope = option_with_scope(:resource_scope)
end
|
#resources ⇒ Object
41
42
43
|
# File 'lib/resources/manager.rb', line 41
def resources
@resources ||= settings.search ? resources_search.result(settings.search_options) : resources_scope
end
|
#resources_scope ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/resources/manager.rb', line 15
def resources_scope
scope = option_with_scope(:resources_scope)
@resources_scope =
case
when
scope = scope.page(params_page) if scope.respond_to?(:page)
scope = scope.paginate(page: params_page) if scope.respond_to?(:paginate)
scope
else
scope
end
end
|
#resources_search ⇒ Object
36
37
38
|
# File 'lib/resources/manager.rb', line 36
def resources_search
@resources_search ||= resources_scope.search(params_search) rescue nil
end
|
#settings ⇒ Object
55
56
57
|
# File 'lib/resources/manager.rb', line 55
def settings
@settings
end
|