Class: Rpremote::Target

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

Constant Summary collapse

DEFAULT_LANGUAGE =

Returns:

  • (String)
"picoruby"
DEFAULT_LANGUAGE_VERSION =

Returns:

  • (String)
"4.0.3"
DEFAULT_BOARD =

Returns:

  • (String)
"pico2"
DEFAULT_CACHE_DIR =

Returns:

  • (String)
"firmware"
IDENTIFIER_PATTERN =

Returns:

  • (Regexp)
/\A[a-zA-Z0-9][a-zA-Z0-9._-]*\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language: DEFAULT_LANGUAGE, language_version: DEFAULT_LANGUAGE_VERSION, board: DEFAULT_BOARD, cache_dir: DEFAULT_CACHE_DIR, firmware: nil) ⇒ Target

Returns a new instance of Target.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rpremote/target.rb', line 13

def initialize(
  language: DEFAULT_LANGUAGE,
  language_version: DEFAULT_LANGUAGE_VERSION,
  board: DEFAULT_BOARD,
  cache_dir: DEFAULT_CACHE_DIR,
  firmware: nil
)
  @language = validate_identifier(:language, language)
  @language_version = validate_identifier(:language_version, language_version)
  @board = validate_identifier(:board, board)
  @cache_dir = String(cache_dir).gsub("{version}", @language_version)
  @firmware = firmware
  raise ArgumentError, "cache must not be empty" if @cache_dir.empty?
end

Instance Attribute Details

#boardString (readonly)

Returns the value of attribute board.

Returns:

  • (String)


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

def board
  @board
end

#cache_dirString (readonly)

Returns the value of attribute cache_dir.

Returns:

  • (String)


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

def cache_dir
  @cache_dir
end

#languageString (readonly)

Returns the value of attribute language.

Returns:

  • (String)


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

def language
  @language
end

#language_versionString (readonly)

Returns the value of attribute language_version.

Returns:

  • (String)


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

def language_version
  @language_version
end

Instance Method Details

#firmware_path(root: nil) ⇒ String

Parameters:

  • root: (String, nil) (defaults to: nil)

Returns:

  • (String)


32
33
34
35
# File 'lib/rpremote/target.rb', line 32

def firmware_path(root: nil)
  path = @firmware || File.join(cache_dir, "#{language}-#{language_version}-#{board}.uf2")
  root ? File.expand_path(path, root) : path
end

#source_dir(root: Dir.pwd) ⇒ String

Parameters:

  • root: (String) (defaults to: Dir.pwd)

Returns:

  • (String)


28
29
30
# File 'lib/rpremote/target.rb', line 28

def source_dir(root: Dir.pwd)
  File.expand_path(File.join(cache_dir, "#{language}-#{language_version}"), root)
end