Sha256: 824d56356dbd8240a0a03b39d56838cad559ffa7369d8431b5ff64468efe3ba9

Contents?: true

Size: 654 Bytes

Versions: 6

Compression:

Stored size: 654 Bytes

Contents

# encoding: UTF-8

require 'securerandom'

module MarkLogic
  class ObjectId

    def initialize
      @id = SecureRandom.hex
    end

    def to_s
      @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

6 entries across 6 versions & 1 rubygems

Version Path
marklogic-0.0.7 lib/marklogic/object_id.rb
marklogic-0.0.6 lib/marklogic/object_id.rb
marklogic-0.0.5 lib/marklogic/object_id.rb
marklogic-0.0.4 lib/marklogic/object_id.rb
marklogic-0.0.3 lib/marklogic/object_id.rb
marklogic-0.0.1 lib/marklogic/object_id.rb