Class: MarkLogic::ObjectId

Inherits:
Object
  • Object
show all
Defined in:
lib/marklogic/object_id.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObjectId

Returns a new instance of ObjectId.



8
9
10
# File 'lib/marklogic/object_id.rb', line 8

def initialize
  @id = SecureRandom.hex
end

Class Method Details

.from_string(str) ⇒ Object



21
22
23
24
25
# File 'lib/marklogic/object_id.rb', line 21

def from_string(str)
  object_id = allocate
  object_id.instance_variable_set(:@id, str)
  object_id
end

.legal?(string) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/marklogic/object_id.rb', line 27

def legal?(string)
  string.to_s =~ /^[0-9a-f]{32}$/i ? true : false
end

Instance Method Details

#==(other) ⇒ Object



32
33
34
# File 'lib/marklogic/object_id.rb', line 32

def ==(other)
  to_s == other.to_s
end

#as_json(options = nil) ⇒ Object



36
37
38
# File 'lib/marklogic/object_id.rb', line 36

def as_json(options=nil)
  to_s
end

#hashObject



44
45
46
# File 'lib/marklogic/object_id.rb', line 44

def hash
  to_s.hash
end

#inspectObject



16
17
18
# File 'lib/marklogic/object_id.rb', line 16

def inspect
  "#<#{self.class}('#{@id}')>"
end

#to_json(options = nil) ⇒ Object



40
41
42
# File 'lib/marklogic/object_id.rb', line 40

def to_json(options = nil)
  as_json.to_json
end

#to_sObject Also known as: to_str



12
13
14
# File 'lib/marklogic/object_id.rb', line 12

def to_s
  @id
end