class Voom::Presenters::DSL::Components::Actions::Base

Attributes

dynamic_params[R]

Options are used by the actions Params are passed by the user

options[R]

Options are used by the actions Params are passed by the user

params[R]

Options are used by the actions Params are passed by the user

Public Class Methods

new(type:, **attribs_, &block) click to toggle source
# File lib/voom/presenters/dsl/components/actions/base.rb, line 11
def initialize(type:, **attribs_, &block)
  super(type: type, **attribs_, &block)
  @options = {}
  extract_options!
  _params_ = attribs.delete(:params) {{}}
  @dynamic_params = extract_dynamic_params(_params_)
  @params = extract_params(_params_)
  @url = nil
end

Public Instance Methods

url() click to toggle source
# File lib/voom/presenters/dsl/components/actions/base.rb, line 21
def url
  @parent.router.url(render: options[:presenter], command: options[:path], context: params)
end

Private Instance Methods

clean_dynamic_values(hash) click to toggle source

This is an attempt to fix an intermittent bug where “params” would end up in the list of values when using `last_response`.

# File lib/voom/presenters/dsl/components/actions/base.rb, line 46
def clean_dynamic_values(hash)
  hash[:value].delete(:params) if hash.has_key?(:value) && hash[:value].is_a?(Array)
  hash
end
extract_dynamic_params(hash) click to toggle source
# File lib/voom/presenters/dsl/components/actions/base.rb, line 34
def extract_dynamic_params(hash)
  HashExt::Traverse.traverse(hash) do |k, v|
    if v.respond_to?(:to_hash) || v.respond_to?(:dynamic_parameter)
      [k, clean_dynamic_values(v.to_hash)]
    else
      [nil, nil]
    end
  end
end
extract_options!() click to toggle source
# File lib/voom/presenters/dsl/components/actions/base.rb, line 27
def extract_options!
  %i(path presenter target input_tag headers).each do |option|
    option_value = attribs.delete(option){:not_found}
    @options.merge!({option => option_value}) unless option_value==:not_found
  end
end
extract_params(hash) click to toggle source
# File lib/voom/presenters/dsl/components/actions/base.rb, line 51
def extract_params(hash)
  HashExt::Traverse.traverse(hash) do |k, v|
    if v.respond_to?(:dynamic_parameter)
      [nil, nil]
    else
      [k, v]
    end
  end
end