module WrapIt::Arguments

This module responisble to parse creation arguments in component initialization process.

Respect to ruby language, any method can take variable number of arguments and a hash of options. Also you can pass a block to it. So, when your component subclassed from WrapIt::Base, user can create its instances via helpers. And when such component initialized you should be able to process all arguments, passed to helper or constructor. Finally all unprocessed options setted as component html attributes.

Two API methods provided for this purposes - `argument` and `option`. Each of them declares conditions for capturing some arguments and options. Conditions applies to arguments itself or to options keys. CapturedArray Array extension is used to capture arguments, so refer to its documentation for conditions details.

@author Alexey Ovchinnikov <alexiss@cybernetlab.ru>

Constants

SETTER

Evaluated in instance context by .extract_for_class

Public Class Methods

included(base) click to toggle source
# File lib/wrap_it/arguments.rb, line 30
def self.included(base)
  @base = base
  base.extend ClassMethods
end

Private Class Methods

base() click to toggle source
# File lib/wrap_it/arguments.rb, line 365
def self.base
  @base
end
make_conditions(name, **opts) click to toggle source
# File lib/wrap_it/arguments.rb, line 359
def self.make_conditions(name, **opts)
  cond = normalize_conditions(opts.key?(:if) ? opts[:if] : name)
  opts.key?(:and) && cond << {and: normalize_conditions(opts[:and])}
  cond
end
normalize_conditions(cond) click to toggle source
# File lib/wrap_it/arguments.rb, line 350
def self.normalize_conditions(cond)
  if cond.is_a?(Array) &&
     cond.any? { |x| !x.is_a?(Symbol) && !x.is_a?(String) }
    cond
  else
    [cond]
  end
end

Protected Instance Methods

capture_arguments!(args, &block) click to toggle source

@!visibility public

Captures arguments

In rare cases you can override this method to control directly arguments capturing process. Refer to {ClassMethods#capture_arguments! capture_arguments!} for examples.

> Note that this method is `protected`, so override should be `protected` > too.

@param args [Array<Object>] arguments, passed to constructor @param block [Proc] block, passed to constructor

@return [Array<Object>] captured arguments

# File lib/wrap_it/arguments.rb, line 332
def capture_arguments!(args, &block)
  self.class.capture_arguments!(args, true, self, &block)
end