extended_inherited_resources 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{extended_inherited_resources}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["josevalim", "stevo"]
|
@@ -33,10 +33,26 @@ module InheritedResources
|
|
33
33
|
# @projects ||= end_of_association_chain.paginate(params[:page]).all
|
34
34
|
# end
|
35
35
|
#
|
36
|
+
|
37
|
+
def setup_searchlogic(param)
|
38
|
+
if param
|
39
|
+
param=:search unless param.is_a? Symbol
|
40
|
+
instance_variable_set("@search",end_of_association_chain.searchlogic(params[param]))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def config_hash
|
45
|
+
self.class.resources_configuration[:self]
|
46
|
+
end
|
47
|
+
|
36
48
|
def collection
|
37
|
-
|
49
|
+
setup_searchlogic(config_hash[:searchlogic])
|
50
|
+
end_of_chain = config_hash[:searchlogic] ? @search : end_of_association_chain
|
51
|
+
end_of_chain = (per_page = config_hash[:pagination]) ? end_of_chain.paginate(:page => params[:page], :per_page => per_page) : end_of_chain.find(:all)
|
52
|
+
get_collection_ivar || set_collection_ivar(end_of_chain)
|
38
53
|
end
|
39
54
|
|
55
|
+
|
40
56
|
# This is how the resource is loaded.
|
41
57
|
#
|
42
58
|
# You might want to overwrite this method when you are using permalink.
|
@@ -36,7 +36,7 @@ module InheritedResources
|
|
36
36
|
options.symbolize_keys!
|
37
37
|
options.assert_valid_keys(:resource_class, :collection_name, :instance_name,
|
38
38
|
:class_name, :route_prefix, :route_collection_name,
|
39
|
-
:route_instance_name, :singleton, :redirects)
|
39
|
+
:route_instance_name, :singleton, :redirects, :searchlogic, :pagination)
|
40
40
|
|
41
41
|
self.resource_class = options.delete(:resource_class) if options.key?(:resource_class)
|
42
42
|
self.resource_class = options.delete(:class_name).constantize if options.key?(:class_name)
|
@@ -56,6 +56,9 @@ module InheritedResources
|
|
56
56
|
self.redirects = {:create => self.redirects, :update => self.redirects}
|
57
57
|
end
|
58
58
|
|
59
|
+
config[:searchlogic] = options.delete(:searchlogic) if options.key?(:searchlogic)
|
60
|
+
config[:pagination] = options.delete(:pagination) if options.key?(:pagination)
|
61
|
+
|
59
62
|
options.each do |key, value|
|
60
63
|
config[key] = value.to_sym
|
61
64
|
end
|
@@ -255,11 +258,15 @@ module InheritedResources
|
|
255
258
|
|
256
259
|
config[:route_collection_name] = config[:collection_name]
|
257
260
|
config[:route_instance_name] = config[:instance_name]
|
261
|
+
|
262
|
+
config[:pagination] ||= 25
|
263
|
+
config[:searchlogic] ||= false
|
264
|
+
|
258
265
|
|
259
266
|
# Deal with namespaced controllers
|
260
267
|
namespaces = self.controller_path.split('/')[0..-2]
|
261
268
|
config[:route_prefix] = namespaces.join('_') unless namespaces.empty?
|
262
|
-
|
269
|
+
|
263
270
|
self.redirects ||= {}
|
264
271
|
self.redirects[:create] ||= :index
|
265
272
|
self.redirects[:update] ||= :index
|