Sha256: c7c994460fd2e2f9b0e917fc3df1213b6c80f6d35e141752bef52d7f988a0c29

Contents?: true

Size: 714 Bytes

Versions: 4

Compression:

Stored size: 714 Bytes

Contents

# encoding: UTF-8

require 'securerandom'

module MarkLogic
  class ObjectId

    def initialize
      @id = SecureRandom.hex
    end

    def to_s
      @id
    end

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

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

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

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

    def as_json(options=nil)
      to_s
    end

    def to_json(options = nil)
      as_json.to_json
    end

    def hash
      to_s.hash
    end

    alias to_str to_s
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
marklogic-0.0.11 lib/marklogic/object_id.rb
marklogic-0.0.10 lib/marklogic/object_id.rb
marklogic-0.0.9 lib/marklogic/object_id.rb
marklogic-0.0.8 lib/marklogic/object_id.rb