Module: WrapIt::Arguments
Overview
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.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
#argument(name, opts = {}) {|name, value| ... } ⇒ void
extended
from ClassMethods
Desclares argument for capturing on initialization process.
-
#capture_arguments!(args, opts = {}, &block) ⇒ Array<Object>
extended
from ClassMethods
Capture arguments for class and it's ancestors.
-
#option(name, opts = {}) {|name, value| ... } ⇒ void
extended
from ClassMethods
Desclares option for capturing on initialization process.
Instance Method Summary collapse
-
#capture_arguments!(args, &block) ⇒ Array<Object>
Captures arguments.
Class Method Details
#argument(name, opts = {}) {|name, value| ... } ⇒ void Originally defined in module ClassMethods
This method returns an undefined value.
Desclares argument for capturing on initialization process.
Inside initialization process, all arguments (except options hash),
passed to constructor will be inspected to satisfy conditions,
specified in :if and :and options. If this happens, and block
given, it evaluated in context of component instance. If no block
given, setter with name will be attempted to set value. In any way
if conditions satisfied, argument removed from future processing.
If no conditions specified, the name of attribute taked as only
condition.
#capture_arguments!(args, opts = {}, &block) ⇒ Array<Object> Originally defined in module ClassMethods
Capture arguments for class and it's ancestors. All captured arguments
and options will be extracted from original args argument.
Actually you rare needs to call this method directly. For example you can call it in instance capture_arguments! override to capture arguments for some child components.
#option(name, opts = {}) {|name, value| ... } ⇒ void Originally defined in module ClassMethods
This method returns an undefined value.
Desclares option for capturing on initialization process.
Provides same manner as #argument but for hash of options, passed to constructor. Specified conditions are applied to options keys, not to values.
Hint: you can specify argument and options with same name to call same setter.
Instance Method Details
#capture_arguments!(args, &block) ⇒ Array<Object>
Captures arguments
In rare cases you can override this method to control directly arguments capturing process. Refer to capture_arguments! for examples.
Note that this method is
protected, so override should beprotectedtoo.
332 333 334 |
# File 'lib/wrap_it/arguments.rb', line 332 def capture_arguments!(args, &block) self.class.capture_arguments!(args, true, self, &block) end |