Class: Device::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/device/application.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, remote, type, crc) ⇒ Application

Returns a new instance of Application.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/device/application.rb', line 23

def initialize(label, remote, type, crc)
  @type     = type
  @crc      = crc
  @original = remote
  @order, @label = split_label(label)
  company    = check_company(remote)
  @remote    = remote.sub("#{company}_", "")
  @name      = remote.sub("#{company}_", "").split(".")[0]
  @file      = check_path(@remote)
  @crc_local = @crc if File.exists?(@file)
end

Instance Attribute Details

#crcObject

Returns the value of attribute crc.



11
12
13
# File 'lib/device/application.rb', line 11

def crc
  @crc
end

#crc_localObject (readonly)

Returns the value of attribute crc_local.



12
13
14
# File 'lib/device/application.rb', line 12

def crc_local
  @crc_local
end

#fileObject (readonly)

Returns the value of attribute file.



12
13
14
# File 'lib/device/application.rb', line 12

def file
  @file
end

#labelObject (readonly)

Returns the value of attribute label.



12
13
14
# File 'lib/device/application.rb', line 12

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/device/application.rb', line 12

def name
  @name
end

#orderObject (readonly)

Returns the value of attribute order.



12
13
14
# File 'lib/device/application.rb', line 12

def order
  @order
end

#originalObject (readonly)

Returns the value of attribute original.



12
13
14
# File 'lib/device/application.rb', line 12

def original
  @original
end

#remoteObject (readonly)

Returns the value of attribute remote.



12
13
14
# File 'lib/device/application.rb', line 12

def remote
  @remote
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/device/application.rb', line 12

def type
  @type
end

Class Method Details

.delete(collection) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/device/application.rb', line 14

def self.delete(collection)
  collection.each do |app|
    begin
      app.delete
    rescue RuntimeError
    end
  end
end

Instance Method Details

#deleteObject



61
62
63
64
65
66
# File 'lib/device/application.rb', line 61

def delete
  File.delete(self.file) if exists?
  if self.ruby? && Dir.exist?(self.dir) && self.dir != "main"
    Dir.delete(self.dir)
  end
end

#dirObject



53
54
55
# File 'lib/device/application.rb', line 53

def dir
  @name
end

#download(force = false) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/device/application.rb', line 35

def download(force = false)
  if force || self.outdated?
    ret = Device::Transaction::Download.request_file(remote, file, crc_local)
  else
    ret = Device::Transaction::Download::FILE_NOT_CHANGE
  end
  if ret == Device::Transaction::Download::SUCCESS
    @crc_local = calculate_crc
    if @crc_local != @crc
      return Device::Transaction::Download::COMMUNICATION_ERROR
    end
  end
  ret
rescue => e
  puts "ERROR #{e.message}"
  Device::Transaction::Download::IO_ERROR
end

#execute(json = "") ⇒ Object



76
77
78
79
80
81
82
# File 'lib/device/application.rb', line 76

def execute(json = "")
  if posxml?
    PosxmlInterpreter.new(remote, nil, false).start
  else
    Device::Runtime.execute(name, json)
  end
end

#exists?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/device/application.rb', line 57

def exists?
  File.exists? file
end

#outdated?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# File 'lib/device/application.rb', line 68

def outdated?
  return true unless File.exists?(file)
  @crc_local = calculate_crc unless @crc_local
  @crc_local != @crc
rescue
  true
end

#posxml?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/device/application.rb', line 84

def posxml?
  @type == "posxml" || remote.include?(".posxml")
end

#ruby?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/device/application.rb', line 88

def ruby?
  @type == "ruby" || (! remote.include? ".posxml")
end