Class: ActionView::Helpers::JavaScriptCollectionProxy

Inherits:
JavaScriptProxy show all
Defined in:
lib/action_view/helpers/prototype_helper.rb

Overview

:nodoc:

Direct Known Subclasses

JavaScriptElementCollectionProxy

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

#initialize(generator, pattern) ⇒ JavaScriptCollectionProxy

Returns a new instance of JavaScriptCollectionProxy.



808
809
810
# File 'lib/action_view/helpers/prototype_helper.rb', line 808

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 (private)



839
840
841
842
843
844
845
846
847
# File 'lib/action_view/helpers/prototype_helper.rb', line 839

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

#generatorObject (readonly)

Returns the value of attribute generator.



805
806
807
# File 'lib/action_view/helpers/prototype_helper.rb', line 805

def generator
  @generator
end

Instance Method Details

#grep(variable, pattern, &block) ⇒ Object



812
813
814
# File 'lib/action_view/helpers/prototype_helper.rb', line 812

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



816
817
818
# File 'lib/action_view/helpers/prototype_helper.rb', line 816

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



820
821
822
823
# File 'lib/action_view/helpers/prototype_helper.rb', line 820

def pluck(variable, property)
  add_variable_assignment!(variable)
  append_enumerable_function!("pluck(#{property.to_json});")
end

#zip(variable, *arguments, &block) ⇒ Object



825
826
827
828
829
830
831
832
833
834
835
836
# File 'lib/action_view/helpers/prototype_helper.rb', line 825

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