Class: Doodle::AppendableAttribute
- Inherits:
-
AttributeCollector
- Object
- Doodle
- DoodleAttribute
- AttributeCollector
- Doodle::AppendableAttribute
- Defined in:
- lib/doodle.rb
Overview
define collector methods for array-like attribute collectors
Instance Method Summary collapse
-
#define_collection ⇒ Object
define a collector for appendable collections - collection should provide a :<< method.
Methods inherited from AttributeCollector
#initialize, #post_process, #resolve_collector_class, #resolve_value
Methods inherited from DoodleAttribute
#abstract, #default_defined?, #init_defined?, #optional?, params_from_args, #readonly, #required?, #validate!
Methods inherited from Doodle
context, parent, raise_exception_on_error, raise_exception_on_error=
Methods included from Core
Constructor Details
This class inherits a constructor from Doodle::AttributeCollector
Instance Method Details
#define_collection ⇒ Object
define a collector for appendable collections
-
collection should provide a :<< method
1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 |
# File 'lib/doodle.rb', line 1439 def define_collection # FIXME: don't use eval in 1.9+ if collector_class.nil? doodle_owner.sc_eval("def #{collector_name}(*args, &block) junk = #{name} if !#{name} # force initialization for classes args.unshift(block) if block_given? #{name}.<<(*args); end", __FILE__, __LINE__) else doodle_owner.sc_eval("def #{collector_name}(*args, &block) junk = #{name} if !#{name} # force initialization for classes if args.size > 0 and args.all?{|x| x.kind_of?(#{collector_class})} #{name}.<<(*args) else #{name} << #{collector_class}.new(*args, &block) end end", __FILE__, __LINE__) end end |