Class: Fastlane::RamDisk::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/ram_disk/manager.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Manager

Returns a new instance of Manager.



21
22
23
24
# File 'lib/fastlane/plugin/ram_disk/manager.rb', line 21

def initialize(params)
  @params = params
  UI.user_error!('Sorry, it only works in macOS for now') unless mac?
end

Class Method Details

.run(params) ⇒ Object



14
15
16
17
18
19
# File 'lib/fastlane/plugin/ram_disk/manager.rb', line 14

def self.run(params)
  instance = new(params)
  instance.create
  params[:use].call
  instance.remove
end

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fastlane/plugin/ram_disk/manager.rb', line 26

def create
  name = @params[:name]
  path = @params[:mount_path]
  size = @params[:size]
  ram_disk_path = File.join(path, name)

  UI.user_error!('the name is empty') if name.to_s.empty?
  UI.user_error!('the disk size is zero or negative') if size.to_i <= 0
  UI.user_error!("mount path existed: #{ram_disk_path}") if File.exist?(ram_disk_path)

  commands = []
  commands << create_ram_disk(name, size)
  commands << spotlight_indexes(ram_disk_path, true)

  commands.each do |shell_command|
    if Helper.test?
      UI.message("$ #{shell_command}")
      next
    end

    Actions.sh(shell_command)
  end

  UI.crash! "fail to create ram disk" unless Dir.exist?(ram_disk_path)

  UI.success "Successful on ram disk: #{ram_disk_path}"
  shared_value(Actions::SharedValues::RAM_DISK_PATH, ram_disk_path)
end

#mac?Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
# File 'lib/fastlane/plugin/ram_disk/manager.rb', line 78

def mac?
  require 'rbconfig'

  platform = RbConfig::CONFIG['host_os']
  platform.include?('darwin')
end

#removeObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fastlane/plugin/ram_disk/manager.rb', line 55

def remove
  path = @params[:path]

  UI.user_error!('ram path is empty') if path.to_s.empty?
  UI.user_error!("ram path is not exist: #{path}") unless Dir.exist?(path)
  UI.message("Found ram disk: #{path}")

  commands = []
  commands << spotlight_indexes(path, false)
  commands << remove_ram_disk(path)

  commands.each do |shell_command|
    if Helper.test?
      UI.message("$ #{shell_command}")
      next
    end

    Actions.sh(shell_command)
  end

  UI.crash! "fail to remove ram disk" if Dir.exist?(path)
end