Class: Effigy::Selection

Inherits:
Object show all
Defined in:
lib/effigy/selection.rb

Overview

Proxy class for performing transformations with a set selection.

Selections are created and returned when calling View#find without a block. Any methods called on the Selection will be forwarded to the given view with the given selector inserted at the front of the argument list.

All methods should return the Selection itself, so transformation methods can be chained on a selection.

Normally, Selections are not instantiated directly, but by calling View#find.

Examples:

view = Effigy::View.new
# same as calling view.remove_class('.active', 'inactive')
view.find('.active').remove_class('inactive')

Instance Method Summary collapse

Constructor Details

#initialize(view, selector) ⇒ Selection

Creates a selection over the given view using the given selector.

Parameters:

  • view (View)

    the view to which transformations should be forwarded

  • selector (String)

    the selector that should be used for forwarded transformation methods



24
25
26
27
# File 'lib/effigy/selection.rb', line 24

def initialize(view, selector)
  @view     = view
  @selector = selector
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Selection

Undefined methods are forwarded to the view with the selector inserted at the beginning of the argument list. The Selection is then returned for chaining.

Returns:



34
35
36
37
# File 'lib/effigy/selection.rb', line 34

def method_missing(method, *args, &block)
  @view.send(method, @selector, *args, &block)
  self
end