Module: Mongoid::Extensions::String
- Defined in:
- lib/mongoid/extensions/string.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#unconvertable_to_bson ⇒ Object
Returns the value of attribute unconvertable_to_bson.
- #unconvertable_to_bson If the document is unconvertable.(Ifthedocumentisunconvertable.) ⇒ Object
Instance Method Summary collapse
-
#__evolve_object_id__ ⇒ String, BSON::ObjectId
Evolve the string into an object id if possible.
-
#__mongoize_object_id__ ⇒ String, ...
Mongoize the string into an object id if possible.
-
#__mongoize_time__ ⇒ Time | ActiveSupport::TimeWithZone
Mongoize the string for storage.
-
#before_type_cast? ⇒ true, false
Does the string end with _before_type_cast?.
-
#collectionize ⇒ String
Convert the string to a collection friendly name.
-
#mongoid_id? ⇒ true, false
Is the string a valid value for a Mongoid id?.
-
#numeric? ⇒ true, false
Is the string a number? The literals “NaN”, “Infinity”, and “-Infinity” are counted as numbers.
-
#reader ⇒ String
Get the string as a getter string.
-
#unconvertable_to_bson? ⇒ true, false
Is the object not to be converted to bson on criteria creation?.
-
#valid_method_name? ⇒ true, false
Is this string a valid_method_name?.
-
#writer? ⇒ true, false
Is this string a writer?.
Instance Attribute Details
#unconvertable_to_bson ⇒ Object
Returns the value of attribute unconvertable_to_bson.
8 9 10 |
# File 'lib/mongoid/extensions/string.rb', line 8 def unconvertable_to_bson @unconvertable_to_bson end |
#unconvertable_to_bson If the document is unconvertable.(Ifthedocumentisunconvertable.) ⇒ Object
8 |
# File 'lib/mongoid/extensions/string.rb', line 8 attr_accessor :unconvertable_to_bson |
Instance Method Details
#__evolve_object_id__ ⇒ String, BSON::ObjectId
Evolve the string into an object id if possible.
16 17 18 |
# File 'lib/mongoid/extensions/string.rb', line 16 def __evolve_object_id__ convert_to_object_id end |
#__mongoize_object_id__ ⇒ String, ...
Mongoize the string into an object id if possible.
26 27 28 |
# File 'lib/mongoid/extensions/string.rb', line 26 def __mongoize_object_id__ convert_to_object_id unless blank? end |
#__mongoize_time__ ⇒ Time | ActiveSupport::TimeWithZone
Returns a local time in the default time zone.
Mongoize the string for storage.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mongoid/extensions/string.rb', line 40 def __mongoize_time__ # This extra parse from Time is because ActiveSupport::TimeZone # either returns nil or Time.now if the string is empty or invalid, # which is a regression from pre-3.0 and also does not agree with # the core Time API. parsed = ::Time.parse(self) if ::Time == ::Time.configured parsed else ::Time.configured.parse(self) end end |
#before_type_cast? ⇒ true, false
Does the string end with _before_type_cast?
122 123 124 |
# File 'lib/mongoid/extensions/string.rb', line 122 def before_type_cast? ends_with?("_before_type_cast") end |
#collectionize ⇒ String
Convert the string to a collection friendly name.
59 60 61 |
# File 'lib/mongoid/extensions/string.rb', line 59 def collectionize tableize.gsub("/", "_") end |
#mongoid_id? ⇒ true, false
Is the string a valid value for a Mongoid id?
69 70 71 |
# File 'lib/mongoid/extensions/string.rb', line 69 def mongoid_id? self =~ /\A(|_)id\z/ end |
#numeric? ⇒ true, false
Is the string a number? The literals “NaN”, “Infinity”, and “-Infinity” are counted as numbers.
80 81 82 83 84 |
# File 'lib/mongoid/extensions/string.rb', line 80 def numeric? !!Float(self) rescue ArgumentError (self =~ /\A(?:NaN|-?Infinity)\z/) == 0 end |
#reader ⇒ String
Get the string as a getter string.
92 93 94 |
# File 'lib/mongoid/extensions/string.rb', line 92 def reader delete("=").sub(/\_before\_type\_cast\z/, '') end |
#unconvertable_to_bson? ⇒ true, false
Is the object not to be converted to bson on criteria creation?
132 133 134 |
# File 'lib/mongoid/extensions/string.rb', line 132 def unconvertable_to_bson? @unconvertable_to_bson ||= false end |
#valid_method_name? ⇒ true, false
Is this string a valid_method_name?
112 113 114 |
# File 'lib/mongoid/extensions/string.rb', line 112 def valid_method_name? /[@$"-]/ !~ self end |
#writer? ⇒ true, false
Is this string a writer?
102 103 104 |
# File 'lib/mongoid/extensions/string.rb', line 102 def writer? include?("=") end |