module BreezyTemplate::SearchExtension

Public Instance Methods

_found!() click to toggle source
# File lib/breezy_template/search_extension.rb, line 5
def _found!
  if !@search_path.nil? && @found.nil?
    ::Kernel.raise NotFoundError.build(@search_path)
  end

  found = @found
  @found = nil
  @search_path = nil
  found
end
_mapping_element(element, options) { |element| ... } click to toggle source
Calls superclass method
# File lib/breezy_template/search_extension.rb, line 25
def _mapping_element(element, options)
  if @search_path && !@search_path.empty?
    original_search_path = @search_path
    @search_path = original_search_path[1..-1]
    if @search_path.size == 0
      @found = super
    else
      yield element
    end

    @search_path = original_search_path
  else
    super
  end
end
_prepare_collection_for_map(collection) click to toggle source
Calls superclass method
# File lib/breezy_template/search_extension.rb, line 41
def _prepare_collection_for_map(collection)
  if @search_path && !@search_path.empty?
    id_name, id_val = @search_path.first.split('=')

    if id_val
      id_val = id_val.to_i
      found = collection.member_by(id_name, id_val)
    else
      index = id_name.to_i
      found = collection.member_at(index)
    end

    found ? [found] : []
  else
    super
  end
end
_set_search_path_once(search_path) click to toggle source
# File lib/breezy_template/search_extension.rb, line 16
def _set_search_path_once(search_path)
  return if @search_path

  if search_path.is_a? ::String
    return _set_search_path_once(search_path.split('.'))
  end
  @search_path = search_path
end
set!(key, value = BLANK, *args) { |self| ... } click to toggle source
Calls superclass method
# File lib/breezy_template/search_extension.rb, line 59
def set!(key, value = BLANK, *args)
  return if @found
  options = args.first || {}

  if @search_path && !@search_path.empty?
    if key.to_s == @search_path.first
      original_search_path = @search_path
      @search_path = original_search_path[1..-1]
      if @search_path.size == 0
        @found = super
      else
        if ::Kernel.block_given?
          yield self
        elsif _partial_options?(options)
          without = options.dup
          without.delete(:cache)

          super(key, value, without)
        else
          ::Kernel.raise LeafTraversalError.build(key, value, options, @search_path)
        end
      end

      @search_path = original_search_path
    end

    return _blank
  else
    super
  end
end