class Application

Constants

ApplicationParams

Public Class Methods

array_conf(_name, _array) click to toggle source
# 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) click to toggle source
# File lib/a-commons.rb, line 1163
def Application.conf(_property, _value=nil)
  @@instance.conf(_property, _value) if @@instance
end
conf_array(_name) click to toggle source
# 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) click to toggle source
# File lib/a-commons.rb, line 1213
def Application.del_conf(_k)
  @@instance['conf'].delete(_k)
end
del_conf_group(_conf_hash, _group) click to toggle source

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

# 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() click to toggle source
# File lib/a-commons.rb, line 1159
def Application.instance
  @@instance
end
local_dir() click to toggle source
# File lib/a-commons.rb, line 1171
def Application.local_dir
  @@instance.local_dir if @@instance
end
new(_ap=ApplicationParams.new) { |self| ... } click to toggle source
# File lib/a-commons.rb, line 1140
def initialize(_ap=ApplicationParams.new)
  @@instance = self
  eval('$'+_ap.name+'=self') # set $arcadia to this instance
  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
  # read in the settings'
  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
sys_info() click to toggle source
# File lib/a-commons.rb, line 1182
def Application.sys_info
  "[Platform = #{RUBY_PLATFORM}]\n[Ruby version = #{RUBY_VERSION}]"
end
version() click to toggle source
# File lib/a-commons.rb, line 1167
def Application.version
  @@instance['applicationParams'].version if @@instance
end

Public Instance Methods

[](_name) click to toggle source
# File lib/a-commons.rb, line 1354
def [](_name)
  if @objs[_name]
    return @objs[_name]
  else
    return nil
    #raise RuntimeError, "resurce '"+_name+"' unavabled ", caller
  end
end
[]=(_name, _value) click to toggle source
# File lib/a-commons.rb, line 1363
def []=(_name, _value)
  @objs[_name] = _value
  #    if @objs[_name]
  #      @objs[_name] = _value
  #    end
end
conf(_property, _value=nil) click to toggle source
# 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) click to toggle source
# File lib/a-commons.rb, line 1346
def create(_name, _class)
  register(_name,_class.new)
end
load_local_config(_create_if_not_exist=true) click to toggle source

this method load config file from local directory for personalizations

# 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) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/a-commons.rb, line 1250
def local_file_config
  File.join(local_dir, File.basename(self['applicationParams'].config_file))
end
objects(_name) click to toggle source
# File lib/a-commons.rb, line 1350
def objects(_name)
  return @objs[_name]
end
prepare() click to toggle source
# File lib/a-commons.rb, line 1238
def prepare
end
publish(_name, _obj) click to toggle source
# 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() click to toggle source
# File lib/a-commons.rb, line 1371
def run
end
update_local_config() click to toggle source
# File lib/a-commons.rb, line 1254
def update_local_config
  # local_dir is ~/arcadia
  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?('>>>')) # || self['local_conf'][key].nil?
                f.syswrite("# #{key}=#{self['origin_conf'][key]}\n") # write it as a comment since it isn't a real change
              elsif self['conf'][key]
                f.syswrite("#{key}=#{self['conf'][key]}\n")
              end
            }
          end
        end
      ensure
        f.close unless f.nil?
      end
    end
  end
end