Class: Fastlane::Helper::SyncDevicesHelper::DevicesPatch

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/sync_devices/helper/sync_devices_helper/devices_patch.rb

Overview

Represents a collection of DevicePatch.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(old_devices, new_devices) ⇒ DevicesPatch

Returns a new instance of DevicesPatch.

Parameters:

  • old_devices (Array<Spaceship::ConnectAPI::Device>)
  • new_devices (Array<Spaceship::ConnectAPI::Device>)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fastlane/plugin/sync_devices/helper/sync_devices_helper/devices_patch.rb', line 19

def initialize(old_devices, new_devices) # rubocop:disable Metrics/AbcSize
  @old_devices = old_devices
  @new_devices = new_devices

  old_device_by_udid = old_devices.group_by { |d| d.udid.downcase }.transform_values(&:first)
  new_device_by_udid = new_devices.group_by { |d| d.udid.downcase }.transform_values(&:first)
  @commands = (old_device_by_udid.keys + new_device_by_udid.keys)
              .sort
              .uniq
              .map do |udid|
    old_device = old_device_by_udid[udid]
    new_device = new_device_by_udid[udid]
    DevicePatch.new(old_device, new_device).command
  end
end

Instance Attribute Details

#commandsArray<DevicePatch> (readonly)

Returns:



15
16
17
# File 'lib/fastlane/plugin/sync_devices/helper/sync_devices_helper/devices_patch.rb', line 15

def commands
  @commands
end

#new_devicesSpaceship::ConnectAPI::Device (readonly)

Returns:

  • (Spaceship::ConnectAPI::Device)


13
14
15
# File 'lib/fastlane/plugin/sync_devices/helper/sync_devices_helper/devices_patch.rb', line 13

def new_devices
  @new_devices
end

#old_devicesSpaceship::ConnectAPI::Device (readonly)

Returns:

  • (Spaceship::ConnectAPI::Device)


13
14
15
# File 'lib/fastlane/plugin/sync_devices/helper/sync_devices_helper/devices_patch.rb', line 13

def old_devices
  @old_devices
end

Instance Method Details

#apply!(dry_run: false) ⇒ void

This method returns an undefined value.

Parameters:

  • dry_run (Boolean) (defaults to: false)


37
38
39
40
41
42
43
44
45
46
# File 'lib/fastlane/plugin/sync_devices/helper/sync_devices_helper/devices_patch.rb', line 37

def apply!(dry_run: false)
  @commands.each do |command|
    if dry_run
      UI.message("(dry-run) #{command.description}")
    else
      command.run
      UI.message(command.description)
    end
  end
end