Module: Ripple::NestedAttributes
- Extended by:
- ActiveSupport::Concern
- Defined in:
- ripple/lib/ripple/nested_attributes.rb
Overview
:nodoc:
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Constant Summary
- UNASSIGNABLE_KEYS =
%w{ _destroy }
- TRUE_VALUES =
[ true, "true", 1, "1", "yes", "ok", "y" ]
Instance Method Summary (collapse)
- - (Object) assign_to_or_mark_for_destruction(record, attributes, association_name, allow_destroy)
- - (Object) call_reject_if(association_name, attributes)
- - (Boolean) has_destroy_flag?(hash)
- - (Boolean) reject_new_record?(association_name, attributes)
Instance Method Details
- (Object) assign_to_or_mark_for_destruction(record, attributes, association_name, allow_destroy)
251 252 253 254 255 256 257 |
# File 'ripple/lib/ripple/nested_attributes.rb', line 251 def assign_to_or_mark_for_destruction(record, attributes, association_name, allow_destroy) if has_destroy_flag?(attributes) && allow_destroy (self.marked_for_destruction[association_name] ||= []) << record else record.attributes = attributes.except(*UNASSIGNABLE_KEYS) end end |
- (Object) call_reject_if(association_name, attributes)
267 268 269 270 271 272 273 274 275 |
# File 'ripple/lib/ripple/nested_attributes.rb', line 267 def call_reject_if(association_name, attributes) attributes = attributes.stringify_keys case callback = [association_name][:reject_if] when Symbol method(callback).arity == 0 ? send(callback) : send(callback, attributes) when Proc callback.call(attributes) end end |
- (Boolean) has_destroy_flag?(hash)
259 260 261 |
# File 'ripple/lib/ripple/nested_attributes.rb', line 259 def has_destroy_flag?(hash) TRUE_VALUES.include?(hash.stringify_keys['_destroy']) end |
- (Boolean) reject_new_record?(association_name, attributes)
263 264 265 |
# File 'ripple/lib/ripple/nested_attributes.rb', line 263 def reject_new_record?(association_name, attributes) has_destroy_flag?(attributes) || call_reject_if(association_name, attributes) end |