diff --git a/lib/liberic/boot.rb b/lib/liberic/boot.rb index 47c70cb..9d73d19 100644 --- a/lib/liberic/boot.rb +++ b/lib/liberic/boot.rb @@ -8,6 +8,10 @@ def eric_home ERIC_HOME end + def binaries_unavailable? + ENV['ERIC_HOME_27'].to_s.empty? + end + def library_path suffix = if RUBY_PLATFORM =~ /linux/ 'so' @@ -19,10 +23,12 @@ def library_path File.expand_path("libericapi.#{suffix}", ERIC_LIB_FOLDER) end - ERIC_HOME = ENV['ERIC_HOME_27'] || raise(InitializationError.new('ERIC_HOME_27 environment variable not found (set it to the path to the ERiC libraries)')) + ERIC_HOME = ENV['ERIC_HOME_27'] || warn(InitializationError.new('ERIC_HOME_27 environment variable not found (set it to the path to the ERiC libraries)')) ERIC_LIB_FOLDER = File.expand_path('lib', ERIC_HOME) def check_eric_version! + return true if binaries_unavailable? + version_response = Response::Version.new( Helpers::Invocation.with_result_buffer do |handle| SDK::API::version(handle) diff --git a/lib/liberic/sdk/api.rb b/lib/liberic/sdk/api.rb index 290a488..6633447 100644 --- a/lib/liberic/sdk/api.rb +++ b/lib/liberic/sdk/api.rb @@ -2,11 +2,19 @@ module Liberic module SDK module API extend FFI::Library - ffi_lib Liberic.library_path - def self.attach_eric_function(name, params, return_type, original_name = nil) - original_name ||= 'Eric' + name.to_s.capitalize.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" } - attach_function(name, original_name, params, return_type) + if Liberic.binaries_unavailable? + # define fake functions to allow tests pass + def self.attach_eric_function(name, params, return_type, original_name = nil) + define_singleton_method(name) { |*options| true } + end + else + ffi_lib Liberic.library_path + + def self.attach_eric_function(name, params, return_type, original_name = nil) + original_name ||= 'Eric' + name.to_s.capitalize.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" } + attach_function(name, original_name, params, return_type) + end end # ERICAPI_DECL int STDCALL EricBearbeiteVorgang(