Class: Application
Defined Under Namespace
Classes: ApplicationParams
Constant Summary
Configurable::ADD_SYMBOL, Configurable::FONT_TYPE_SYMBOL, Configurable::LC_SYMBOL, Configurable::LINK_SYMBOL
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from EventBus
attach_listener, attach_listeners_listener, broadcast_event, detach_listener, detach_listeners_listener, process_event
#append_persistent_property, #override_persistent
clear_properties_group_cache, #hash2properties_file, #make_locale_value, #make_value, #properties_file2hash, properties_group, #resolve_locale_value, #resolve_properties_link, #resolve_value
Constructor Details
#initialize(_ap = ApplicationParams.new) {|_self| ... } ⇒ Application
Returns a new instance of Application.
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
|
# File 'lib/a-commons.rb', line 1140
def initialize(_ap=ApplicationParams.new)
@@instance = self
eval('$'+_ap.name+'=self') publish('applicationParams', _ap)
publish(_ap.name,self)
@first_run = false
self['applicationParams'].persistent_file = File.join(local_dir, self['applicationParams'].name+'.pers')
if !File.exists?(self['applicationParams'].persistent_file)
File.new(self['applicationParams'].persistent_file, File::CREAT).close
end
publish('conf', properties_file2hash(self['applicationParams'].config_file)) if self['applicationParams'].config_file
publish('origin_conf', Hash.new.update(self['conf'])) if self['conf']
publish('local_conf', Hash.new)
publish('conf_without_local', Hash.new.update(self['conf'])) if self['conf']
publish('pers', properties_file2hash(self['applicationParams'].persistent_file)) if self['applicationParams'].persistent_file
yield(self) if block_given?
end
|
Class Method Details
.array_conf(_name, _array) ⇒ Object
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
|
# File 'lib/a-commons.rb', line 1224
def Application.array_conf(_name, _array)
value = ''
_array.each{|e|
if value.length > 0
value = "#{value},#{e}"
else
value = "#{e}"
end
}
@@instance['conf'][_name]=value
value
end
|
.conf(_property, _value = nil) ⇒ Object
1163
1164
1165
|
# File 'lib/a-commons.rb', line 1163
def Application.conf(_property, _value=nil)
@@instance.conf(_property, _value) if @@instance
end
|
.conf_array(_name) ⇒ Object
1217
1218
1219
1220
1221
1222
|
# File 'lib/a-commons.rb', line 1217
def Application.conf_array(_name)
res = []
value = @@instance['conf'][_name]
res.concat(value.split(',')) if value
res
end
|
.del_conf(_k) ⇒ Object
1213
1214
1215
|
# File 'lib/a-commons.rb', line 1213
def Application.del_conf(_k)
@@instance['conf'].delete(_k)
end
|
.del_conf_group(_conf_hash, _group) ⇒ Object
def Application.conf_group(_group, _suff = ‘conf’)
group_key="#{_suff}.#{_group}"
@@conf_groups = Hash.new if !defined?(@@conf_groups)
if @@conf_groups[group_key].nil?
@@conf_groups[group_key] = Hash.new
glen=_group.length
@@instance['conf'].keys.sort.each{|k|
if k[0..glen] == "#{_group}."
@@conf_groups[group_key][k[glen+1..-1]]=@@instance['conf'][k]
elsif @@conf_groups[group_key].length > 0
break
end
}
end
@@conf_groups[_group]
end
1204
1205
1206
1207
1208
1209
1210
1211
|
# File 'lib/a-commons.rb', line 1204
def Application.del_conf_group(_conf_hash, _group)
glen=_group.length
_conf_hash.keys.sort.each{|k|
if k[0..glen] == "#{_group}."
_conf_hash.delete(k)
end
}
end
|
.instance ⇒ Object
1159
1160
1161
|
# File 'lib/a-commons.rb', line 1159
def Application.instance
@@instance
end
|
.local_dir ⇒ Object
1171
1172
1173
|
# File 'lib/a-commons.rb', line 1171
def Application.local_dir
@@instance.local_dir if @@instance
end
|
.sys_info ⇒ Object
1182
1183
1184
|
# File 'lib/a-commons.rb', line 1182
def Application.sys_info
"[Platform = #{RUBY_PLATFORM}]\n[Ruby version = #{RUBY_VERSION}]"
end
|
.version ⇒ Object
1167
1168
1169
|
# File 'lib/a-commons.rb', line 1167
def Application.version
@@instance['applicationParams'].version if @@instance
end
|
Instance Method Details
#[](_name) ⇒ Object
1354
1355
1356
1357
1358
1359
1360
1361
|
# File 'lib/a-commons.rb', line 1354
def [](_name)
if @objs[_name]
return @objs[_name]
else
return nil
end
end
|
#[]=(_name, _value) ⇒ Object
1363
1364
1365
1366
1367
1368
|
# File 'lib/a-commons.rb', line 1363
def []=(_name, _value)
@objs[_name] = _value
end
|
#conf(_property, _value = nil) ⇒ Object
1175
1176
1177
1178
1179
1180
|
# File 'lib/a-commons.rb', line 1175
def conf(_property, _value=nil)
if !_value.nil?
self['conf'][_property] = _value
end
self['conf'][_property]
end
|
#create(_name, _class) ⇒ Object
1346
1347
1348
|
# File 'lib/a-commons.rb', line 1346
def create(_name, _class)
register(_name,_class.new)
end
|
#load_local_config(_create_if_not_exist = true) ⇒ Object
this method load config file from local directory for personalizations
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
|
# File 'lib/a-commons.rb', line 1280
def load_local_config(_create_if_not_exist=true)
if FileTest.exist?(local_file_config)
self['local_conf']= self.properties_file2hash(local_file_config)
self['conf'].update(self['local_conf'])
elsif _create_if_not_exist
if FileTest.writable?(local_dir)
f = File.new(local_file_config, "w")
begin
if f
p = self['conf']
if p
p.keys.sort.each{|key|
f.syswrite('#'+key+'='+self['conf'][key]+"\n")
}
end
end
ensure
f.close unless f.nil?
end
else
msg = Arcadia.text('main.e.dir_not_writable.msg', [local_dir])
Arcadia.dialog(self, 'type'=>'ok','title' => Arcadia.text('main.e.dir_not_writable.title', ['(Arcadia)']), 'msg' => msg, 'level'=>'error')
exit
end
end
end
|
#load_theme(_name = nil) ⇒ Object
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
|
# File 'lib/a-commons.rb', line 1307
def load_theme(_name=nil)
_theme_file = "conf/theme-#{_name}.conf" if !_name.nil?
if _theme_file && File.exist?(_theme_file)
thash = self.properties_file2hash(_theme_file)
if thash.has_key?('parent')
load_theme(thash['parent'])
self['conf_theme'].update(thash)
else
self['conf_theme'] = thash
end
self['conf'].update(self['conf_theme'])
self['conf_without_local'].update(self['conf_theme'])
_theme_res_file = "#{Dir.pwd}/conf/theme-#{_name}.res.rb"
if _theme_res_file && File.exist?(_theme_res_file)
begin
require _theme_res_file
rescue Exception => e
end
end
end
end
|
#local_dir ⇒ Object
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
|
# File 'lib/a-commons.rb', line 1330
def local_dir
home = File.expand_path '~'
_local_dir = File.join(home,'.'+self['applicationParams'].name) if home
if _local_dir && !File.exist?(_local_dir)
if FileTest.exist?(home)
Dir.mkdir(_local_dir)
@first_run = true
else
msg = Arcadia.text('main.e.dir_not_writable.msg', [home])
Arcadia.dialog(self, 'type'=>'ok', 'title' => Arcadia.text('main.e.dir_not_writable.title', [self['applicationParams'].name]), 'msg' => msg, 'level'=>'error')
exit
end
end
return _local_dir
end
|
#local_file_config ⇒ Object
1250
1251
1252
|
# File 'lib/a-commons.rb', line 1250
def local_file_config
File.join(local_dir, File.basename(self['applicationParams'].config_file))
end
|
#objects(_name) ⇒ Object
1350
1351
1352
|
# File 'lib/a-commons.rb', line 1350
def objects(_name)
return @objs[_name]
end
|
#prepare ⇒ Object
1238
1239
|
# File 'lib/a-commons.rb', line 1238
def prepare
end
|
#publish(_name, _obj) ⇒ Object
1241
1242
1243
1244
1245
1246
1247
1248
|
# File 'lib/a-commons.rb', line 1241
def publish(_name, _obj)
@objs = Hash.new if !defined?(@objs)
if @objs[_name] == nil
@objs[_name] = _obj
else
raise("The name #{_name} already exist")
end
end
|
#run ⇒ Object
1371
1372
|
# File 'lib/a-commons.rb', line 1371
def run
end
|
#update_local_config ⇒ Object
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
|
# File 'lib/a-commons.rb', line 1254
def update_local_config
if FileTest.exist?(local_file_config)
if FileTest.writable?(local_dir)
f = File.new(local_file_config, "w")
begin
if f
properties = self['conf']
if properties
properties.keys.sort.each{|key|
if self['conf_without_local'][key] == self['conf'][key] || (self['origin_conf'][key] && self['origin_conf'][key].include?('>>>')) f.syswrite("# #{key}=#{self['origin_conf'][key]}\n") elsif self['conf'][key]
f.syswrite("#{key}=#{self['conf'][key]}\n")
end
}
end
end
ensure
f.close unless f.nil?
end
end
end
end
|