Sha256: 957ad38f626b73f0c650dedbb3505633df2e45930dfad99d1b8cd232d9055295

Contents?: true

Size: 935 Bytes

Versions: 4

Compression:

Stored size: 935 Bytes

Contents

# Timestamp function for Rhubarb.
#
# Copyright (c) 2009--2010 Red Hat, Inc.
#
# Author:  William Benton (willb@redhat.com)
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0

require 'time'

module Rhubarb
  module Util
    # A higher-resolution timestamp
    def self.timestamp(tm=nil)
      tm ||= Time.now.utc
      (tm.tv_sec * 1000000) + tm.tv_usec
    end

    # Identity for objects that may be used as foreign keys
    def self.rhubarb_fk_identity(object)
      (object.row_id if object.class.ancestors.include? Persisting) || object
    end
    
    def self.blobify(obj)
      blobify_proc.call(obj)
    end
    
    def self.blobify_proc
      @blobify_proc ||= Proc.new {|x| x.is_a?(SQLite3::Blob) ? x : SQLite3::Blob.new(x)}
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rhubarb-0.2.5 lib/rhubarb/util.rb
rhubarb-0.2.4 lib/rhubarb/util.rb
rhubarb-0.2.3 lib/rhubarb/util.rb
rhubarb-0.2.2 lib/rhubarb/util.rb