Class: ActionView::Helpers::JavaScriptCollectionProxy
Overview
Constant Summary
collapse
- ENUMERABLE_METHODS_WITH_RETURN =
[:all, :any, :collect, :map, :detect, :find, :find_all, :select, :max, :min, :partition, :reject, :sort_by, :in_groups_of, :each_slice]
- ENUMERABLE_METHODS =
ENUMERABLE_METHODS_WITH_RETURN + [:each]
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#each_slice(variable, number, &block) ⇒ Object
-
#grep(variable, pattern, &block) ⇒ Object
-
#in_groups_of(variable, number, fill_with = nil) ⇒ Object
-
#initialize(generator, pattern) ⇒ JavaScriptCollectionProxy
constructor
A new instance of JavaScriptCollectionProxy.
-
#inject(variable, memo, &block) ⇒ Object
-
#pluck(variable, property) ⇒ Object
-
#zip(variable, *arguments, &block) ⇒ Object
Constructor Details
Returns a new instance of JavaScriptCollectionProxy.
1205
1206
1207
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 1205
def initialize(generator, pattern)
super(generator, @pattern = pattern)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
1252
1253
1254
1255
1256
1257
1258
1259
1260
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 1252
def method_missing(method, *arguments, &block)
if ENUMERABLE_METHODS.include?(method)
returnable = ENUMERABLE_METHODS_WITH_RETURN.include?(method)
variable = arguments.first if returnable
enumerate(method, {:variable => (arguments.first if returnable), :return => returnable, :yield_args => %w(value index)}, &block)
else
super
end
end
|
Instance Attribute Details
#generator ⇒ Object
Returns the value of attribute generator.
1202
1203
1204
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 1202
def generator
@generator
end
|
Instance Method Details
#each_slice(variable, number, &block) ⇒ Object
1209
1210
1211
1212
1213
1214
1215
1216
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 1209
def each_slice(variable, number, &block)
if block
enumerate :eachSlice, :variable => variable, :method_args => [number], :yield_args => %w(value index), :return => true, &block
else
add_variable_assignment!(variable)
append_enumerable_function!("eachSlice(#{::ActiveSupport::JSON.encode(number)});")
end
end
|
#grep(variable, pattern, &block) ⇒ Object
1218
1219
1220
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 1218
def grep(variable, pattern, &block)
enumerate :grep, :variable => variable, :return => true, :method_args => [pattern], :yield_args => %w(value index), &block
end
|
#in_groups_of(variable, number, fill_with = nil) ⇒ Object
1222
1223
1224
1225
1226
1227
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 1222
def in_groups_of(variable, number, fill_with = nil)
arguments = [number]
arguments << fill_with unless fill_with.nil?
add_variable_assignment!(variable)
append_enumerable_function!("inGroupsOf(#{arguments_for_call arguments});")
end
|
#inject(variable, memo, &block) ⇒ Object
1229
1230
1231
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 1229
def inject(variable, memo, &block)
enumerate :inject, :variable => variable, :method_args => [memo], :yield_args => %w(memo value index), :return => true, &block
end
|
#pluck(variable, property) ⇒ Object
1233
1234
1235
1236
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 1233
def pluck(variable, property)
add_variable_assignment!(variable)
append_enumerable_function!("pluck(#{::ActiveSupport::JSON.encode(property)});")
end
|
#zip(variable, *arguments, &block) ⇒ Object
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 1238
def zip(variable, *arguments, &block)
add_variable_assignment!(variable)
append_enumerable_function!("zip(#{arguments_for_call arguments}")
if block
function_chain[-1] += ", function(array) {"
yield ::ActiveSupport::JSON::Variable.new('array')
add_return_statement!
@generator << '});'
else
function_chain[-1] += ');'
end
end
|