imag/libimagruby/lib/imag.rb

104 lines
1.9 KiB
Ruby
Raw Normal View History

2017-01-22 15:39:57 +00:00
#!/usr/bin/env ruby
2017-02-04 11:30:55 +00:00
require 'thermite/fiddle'
toplevel_dir = File.dirname(File.dirname(__FILE__))
Thermite::Fiddle.load_module('init_imag',
cargo_project_path: toplevel_dir,
ruby_project_path: toplevel_dir)
2017-01-22 16:05:40 +00:00
module Imag
2017-01-22 15:39:57 +00:00
IMAG_INIT_FN_NAME = 'imag_ruby_initialize'
def self.setup binary_path
require binary_path
2017-01-22 15:39:57 +00:00
self.core_setup
2017-01-22 15:39:57 +00:00
self.classes_setup
end
module Logger
def self.init debug, verbose, color
2017-01-22 16:05:40 +00:00
RImag.init_logger debug, verbose, color
2017-01-22 15:39:57 +00:00
end
def self.trace msg
2017-01-22 16:05:40 +00:00
RImag.trace msg
2017-01-22 15:39:57 +00:00
end
def self.dbg msg
2017-01-22 16:05:40 +00:00
RImag.dbg msg
2017-01-22 15:39:57 +00:00
end
def self.debug msg
2017-01-22 16:05:40 +00:00
RImag.debug msg
2017-01-22 15:39:57 +00:00
end
def self.info msg
2017-01-22 16:05:40 +00:00
RImag.info msg
2017-01-22 15:39:57 +00:00
end
def self.warn msg
2017-01-22 16:05:40 +00:00
RImag.warn msg
2017-01-22 15:39:57 +00:00
end
def self.error msg
2017-01-22 16:05:40 +00:00
RImag.error msg
2017-01-22 15:39:57 +00:00
end
end
private
def self.class_names
[
:StoreId ,
:StoreHandle ,
:FileLockEntryHandle ,
:EntryHeader ,
:EntryContent ,
]
end
def self.core_setup
2017-01-22 15:39:57 +00:00
self.class_names.map {|n| [n, "R#{n}".to_sym ] }.each do |elem|
2017-01-22 16:05:40 +00:00
Imag.const_set elem.first, Kernel.const_get(elem.last)
2017-01-22 15:39:57 +00:00
end
end
def self.classes_setup
self.class_storeid_setup
end
def self.class_storeid_setup
2017-01-22 16:05:40 +00:00
Imag::StoreId.class_exec do
2017-01-22 15:39:57 +00:00
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
2017-01-22 16:05:40 +00:00
Imag.setup ARGV.first
2017-01-22 15:39:57 +00:00
rescue Exception => e
puts "Seems not to be the case... or something else went wrong..."
puts e
exit 1
end
2017-01-22 16:05:40 +00:00
Imag::Logger.init true, true, true
Imag::Logger.info "The Logger should work now"
2017-01-22 15:39:57 +00:00
2017-01-22 16:05:40 +00:00
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."
2017-01-22 15:39:57 +00:00
end