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.



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

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)



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

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.



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

def generator
  @generator
end

Instance Method Details

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



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

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



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

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



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

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

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



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

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