restful_json 3.0.0 → 3.0.1
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/lib/restful_json/controller.rb +11 -8
- data/lib/restful_json/version.rb +1 -1
- metadata +1 -1
@@ -9,6 +9,7 @@ module RestfulJson
|
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
11
|
module ClassMethods
|
12
|
+
|
12
13
|
def acts_as_restful_json(options = {})
|
13
14
|
include ::ActionController::Serialization
|
14
15
|
include ::ActionController::StrongParameters
|
@@ -16,6 +17,7 @@ module RestfulJson
|
|
16
17
|
include ::TwinTurbo::Controller
|
17
18
|
include ActsAsRestfulJson
|
18
19
|
end
|
20
|
+
|
19
21
|
end
|
20
22
|
|
21
23
|
module ActsAsRestfulJson
|
@@ -55,6 +57,7 @@ module RestfulJson
|
|
55
57
|
end
|
56
58
|
|
57
59
|
module ClassMethods
|
60
|
+
|
58
61
|
# A whitelist of filters and definition of filter options related to request parameters.
|
59
62
|
#
|
60
63
|
# If no options are provided or the :using option is provided, defines attributes that are queryable through the operation(s) already defined in can_filter_by_default_using, or can specify attributes:
|
@@ -129,16 +132,16 @@ module RestfulJson
|
|
129
132
|
# or
|
130
133
|
# order_by {:foo_date => :asc}, :foo_color, 'foo_name', {:bar_date => :desc}
|
131
134
|
def order_by(args)
|
132
|
-
|
133
|
-
self.ordered_by += args
|
134
|
-
elsif args.is_a?(Hash)
|
135
|
-
self.ordered_by.merge!(args)
|
136
|
-
else
|
137
|
-
raise ArgumentError.new("order_by takes a hash or array of hashes")
|
138
|
-
end
|
135
|
+
self.ordered_by = (Array.wrap(self.ordered_by) + Array.wrap(args)).flatten.compact.collect {|item|item.is_a?(Hash) ? item : {item.to_sym => :asc}}
|
139
136
|
end
|
140
137
|
end
|
141
138
|
|
139
|
+
# In initialize we:
|
140
|
+
# * guess model name, if unspecified, from controller name
|
141
|
+
# * define instance variables containing model name
|
142
|
+
# * define the (model_plural_name)_url method, needed if controllers are not in the same module as the models
|
143
|
+
# Note: if controller name is not based on model name *and* controller is in different module than model, you'll need to
|
144
|
+
# redefine the appropriate method(s) to return urls if needed.
|
142
145
|
def initialize
|
143
146
|
super
|
144
147
|
|
@@ -155,7 +158,7 @@ module RestfulJson
|
|
155
158
|
@model_at_singular_name_sym = "@#{@model_singular_name}".to_sym
|
156
159
|
underscored_modules_and_underscored_plural_model_name = qualified_controller_name.gsub('::','_').underscore
|
157
160
|
|
158
|
-
# This workaround for
|
161
|
+
# This is a workaround for controllers that are in a different module than the model only works if the controller's base part of the unqualified name in the plural model name.
|
159
162
|
# If the model name is different than the controller name, you will need to define methods to return the right urls.
|
160
163
|
class_eval "def #{@model_plural_name}_url;#{underscored_modules_and_underscored_plural_model_name}_url;end;def #{@model_singular_name}_url(record);#{underscored_modules_and_underscored_plural_model_name.singularize}_url(record);end"
|
161
164
|
end
|
data/lib/restful_json/version.rb
CHANGED