lib/envkey/platform.rb in envkey-0.1.5 vs lib/envkey/platform.rb in envkey-1.0.0

- old
+ new

@@ -1,34 +1,55 @@ module Envkey::Platform + # Normalize the platform OS + OS = case os = RbConfig::CONFIG['host_os'].downcase + when /linux/ + "linux" + when /darwin/ + "darwin" + when /bsd/ + "freebsd" + when /mingw|mswin/ + "windows" + else + "linux" + end - def self.lib_paths - lib_filenames.map do |fn| - File.expand_path("../../ext/#{fn}", File.dirname(__FILE__)) - end + # Normalize the platform CPU + ARCH = case cpu = RbConfig::CONFIG['host_cpu'].downcase + when /amd64|x86_64/ + "x86_64" + when /i?86|x86|i86pc/ + "x86" + when /ppc|powerpc/ + "powerpc" + when /^arm/ + "arm" + else + cpu end - def self.lib_filenames - is_unix, os, arch, extension = [FFI::Platform.unix?, FFI::Platform::OS, FFI::Platform::ARCH, FFI::Platform::LIBSUFFIX] - - platform_parts = - if !is_unix - raise "Envkey currently only supports unix and OSX platforms" - elsif os == "darwin" - if arch == "x86_64" - ["darwin-10.6-amd64"] - else - ["darwin-10.6-386"] - end + def self.platform_part + case OS + when "darwin", "linux", "windows", "freebsd" + OS else - if arch == "x86_64" - ["linux-amd64", "linux-arm64"] - elsif arch == "i386" - ["linux-386"] - else - %w(arm64 arm-7 arm-6 arm-5).map {|s| "linux-#{s}"} - end + "linux" end + end - platform_parts.map {|part| "envkey-#{part}.#{extension}"} + def self.arch_part + ARCH == "x86_64" ? "amd64" : "386" + end + + def self.ext + platform_part == "windows" ? ".exe" : "" + end + + def self.fetch_env_path + File.expand_path("../../ext/#{lib_file_dir}/envkey-fetch#{ext}", File.dirname(__FILE__)) + end + + def self.lib_file_dir + ["envkey-fetch", Envkey::ENVKEY_FETCH_VERSION.to_s, platform_part, arch_part].join("_") end end \ No newline at end of file