Class: Jsonoid::ObjectId
- Inherits:
-
Object
- Object
- Jsonoid::ObjectId
- Defined in:
- lib/jsonoid/object_id.rb
Class Method Summary collapse
Instance Method Summary collapse
- #!=(id) ⇒ Object
- #<=>(id) ⇒ Object
- #==(id) ⇒ Object
-
#initialize(id = nil) ⇒ ObjectId
constructor
A new instance of ObjectId.
- #new? ⇒ Boolean
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(id = nil) ⇒ ObjectId
Returns a new instance of ObjectId.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/jsonoid/object_id.rb', line 11 def initialize(id=nil) if id @id = id.to_s @new = false raise ArgumentError, 'Invalid ObjectId' unless valid? else @id = SecureRandom.hex @new = true end end |
Class Method Details
.parse(id) ⇒ Object
6 7 8 |
# File 'lib/jsonoid/object_id.rb', line 6 def parse(id) self.new(id) end |
Instance Method Details
#!=(id) ⇒ Object
35 36 37 |
# File 'lib/jsonoid/object_id.rb', line 35 def !=(id) @id != id.to_s end |
#<=>(id) ⇒ Object
39 40 41 |
# File 'lib/jsonoid/object_id.rb', line 39 def <=>(id) @id <=> id.to_s end |
#==(id) ⇒ Object
31 32 33 |
# File 'lib/jsonoid/object_id.rb', line 31 def ==(id) @id == id.to_s end |
#new? ⇒ Boolean
27 28 29 |
# File 'lib/jsonoid/object_id.rb', line 27 def new? @new end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/jsonoid/object_id.rb', line 43 def to_s @id end |
#valid? ⇒ Boolean
23 24 25 |
# File 'lib/jsonoid/object_id.rb', line 23 def valid? @id =~ /[a-z0-9]{32}/ end |