Class: ActionView::Helpers::JavaScriptCollectionProxy

Inherits:
JavaScriptProxy
  • Object
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.


818
819
820
# File 'lib/action_view/helpers/prototype_helper.rb', line 818

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)


849
850
851
852
853
854
855
856
857
# File 'lib/action_view/helpers/prototype_helper.rb', line 849

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


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

def generator
  @generator
end

Instance Method Details

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


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

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


826
827
828
# File 'lib/action_view/helpers/prototype_helper.rb', line 826

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


830
831
832
833
# File 'lib/action_view/helpers/prototype_helper.rb', line 830

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

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


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

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