Skip to content
This repository has been archived by the owner on Aug 2, 2019. It is now read-only.

Do not raise exception if eric binaries are not available #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/liberic/boot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand Down
17 changes: 13 additions & 4 deletions lib/liberic/sdk/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ 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_method(name) { |*options| true }
end
extend self

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to understand - why you need to extend self?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It defines an instance method in the receiver https://apidock.com/ruby/Module/define_method
Here we are using Module so the "extend self" keeps the instance methods public.

Anyway I changed this code. Now I will use define_singleton_method that doesn't require "extend self"

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(
Expand Down