Module: Jinx::Unique
- Defined in:
- lib/jinx/resource/unique.rb
Overview
The Unique mix-in makes values unique within the scope of a Resource class.
Instance Method Summary collapse
-
#uniquify ⇒ Resource
Replaces each String secondary and alternate key property with a unique value.
-
#uniquify_attributes(attributes) ⇒ Object
private
Makes this domain object’s String values for the given attributes unique.
Instance Method Details
#uniquify ⇒ Resource
Replaces each String secondary and alternate key property with a unique value. Successive calls to this method for domain objects of the same class replace the same String key property values with the same unique value.
11 12 13 14 15 |
# File 'lib/jinx/resource/unique.rb', line 11 def uniquify uniquify_attributes(self.class.secondary_key_attributes) uniquify_attributes(self.class.alternate_key_attributes) self end |
#uniquify_attributes(attributes) ⇒ Object (private)
Makes this domain object’s String values for the given attributes unique.
22 23 24 25 26 27 28 29 30 |
# File 'lib/jinx/resource/unique.rb', line 22 def uniquify_attributes(attributes) attributes.each do |ka| oldval = send(ka) next unless String === oldval newval = UniquifierCache.instance.get(self, oldval) set_property_value(ka, newval) logger.debug { "Reset #{qp} #{ka} from #{oldval} to unique value #{newval}." } end end |