Class: Workarea::StringId
Overview
TODO: Remove in v4 A class used strictly for allowing custom strings for model ids while maintaining support for the use of a BSON::ObjectId as the default. Documents within a collection using StringId for _id can be created and queried with either a String or BSON::ObjectId. Legal object ids will be converted before reading or writing from the database.
Class Method Summary collapse
- .evolve(object) ⇒ Object
- .mongoize(object) ⇒ Object (also: demongoize)
Methods inherited from String
#optionize, optionize_seperator_regexes, optionize_unwanted_chars_regex
Class Method Details
.evolve(object) ⇒ Object
38 39 40 41 42 |
# File 'lib/workarea/string_id.rb', line 38 def evolve(object) __evolve__(object) do |obj| obj.regexp? ? obj : obj.to_s.send(:convert_to_object_id) end end |
.mongoize(object) ⇒ Object Also known as: demongoize
32 33 34 35 |
# File 'lib/workarea/string_id.rb', line 32 def mongoize(object) return if object.nil? object.to_s.send(:convert_to_object_id) end |