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



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

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



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

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)


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

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



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

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

  paths.each { |path| require path }
end

.safe_constantize(name) ⇒ Object



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

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
# File 'lib/lutaml/model/runtime_compatibility.rb', line 12

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