Class: Thermite::Config
- Inherits:
-
Object
- Object
- Thermite::Config
- Defined in:
- lib/thermite/config.rb
Overview
Configuration helper
Constant Summary collapse
- DEFAULT_TAG_REGEX =
The basic semantic versioning format.
/^(v\d+\.\d+\.\d+)$/
Instance Method Summary collapse
-
#binary_uri_format ⇒ Object
The interpolation-formatted string used to construct the download URI for the pre-built native extension.
-
#crate_version ⇒ Object
Alias to the crate version specified in the TOML file.
-
#debug_filename ⇒ Object
Location to emit debug output, if not
nil. -
#git_tag_regex ⇒ Object
The format (as a regular expression) that git tags containing Rust binary tarballs are supposed to match.
-
#initialize(options = {}) ⇒ Config
constructor
Creates a new configuration object.
-
#library_name ⇒ Object
The name of the library compiled by Rust.
-
#ruby_extension_path ⇒ Object
Path to the Rust shared library in the context of the Ruby project.
-
#ruby_path(*path_components) ⇒ Object
Generate a path relative to
ruby_toplevel_dir, given thepath_componentsthat are passed toFile.join. -
#ruby_toplevel_dir ⇒ Object
The top-level directory of the Ruby project.
-
#ruby_version ⇒ Object
The major and minor version of the Ruby interpreter that's currently running.
-
#rust_path(*path_components) ⇒ Object
Generate a path relative to
rust_toplevel_dir, given thepath_componentsthat are passed toFile.join. -
#rust_toplevel_dir ⇒ Object
The top-level directory of the Cargo project.
-
#shared_ext ⇒ Object
The file extension of the compiled shared Rust library.
-
#shared_library ⇒ Object
The basename of the Rust shared library.
-
#tarball_filename(version) ⇒ Object
Return the basename of the tarball generated by the
thermite:tarballRake task, given a packageversion. -
#target_arch ⇒ Object
Alias for
RbConfig::CONFIG['target_cpu']. -
#target_os ⇒ Object
Alias for
RbConfig::CONFIG['target_os']. -
#toml ⇒ Object
Parsed TOML object (courtesy of
tomlrb). -
#toml_config ⇒ Object
The Thermite-specific config from the TOML file.
Constructor Details
#initialize(options = {}) ⇒ Config
Creates a new configuration object.
options is the same as the Thermite::Tasks.new parameter.
35 36 37 |
# File 'lib/thermite/config.rb', line 35 def initialize( = {}) @options = end |
Instance Method Details
#binary_uri_format ⇒ Object
The interpolation-formatted string used to construct the download URI for the pre-built
native extension. Can be set via the THERMITE_BINARY_URI_FORMAT environment variable, or a
binary_uri_format option.
66 67 68 69 70 |
# File 'lib/thermite/config.rb', line 66 def binary_uri_format @binary_uri_format ||= ENV['THERMITE_BINARY_URI_FORMAT'] || @options[:binary_uri_format] || false end |
#crate_version ⇒ Object
Alias to the crate version specified in the TOML file.
196 197 198 |
# File 'lib/thermite/config.rb', line 196 def crate_version toml[:package][:version] end |
#debug_filename ⇒ Object
Location to emit debug output, if not nil. Defaults to nil.
42 43 44 |
# File 'lib/thermite/config.rb', line 42 def debug_filename @debug_filename ||= ENV['THERMITE_DEBUG_FILENAME'] end |
#git_tag_regex ⇒ Object
The format (as a regular expression) that git tags containing Rust binary
tarballs are supposed to match. Defaults to DEFAULT_TAG_FORMAT.
176 177 178 179 180 181 182 183 184 |
# File 'lib/thermite/config.rb', line 176 def git_tag_regex @git_tag_regex ||= begin if @options[:git_tag_regex] Regexp.new(@options[:git_tag_regex]) else DEFAULT_TAG_REGEX end end end |
#library_name ⇒ Object
The name of the library compiled by Rust.
Due to the way that Cargo works, all hyphens in library names are replaced with underscores.
104 105 106 107 108 109 |
# File 'lib/thermite/config.rb', line 104 def library_name @library_name ||= begin base = toml[:lib] && toml[:lib][:name] ? toml[:lib] : toml[:package] base[:name].tr('-', '_') if base[:name] end end |
#ruby_extension_path ⇒ Object
Path to the Rust shared library in the context of the Ruby project.
163 164 165 |
# File 'lib/thermite/config.rb', line 163 def ruby_extension_path ruby_path('lib', shared_library) end |
#ruby_path(*path_components) ⇒ Object
Generate a path relative to ruby_toplevel_dir, given the path_components that are passed
to File.join.
141 142 143 |
# File 'lib/thermite/config.rb', line 141 def ruby_path(*path_components) File.join(ruby_toplevel_dir, *path_components) end |
#ruby_toplevel_dir ⇒ Object
The top-level directory of the Ruby project. Defaults to the current working directory.
133 134 135 |
# File 'lib/thermite/config.rb', line 133 def ruby_toplevel_dir @ruby_toplevel_dir ||= @options.fetch(:ruby_project_path, FileUtils.pwd) end |
#ruby_version ⇒ Object
The major and minor version of the Ruby interpreter that's currently running.
75 76 77 78 79 80 |
# File 'lib/thermite/config.rb', line 75 def ruby_version @ruby_version ||= begin version_info = rbconfig_ruby_version.split('.') "ruby#{version_info[0]}#{version_info[1]}" end end |
#rust_path(*path_components) ⇒ Object
Generate a path relative to rust_toplevel_dir, given the path_components that are
passed to File.join.
156 157 158 |
# File 'lib/thermite/config.rb', line 156 def rust_path(*path_components) File.join(rust_toplevel_dir, *path_components) end |
#rust_toplevel_dir ⇒ Object
The top-level directory of the Cargo project. Defaults to the current working directory.
148 149 150 |
# File 'lib/thermite/config.rb', line 148 def rust_toplevel_dir @rust_toplevel_dir ||= @options.fetch(:cargo_project_path, FileUtils.pwd) end |
#shared_ext ⇒ Object
The file extension of the compiled shared Rust library.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/thermite/config.rb', line 49 def shared_ext @shared_ext ||= begin if dlext == 'bundle' 'dylib' elsif Gem.win_platform? 'dll' else dlext end end end |
#shared_library ⇒ Object
The basename of the Rust shared library.
114 115 116 117 118 119 120 |
# File 'lib/thermite/config.rb', line 114 def shared_library @shared_library ||= begin filename = "#{library_name}.#{shared_ext}" filename = "lib#{filename}" unless Gem.win_platform? filename end end |
#tarball_filename(version) ⇒ Object
Return the basename of the tarball generated by the thermite:tarball Rake task, given a
package version.
126 127 128 |
# File 'lib/thermite/config.rb', line 126 def tarball_filename(version) "#{library_name}-#{version}-#{ruby_version}-#{target_os}-#{target_arch}.tar.gz" end |
#target_arch ⇒ Object
Alias for RbConfig::CONFIG['target_cpu'].
87 88 89 |
# File 'lib/thermite/config.rb', line 87 def target_arch @target_arch ||= RbConfig::CONFIG['target_cpu'] end |
#target_os ⇒ Object
Alias for RbConfig::CONFIG['target_os'].
94 95 96 |
# File 'lib/thermite/config.rb', line 94 def target_os @target_os ||= RbConfig::CONFIG['target_os'] end |
#toml ⇒ Object
Parsed TOML object (courtesy of tomlrb).
189 190 191 |
# File 'lib/thermite/config.rb', line 189 def toml @toml ||= Tomlrb.load_file(rust_path('Cargo.toml'), symbolize_keys: true) end |
#toml_config ⇒ Object
The Thermite-specific config from the TOML file.
203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/thermite/config.rb', line 203 def toml_config @toml_config ||= begin # Not using .dig to be Ruby < 2.3 compatible if toml && toml[:package] && toml[:package][:metadata] && toml[:package][:metadata][:thermite] toml[:package][:metadata][:thermite] else {} end end end |