Class: Rpremote::PicoRubySourcePatch

Inherits:
Object
  • Object
show all
Defined in:
lib/rpremote/picoruby_source_patch.rb,
sig/rpremote.rbs

Defined Under Namespace

Classes: Error

Constant Summary collapse

JOB_PATH =

Returns:

  • (String)
"mrbgems/picoruby-shell/mrblib/job.rb"
BOOTSEL_PATH =
"mrbgems/picoruby-machine/include/machine.h"
PATCH_ALIASES =

Returns:

  • (Hash[String, String])
{ "3.4.2" => "3.4.5" }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version:) ⇒ PicoRubySourcePatch

Returns a new instance of PicoRubySourcePatch.

Parameters:

  • version: (String)


13
14
15
# File 'lib/rpremote/picoruby_source_patch.rb', line 13

def initialize(version:)
  @version = version
end

Instance Attribute Details

#versionString (readonly)

Returns the value of attribute version.

Returns:

  • (String)


11
12
13
# File 'lib/rpremote/picoruby_source_patch.rb', line 11

def version
  @version
end

Instance Method Details

#apply(source) ⇒ void

This method returns an undefined value.

Parameters:

  • source (String)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rpremote/picoruby_source_patch.rb', line 17

def apply(source)
  return unless Dir.exist?(source)

  patch_version = PATCH_ALIASES.fetch(version, version)
  patches(patch_version).each do |patch, prerequisite|
    next unless File.file?(patch) && File.file?(File.join(source, prerequisite))
    next if prerequisite == BOOTSEL_PATH && File.read(File.join(source, prerequisite)).include?("Machine_bootsel")

    next if git_apply?(source, patch, "--reverse", "--check")

    raise Error, "cannot apply rpremote patch to PicoRuby #{version}" unless git_apply?(source, patch, "--check")
    raise Error, "cannot apply rpremote patch to PicoRuby #{version}" unless git_apply?(source, patch)
  end
  nil
end