Class: Fastlane::Actions::QrCodeAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/qr_code/actions/qr_code_action.rb

Constant Summary collapse

@@temp_files =

Hold references to the temporary files, so that they aren’t garbage collected (and deleted) before the Fastlane workflow is finished.

[]

Class Method Summary collapse

Class Method Details

.authorsObject



51
52
53
# File 'lib/fastlane/plugin/qr_code/actions/qr_code_action.rb', line 51

def self.authors
  ["Mathijs Bernson"]
end

.available_optionsObject



63
64
65
66
67
68
69
70
71
# File 'lib/fastlane/plugin/qr_code/actions/qr_code_action.rb', line 63

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :contents,
                            env_name: "QR_CODE_CONTENTS",
                         description: "The contents of the QR code",
                            optional: false,
                                type: String)
  ]
end

.descriptionObject



47
48
49
# File 'lib/fastlane/plugin/qr_code/actions/qr_code_action.rb', line 47

def self.description
  "Generates QR codes that you may use in the rest of your workflow."
end

.detailsObject



59
60
61
# File 'lib/fastlane/plugin/qr_code/actions/qr_code_action.rb', line 59

def self.details
  "The QR code PNG image is written to the system's temporary directory."
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/fastlane/plugin/qr_code/actions/qr_code_action.rb', line 73

def self.is_supported?(platform)
  true
end

.return_valueObject



55
56
57
# File 'lib/fastlane/plugin/qr_code/actions/qr_code_action.rb', line 55

def self.return_value
  "Returns the path to the QR code PNG file."
end

.run(params) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fastlane/plugin/qr_code/actions/qr_code_action.rb', line 18

def self.run(params)
  qr_code_contents = params[:contents].to_s
  UI.user_error!("No QR code contents given, pass using `contents: 'http://example.com/123'`") unless qr_code_contents.length > 0

  qr_code = RQRCode::QRCode.new(qr_code_contents)
  qr_code_text = qr_code.as_ansi
  qr_code_png = qr_code.as_png(size: 240)

  temp_file = Tempfile.new('qrcode')
  temp_file.write(qr_code_png.to_s)
  qr_code_png_path = temp_file.path
  temp_file.close
  @@temp_files.append(temp_file)

  # Setting action and environment variables
  Actions.lane_context[SharedValues::QR_CODE_PNG_PATH] = qr_code_png_path
  ENV[SharedValues::QR_CODE_PNG_PATH.to_s] = qr_code_png_path

  Actions.lane_context[SharedValues::QR_CODE_TEXT] = qr_code_text
  ENV[SharedValues::QR_CODE_TEXT.to_s] = qr_code_text

  UI.success("Successfully created QR code at path '#{Actions.lane_context[SharedValues::QR_CODE_PNG_PATH]}'")

  {
    'QR_CODE_TEXT' => qr_code_text,
    'QR_CODE_PNG_PATH' => qr_code_png_path
  }
end