Module: Lutaml::Model::RuntimeCompatibility

Defined in:
lib/lutaml/model/runtime_compatibility.rb

Class Method Summary collapse

Class Method Details

.autoload_native(namespace, constant_paths) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/lutaml/model/runtime_compatibility.rb', line 22

def self.autoload_native(namespace, constant_paths)
  return unless native?

  constant_paths.each do |constant_name, path|
    namespace.autoload(constant_name, path)
  end
end

.define_native_aliases(namespace, constant_targets) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/lutaml/model/runtime_compatibility.rb', line 36

def self.define_native_aliases(namespace, constant_targets)
  return unless native?

  constant_targets.each do |constant_name, target_name|
    namespace.const_set(constant_name, constantize(target_name))
  end
end

.native?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/lutaml/model/runtime_compatibility.rb', line 18

def self.native?
  !opal?
end

.opal?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
# File 'lib/lutaml/model/runtime_compatibility.rb', line 6

def self.opal?
  return @opal if defined?(@opal)

  @opal = RUBY_ENGINE == "opal"
end

.require_native(*paths) ⇒ Object



30
31
32
33
34
# File 'lib/lutaml/model/runtime_compatibility.rb', line 30

def self.require_native(*paths)
  return unless native?

  paths.each { |path| require path }
end

.safe_constantize(name) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/lutaml/model/runtime_compatibility.rb', line 44

def self.safe_constantize(name)
  parts = constant_parts(name)
  return nil if parts.empty?
  return nil unless Object.const_defined?(parts.first)

  parts.inject(Object) do |mod, part|
    mod.const_get(part)
  end
rescue NameError
  nil
end

.windows?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/lutaml/model/runtime_compatibility.rb', line 12

def self.windows?
  defined?(Gem) &&
    Gem.respond_to?(:win_platform?) &&
    Gem.win_platform?
end