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]
- ENUMERABLE_METHODS =
ENUMERABLE_METHODS_WITH_RETURN + [:each]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of JavaScriptCollectionProxy.
792
793
794
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 792
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
823
824
825
826
827
828
829
830
831
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 823
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.
789
790
791
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 789
def generator
@generator
end
|
Instance Method Details
#grep(variable, pattern, &block) ⇒ Object
796
797
798
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 796
def grep(variable, pattern, &block)
enumerate :grep, :variable => variable, :return => true, :method_args => [pattern], :yield_args => %w(value index), &block
end
|
#inject(variable, memo, &block) ⇒ Object
800
801
802
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 800
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
804
805
806
807
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 804
def pluck(variable, property)
add_variable_assignment!(variable)
append_enumerable_function!("pluck(#{property.to_json});")
end
|
#zip(variable, *arguments, &block) ⇒ Object
809
810
811
812
813
814
815
816
817
818
819
820
|
# File 'lib/action_view/helpers/prototype_helper.rb', line 809
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
|