Class: Mod
Class Method Summary
collapse
Instance Method Summary
collapse
#associated_valid?, #no_errors_in_associated?, #save_associated, #save_associated!, #save_with_unsaved_flag, #to_label, #unsaved=, #unsaved?
Class Method Details
arma2 mod: works for all subclasses armaoa mod; works for arma2-oa-st, arma2-oa-
29
30
31
|
# File 'lib/six-updater-web/app/models/mod.rb', line 29
def self.label
Kernel.const_get(self.short+"Appsetting").label
end
|
.read_modfolders(setting) ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/six-updater-web/app/models/mod.rb', line 154
def self.read_modfolders(setting)
Dir.chdir setting.real_modpath.clone do
Dir["@*"].each do |dir|
next unless File.directory?(dir)
m = Mod.find(:first, :conditions => "name LIKE '#{dir}'")
unless m
m = Mod.new :name => dir
m.save
end
logger.debug "#{m.inspect}"
end
end
end
|
33
34
35
|
# File 'lib/six-updater-web/app/models/mod.rb', line 33
def self.short
self.to_s.sub("Mod", "")
end
|
37
38
39
40
41
42
43
44
45
|
# File 'lib/six-updater-web/app/models/mod.rb', line 37
def self.types
return [Arma2Mod] if self.class == Appsetting
e = self
unless e.nil? || [Mod, ActiveRecord::Base].include?(e)
types << e
e = e.class
end
types
end
|
Instance Method Details
#all_dependentmods(mods = []) ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/six-updater-web/app/models/mod.rb', line 16
def all_dependentmods(mods = [])
mods += [self]
self.mods.each do |mod|
next if mods.include?(mod)
mods += mod.all_dependentmods(mods)
mods << mod
end
mods.uniq
end
|
#all_repositories ⇒ Object
120
121
122
123
124
125
126
127
128
|
# File 'lib/six-updater-web/app/models/mod.rb', line 120
def all_repositories
if self.networks.empty?
Repository.find(:all)
else
repos = []
self.networks.each { |net| repos += net.repositories unless net.disabled }
repos
end
end
|
#exists?(setting) ⇒ Boolean
71
72
73
74
|
# File 'lib/six-updater-web/app/models/mod.rb', line 71
def exists?(setting)
return false unless setting.real_modpath && self.real_name
File.exists?(File.join(setting.real_modpath, self.real_name))
end
|
#installed? ⇒ Boolean
67
68
69
|
# File 'lib/six-updater-web/app/models/mod.rb', line 67
def installed?
self.version_local && !self.version_local.empty?
end
|
#read_version(path) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/six-updater-web/app/models/mod.rb', line 84
def read_version(path)
return unless path && self.real_name
cfg = File.join(path, self.real_name, '.rsync', '.repository.yml')
if File.exists?(cfg)
conf = YAML::load_file(cfg)
if conf
begin
conf[:version]
rescue
nil
end
else
nil
end
else
nil
end
end
|
#real_name ⇒ Object
57
58
59
60
61
62
63
64
65
|
# File 'lib/six-updater-web/app/models/mod.rb', line 57
def real_name
return unless self.name
case RUBY_PLATFORM
when /-mingw32$/, /-mswin32$/
self.name
else
self.name.downcase
end
end
|
#real_path(appsetting) ⇒ Object
112
113
114
115
116
117
118
|
# File 'lib/six-updater-web/app/models/mod.rb', line 112
def real_path(appsetting)
if self.path
self.path
else
appsetting.real_modpath
end
end
|
80
81
82
|
# File 'lib/six-updater-web/app/models/mod.rb', line 80
def rema
"mods/show"
end
|
76
77
78
|
# File 'lib/six-updater-web/app/models/mod.rb', line 76
def remote
end
|
#to_updater_yml ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/six-updater-web/app/models/mod.rb', line 134
def to_updater_yml
return unless self.real_name
hash = Hash.new
hash[:folder] = self.real_name
hash[:repository] = []
hash[:skip] = self.skip
hash[:disabled] = self.disabled
hash[:priority] = self.priority
name = self.real_name.clone
name.gsub!("@", '')
unless self.new_record?
self.all_repositories.each do |rep|
hash[:repository] << "#{rep.to_updater_yml}/rel/#{name.downcase}/." unless rep.disabled
end
end
hash
end
|
#update_skip ⇒ Object
130
131
132
|
# File 'lib/six-updater-web/app/models/mod.rb', line 130
def update_skip
self.skip = if self.new_record?; true ; else; ((self.version == self.version_local) && !self.version.nil?); end
end
|
#update_skip_by_version(path) ⇒ Object
107
108
109
110
|
# File 'lib/six-updater-web/app/models/mod.rb', line 107
def update_skip_by_version(path)
self.update_version(path)
self.update_skip
end
|
#update_version(path) ⇒ Object
103
104
105
|
# File 'lib/six-updater-web/app/models/mod.rb', line 103
def update_version(path)
self.version_local = self.read_version(path).to_s
end
|
#version_match?(setting) ⇒ Boolean
47
48
49
50
51
52
53
54
55
|
# File 'lib/six-updater-web/app/models/mod.rb', line 47
def version_match?(setting)
return nil if setting.nil?
self.type.nil? ? true : setting.found_types.map{|e| e.short }.include?(self.class.short)
end
|