class Thermite::Rails::CrateGenerator

Public Instance Methods

add_crate_ext_rakefile() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 67
      def add_crate_ext_rakefile
        rakefile_path = File.join(ext_full_path, 'Rakefile')

        create_file(rakefile_path) do
          <<~THERM
            require 'thermite/tasks'

            project_dir = File.dirname(File.dirname(__FILE__))
            Thermite::Tasks.new(cargo_project_path: project_dir, ruby_project_path: project_dir)
            task default: %w(thermite:build)
          THERM
        end
      end
add_ext_directory() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 63
def add_ext_directory
  empty_directory(ext_full_path)
end
add_thermite_to_gemspec() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 56
def add_thermite_to_gemspec
  insert_into_file(project.gemspec_path, after: %(  spec.require_paths = ["lib"])) do
    lines = %(\n  spec.extensions << 'ext/Rakefile'\n\n)
    lines + %(  spec.add_runtime_dependency 'thermite', '~> 0')
  end
end
bundle_install() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 95
def bundle_install
  run 'bundle'
end
crates_full_path() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 23
def crates_full_path
  @crates_full_path ||= ::Rails.root.join('crates').to_s
end
ext_full_path() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 35
def ext_full_path
  @ext_full_path ||= File.join(project_full_path, 'ext')
end
fix_rubocops() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 87
def fix_rubocops
  run "bundle exec rubocop -a #{project_full_path}" if File.read('Gemfile').include?('rubocop')
end
make_crates_dir() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 39
def make_crates_dir
  empty_directory(crates_full_path)
end
project() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 31
def project
  @project ||= Thermite::Rails::Project.new(project_full_path)
end
project_full_path() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 27
def project_full_path
  @project_full_path ||= File.join(crates_full_path, name)
end
run_crate_new_and_bundle_gem() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 43
def run_crate_new_and_bundle_gem
  inside(crates_full_path, verbose: true) do
    run "#{CargoRunner.instance.cargo} new #{name}"
    run "bundle gem #{name}"
  end
end
start() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 19
def start
  say "Creating crate '#{name}'..."
end
update_cargo_toml() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 50
def update_cargo_toml
  gsub_file(project.cargo_toml_path, "\n[dependencies]") do
    %(publish = false\n\n[lib]\ncrate-type = ["cdylib"]\n\n[dependencies])
  end
end
update_crate_rakefile() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 81
def update_crate_rakefile
  append_to_file(project.rakefile_path) do
    %(\nrequire 'thermite/tasks'\n\nThermite::Tasks.new)
  end
end
update_rails_gemfile() click to toggle source
# File lib/thermite/rails/generators/crate_generator.rb, line 91
def update_rails_gemfile
  gem name, path: "crates/#{name}"
end