summaryrefslogtreecommitdiffstats
path: root/libimagruby/lib/imag.rb
blob: b8c911159822097ad90461ef1a9e8db58523df27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env ruby

module Imag

  IMAG_INIT_FN_NAME = 'imag_ruby_initialize'

  def self.setup binary_path
    require binary_path

    self.core_setup
    self.classes_setup
  end

  module Logger

    def self.init debug, verbose, color
      RImag.init_logger debug, verbose, color
    end

    def self.trace msg
      RImag.trace msg
    end

    def self.dbg msg
      RImag.dbg msg
    end

    def self.debug msg
      RImag.debug msg
    end

    def self.info msg
      RImag.info msg
    end

    def self.warn msg
      RImag.warn msg
    end

    def self.error msg
      RImag.error msg
    end

  end

  private

  def self.class_names
    [
      :StoreId             ,
      :StoreHandle         ,
      :FileLockEntryHandle ,
      :EntryHeader         ,
      :EntryContent        ,
    ]
  end

  def self.core_setup
    self.class_names.map {|n| [n, "R#{n}".to_sym ] }.each do |elem|
      Imag.const_set elem.first, Kernel.const_get(elem.last)
    end
  end

  def self.classes_setup
    self.class_storeid_setup
  end

  def self.class_storeid_setup
    Imag::StoreId.class_exec do
      def to_s
        self.to_str
      end
    end
  end

end

if __FILE__ == $0
  puts "Running some tests..."
  puts "I hope you passed the library object as first argument..."
  begin
    Imag.setup ARGV.first
  rescue Exception => e
    puts "Seems not to be the case... or something else went wrong..."
    puts e
    exit 1
  end

  Imag::Logger.init true, true, true
  Imag::Logger.info "The Logger should work now"

  Imag::Logger.info "Lets see whether we have properly setup StoreId"
  Imag::Logger.info Imag::StoreId::new_baseless("baselessId").to_s
  Imag::Logger.info "Seems good."
end