Class: Fastlane::Actions::QrCodeAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



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

def self.authors
  ["Mathijs Bernson"]
end

.available_optionsObject



60
61
62
63
64
65
66
67
68
# File 'lib/fastlane/plugin/qr_code/actions/qr_code_action.rb', line 60

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



44
45
46
# File 'lib/fastlane/plugin/qr_code/actions/qr_code_action.rb', line 44

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

.detailsObject



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

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

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/fastlane/plugin/qr_code/actions/qr_code_action.rb', line 70

def self.is_supported?(platform)
  true
end

.return_valueObject



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

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

.run(params) ⇒ Object



15
16
17
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
# File 'lib/fastlane/plugin/qr_code/actions/qr_code_action.rb', line 15

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
  IO.binwrite(qr_code_png_path, qr_code_png.to_s)

  # 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