Sha256: eb4ea281618b4f90a52df92f0adfe8deda4c377b64c1987274983f17290cb531

Contents?: true

Size: 1.68 KB

Versions: 14

Compression:

Stored size: 1.68 KB

Contents

module SimCtl
  class Command
    module List
      COMMAND = %w[xcrun simctl list -j]

      # Find a device
      #
      # @param filter [Hash] the filter
      # @return [SimCtl::Device, nil] the device matching the given filter
      def device(filter)
        list_devices.where(filter).first
      end

      # Find a device type
      #
      # @param filter [Hash] the filter
      # @return [SimCtl::DeviceType, nil] the device type matching the given filter
      def devicetype(filter)
        list_devicetypes.where(filter).first
      end

      # List all devices
      #
      # @return [SimCtl::List] a list of SimCtl::Device objects
      def list_devices
        Executor.execute([COMMAND, 'devices']) do |json|
          SimCtl::List.new(json['devices'].map {|os, devices| devices.map {|device| Device.new(device.merge(os: os))}}.flatten)
        end
      end

      # List all device types
      #
      # @return [SimCtl::List] a list of SimCtl::DeviceType objects
      def list_devicetypes
        Executor.execute([COMMAND, 'devicetypes']) do |json|
          SimCtl::List.new(json['devicetypes'].map {|devicetype| DeviceType.new(devicetype)})
        end
      end

      # List all runtimes
      #
      # @return [SimCtl::List] a list of SimCtl::Runtime objects
      def list_runtimes
        Executor.execute([COMMAND, 'runtimes']) do |json|
          SimCtl::List.new(json['runtimes'].map {|runtime| Runtime.new(runtime)})
        end
      end

      # Find a runtime
      #
      # @param filter [Hash] the filter
      # @return [SimCtl::Runtime, nil] the runtime matching the given filter
      def runtime(filter)
        list_runtimes.where(filter).first
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
simctl-1.4.1 lib/simctl/command/list.rb
simctl-1.4.0 lib/simctl/command/list.rb
simctl-1.3.1 lib/simctl/command/list.rb
simctl-1.3.0 lib/simctl/command/list.rb
simctl-1.2.3 lib/simctl/command/list.rb
simctl-1.2.2 lib/simctl/command/list.rb
simctl-1.2.1 lib/simctl/command/list.rb
simctl-1.2.0 lib/simctl/command/list.rb
simctl-1.1.0 lib/simctl/command/list.rb
simctl-1.0.2 lib/simctl/command/list.rb
simctl-1.0.1 lib/simctl/command/list.rb
simctl-1.0.0 lib/simctl/command/list.rb
simctl-0.2.0 lib/simctl/command/list.rb
simctl-0.1.0 lib/simctl/command/list.rb