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 unconvetable.(Ifthedocumentisunconvetable.) ⇒ Object
Instance Method Summary collapse
-
#__evolve_object_id__ ⇒ String, Moped::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
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?.
-
#reader ⇒ String
Get the string as a getter string.
-
#to_a ⇒ Array
Convert the string to an array with the string in it.
-
#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.
7 8 9 |
# File 'lib/mongoid/extensions/string.rb', line 7 def unconvertable_to_bson @unconvertable_to_bson end |
#unconvertable_to_bson If the document is unconvetable.(Ifthedocumentisunconvetable.) ⇒ Object
7 |
# File 'lib/mongoid/extensions/string.rb', line 7 attr_accessor :unconvertable_to_bson |
Instance Method Details
#__evolve_object_id__ ⇒ String, Moped::BSON::ObjectId
Evolve the string into an object id if possible.
17 18 19 |
# File 'lib/mongoid/extensions/string.rb', line 17 def __evolve_object_id__ convert_to_object_id end |
#__mongoize_object_id__ ⇒ String, ...
Mongoize the string into an object id if possible.
29 30 31 |
# File 'lib/mongoid/extensions/string.rb', line 29 def __mongoize_object_id__ convert_to_object_id unless blank? end |
#__mongoize_time__ ⇒ Time
The 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.
Mongoize the string for storage.
46 47 48 49 |
# File 'lib/mongoid/extensions/string.rb', line 46 def __mongoize_time__ ::Time.parse(self) ::Time.configured.parse(self) end |
#before_type_cast? ⇒ true, false
Does the string end with _before_type_cast?
143 144 145 |
# File 'lib/mongoid/extensions/string.rb', line 143 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?
71 72 73 |
# File 'lib/mongoid/extensions/string.rb', line 71 def mongoid_id? self =~ /\A(|_)id$/ end |
#numeric? ⇒ true, false
Is the string a number?
83 84 85 |
# File 'lib/mongoid/extensions/string.rb', line 83 def numeric? true if Float(self) rescue (self == "NaN") end |
#reader ⇒ String
Get the string as a getter string.
95 96 97 |
# File 'lib/mongoid/extensions/string.rb', line 95 def reader delete("=").sub(/\_before\_type\_cast$/, '') end |
#to_a ⇒ Array
Convert the string to an array with the string in it.
107 108 109 |
# File 'lib/mongoid/extensions/string.rb', line 107 def to_a [ self ] end |
#unconvertable_to_bson? ⇒ true, false
Is the object not to be converted to bson on criteria creation?
155 156 157 |
# File 'lib/mongoid/extensions/string.rb', line 155 def unconvertable_to_bson? @unconvertable_to_bson ||= false end |
#valid_method_name? ⇒ true, false
Is this string a valid_method_name?
131 132 133 |
# File 'lib/mongoid/extensions/string.rb', line 131 def valid_method_name? /[@$"]/ !~ to_sym.inspect end |
#writer? ⇒ true, false
Is this string a writer?
119 120 121 |
# File 'lib/mongoid/extensions/string.rb', line 119 def writer? include?("=") end |