class Thermite::Rails::Project

A “project” is a crate that contains both Rust and Ruby code. Usually one of these will live at [rails root]/crates/.

Attributes

config[R]
project_path[R]

Public Class Methods

new(project_path) click to toggle source

@param project_path [String]

# File lib/thermite/rails/project.rb, line 24
def initialize(project_path)
  @project_path = find_project(project_path)
  @config = Thermite::Config.new(ruby_project_path: @project_path, cargo_project_path: @project_path)
end

Public Instance Methods

cargo_toml_path() click to toggle source

@return [String] Path to the project's Cargo.toml file.

# File lib/thermite/rails/project.rb, line 30
def cargo_toml_path
  File.join(@project_path, 'Cargo.toml')
end
crate_name() click to toggle source

@return [String] “package.name” from the crate's Cargo.toml file.

# File lib/thermite/rails/project.rb, line 49
def crate_name
  @crate_name ||= Tomlrb.load_file(cargo_toml_path)['package']['name']
end
ensure_built!() click to toggle source

Raise if the project is outdated.

# File lib/thermite/rails/project.rb, line 74
def ensure_built!
  raise OutdatedBuildError, crate_name if outdated_build?
end
gemspec_path() click to toggle source

@return [String] Path to the project's Cargo.toml file.

# File lib/thermite/rails/project.rb, line 35
def gemspec_path
  File.join(@project_path, "#{crate_name}.gemspec")
end
outdated_build?() click to toggle source

@return [Boolean] Has the crate been updated since it was last built?

# File lib/thermite/rails/project.rb, line 66
def outdated_build?
  mtime = Dir["#{@project_path}/src/**/*.rs"].map { |file| File.mtime(file) }.max
  native = "#{@project_path}/lib/#{@config.shared_library}"

  !File.exist?(native) || File.mtime(native) < mtime
end
rakefile_path() click to toggle source
# File lib/thermite/rails/project.rb, line 39
def rakefile_path
  File.join(@project_path, 'Rakefile')
end
spec_path() click to toggle source

@return [String] Path to `[project root]/spec/`.

# File lib/thermite/rails/project.rb, line 44
def spec_path
  File.join(@project_path, 'spec')
end
specs?() click to toggle source

@return [Boolean] Does this project have `[project root]/spec/`?

# File lib/thermite/rails/project.rb, line 54
def specs?
  File.exist?(spec_path)
end
thermite?() click to toggle source

@return [Boolean] Does this project use thermite?

# File lib/thermite/rails/project.rb, line 59
def thermite?
  return false unless File.exist?(gemspec_path)

  File.read(gemspec_path).include? 'thermite'
end

Private Instance Methods

find_project(project_path) click to toggle source

@param project_path [String]

# File lib/thermite/rails/project.rb, line 81
def find_project(project_path)
  Thermite::Rails.find_root(project_path) do |dir|
    File.exist?("#{dir}/Cargo.toml")
  end
end