Module: Rhubarb::Util

Defined in:
lib/rhubarb/util.rb

Class Method Summary collapse

Class Method Details

.blobify_procObject



34
35
36
# File 'lib/rhubarb/util.rb', line 34

def self.blobify_proc
  @blobify_proc ||= Proc.new {|obj| obj.is_a?(SQLite3::Blob) ? obj : SQLite3::Blob.new(obj)}
end

.deswizzle_object_procObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/rhubarb/util.rb', line 59

def self.deswizzle_object_proc
  @deswizzle_object_proc ||= Proc.new do |zy_obj|
    if zy_obj.nil? || zy_obj == ""
      nil
    else
      obj = YAML.load(Zlib::Inflate.inflate(zy_obj))
      obj.freeze
    end
  end
end

.dezblobify_procObject



42
43
44
45
46
47
48
49
50
# File 'lib/rhubarb/util.rb', line 42

def self.dezblobify_proc
  @dezblobify_proc ||= Proc.new do |obj| 
    if obj.nil? || obj == ""
      nil
    else
      Zlib::Inflate.inflate(obj)
    end
  end
end

.rhubarb_fk_identity(object) ⇒ Object

Identity for objects that may be used as foreign keys



26
27
28
# File 'lib/rhubarb/util.rb', line 26

def self.rhubarb_fk_identity(object)
  (object.class.ancestors.include?(Persisting) || object.class.ancestors.include?(Rhubarb::Persisting)) ? object.row_id : object
end

.swizzle_object_procObject



52
53
54
55
56
57
# File 'lib/rhubarb/util.rb', line 52

def self.swizzle_object_proc
  @swizzle_object_proc ||= Proc.new do |obj| 
    yamlrepr = obj.to_yaml
    SQLite3::Blob.new(Zlib::Deflate.deflate(yamlrepr, Zlib::BEST_COMPRESSION))
  end
end

.timestamp(tm = nil) ⇒ Object

A higher-resolution timestamp



20
21
22
23
# File 'lib/rhubarb/util.rb', line 20

def self.timestamp(tm=nil)
  tm ||= Time.now.utc
  (tm.tv_sec * 1000000) + tm.tv_usec
end

.truthify_procObject



30
31
32
# File 'lib/rhubarb/util.rb', line 30

def self.truthify_proc
  @truthify_proc ||= Proc.new {|obj| !!(obj) ? "true" : "false"}
end

.zblobify_procObject



38
39
40
# File 'lib/rhubarb/util.rb', line 38

def self.zblobify_proc
  @zblobify_proc ||= Proc.new {|obj| obj.is_a?(SQLite3::Blob) ? obj : SQLite3::Blob.new(Zlib::Deflate.deflate(obj))}
end