Class: Fastlane::Helper::SyncDevicesHelper::DevicePatch

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

Overview

Represents differences between 2 devices.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(old_device, new_device) ⇒ DevicePatch

Returns a new instance of DevicePatch.

Parameters:

  • old_device (Spaceship::ConnectAPI::Device, nil)
  • new_device (Spaceship::ConnectAPI::Device, nil)


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

def initialize(old_device, new_device)
  @old_device = old_device
  @new_device = new_device
end

Instance Attribute Details

#new_deviceSpaceship::ConnectAPI::Device (readonly)

Returns:

  • (Spaceship::ConnectAPI::Device)


11
12
13
# File 'lib/fastlane/plugin/sync_devices/helper/sync_devices_helper/device_patch.rb', line 11

def new_device
  @new_device
end

#old_deviceSpaceship::ConnectAPI::Device (readonly)

Returns:

  • (Spaceship::ConnectAPI::Device)


11
12
13
# File 'lib/fastlane/plugin/sync_devices/helper/sync_devices_helper/device_patch.rb', line 11

def old_device
  @old_device
end

Instance Method Details

#commandCommand::Base

Returns:

Raises:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fastlane/plugin/sync_devices/helper/sync_devices_helper/device_patch.rb', line 47

def command # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
  raise UnsupportedOperation.change_platform(old_device, new_device) if platform_changed?

  case [renamed?, enabled?, disabled?, created?]
  when [false, false, false, false]
    Command::Noop.new(old_device)
  when [false, false, false, true]
    Command::Create.new(new_device)
  when [false, false, true, false]
    Command::Disable.new(old_device)
  when [false, true, false, false]
    Command::Enable.new(old_device)
  when [true, false, false, false]
    Command::Rename.new(old_device, new_device.name)
  when [true, false, true, false]
    Command::DisableAndRename.new(old_device, new_device.name)
  when [true, true, false, false]
    Command::EnableAndRename.new(old_device, new_device.name)
  else
    # :nocov:
    raise UnsupportedOperation.internal_inconsistency(self, old_device, new_device)
    # :nocov:
  end
end

#created?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/fastlane/plugin/sync_devices/helper/sync_devices_helper/device_patch.rb', line 36

def created?
  old_device.nil? && !!new_device&.enabled?
end

#disabled?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/fastlane/plugin/sync_devices/helper/sync_devices_helper/device_patch.rb', line 31

def disabled?
  !!old_device && old_device.enabled? && !new_device&.enabled?
end

#enabled?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/fastlane/plugin/sync_devices/helper/sync_devices_helper/device_patch.rb', line 26

def enabled?
  !!old_device && !old_device.enabled? && !!new_device&.enabled?
end

#platform_changed?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/fastlane/plugin/sync_devices/helper/sync_devices_helper/device_patch.rb', line 41

def platform_changed?
  !!old_device && !!new_device && old_device.platform != new_device.platform
end

#renamed?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/fastlane/plugin/sync_devices/helper/sync_devices_helper/device_patch.rb', line 21

def renamed?
  !!old_device && !!new_device && old_device.name != new_device.name
end