Class: Nemo::MetaObject::MultipleRelationshipAttribute

Inherits:
RelationshipAttribute show all
Defined in:
lib/nemo/metaobject/attributes.rb

Instance Attribute Summary

Attributes inherited from Attribute

#cache, #metaobject, #symbol, #validation_rules

Instance Method Summary collapse

Methods inherited from RelationshipAttribute

#formatted_items, #items

Methods inherited from Attribute

#add_validation_rule, #commit_cache, #error_class, #format, #initialize, #required, #required?, #rule_class, #validate_cache, #value

Methods included from Util::Accessors

#bool_accessor, #call_accessor, #proc_accessor

Constructor Details

This class inherits a constructor from Nemo::MetaObject::Attribute

Instance Method Details

#accept(visitor) ⇒ Object



257
258
259
# File 'lib/nemo/metaobject/attributes.rb', line 257

def accept(visitor)
  visitor.visit_multiple_relationship_attribute(self)
end

#add_required_ruleObject



261
262
263
# File 'lib/nemo/metaobject/attributes.rb', line 261

def add_required_rule
  add_validation_rule { |value| ! value.to_s.empty? }.error_string('required')
end

#add_to_cache(item) ⇒ Object



265
266
267
268
# File 'lib/nemo/metaobject/attributes.rb', line 265

def add_to_cache(item)
  @cache ||= Array.new
  @cache << item
end

#formatted_valueObject



278
279
280
# File 'lib/nemo/metaobject/attributes.rb', line 278

def formatted_value
  value.collect { |item| format(item) }
end

#refresh_cacheObject



270
271
272
# File 'lib/nemo/metaobject/attributes.rb', line 270

def refresh_cache
  @cache = value.collect
end

#remove_from_cache(item) ⇒ Object



274
275
276
# File 'lib/nemo/metaobject/attributes.rb', line 274

def remove_from_cache(item)
  cache.delete(item)
end