Class: Application
Defined Under Namespace
Classes: ApplicationParams
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from EventBus
attach_listener, broadcast_event, detach_listener, process_event
#append_persistent_property, #override_persistent
#properties_file2hash, properties_group, #resolve_link, #resolve_properties_link
Constructor Details
#initialize(_ap = ApplicationParams.new) {|_self| ... } ⇒ Application
Returns a new instance of Application.
595
596
597
598
599
600
601
602
603
604
605
606
607
608
|
# File 'lib/a-commons.rb', line 595
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('pers', properties_file2hash(self['applicationParams'].persistent_file)) if self['applicationParams'].persistent_file
yield(self) if block_given?
end
|
Class Method Details
.conf(_property) ⇒ Object
614
615
616
|
# File 'lib/a-commons.rb', line 614
def Application.conf(_property)
@@instance['conf'][_property] if @@instance
end
|
.conf_group(_group) ⇒ Object
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
|
# File 'lib/a-commons.rb', line 626
def Application.conf_group(_group)
@@conf_groups = Hash.new if !defined?(@@conf_groups)
if @@conf_groups[_group].nil?
@@conf_groups[_group] = Hash.new
glen=_group.length
@@instance['conf'].keys.sort.each{|k|
if k[0..glen] == "#{_group}."
@@conf_groups[_group][k[glen+1..-1]]=@@instance['conf'][k]
elsif @@conf_groups[_group].length > 0
break
end
}
end
@@conf_groups[_group]
end
|
.instance ⇒ Object
610
611
612
|
# File 'lib/a-commons.rb', line 610
def Application.instance
@@instance
end
|
Instance Method Details
#[](_name) ⇒ Object
721
722
723
724
725
726
727
|
# File 'lib/a-commons.rb', line 721
def [](_name)
if @objs[_name]
return @objs[_name]
else
raise RuntimeError, "resurce '"+_name+"' unavabled ", caller
end
end
|
#[]=(_name, _value) ⇒ Object
729
730
731
732
733
|
# File 'lib/a-commons.rb', line 729
def []=(_name, _value)
if @objs[_name]
@objs[_name] = _value
end
end
|
#conf(_property) ⇒ Object
618
619
620
|
# File 'lib/a-commons.rb', line 618
def conf(_property)
self['conf'][_property]
end
|
#create(_name, _class) ⇒ Object
713
714
715
|
# File 'lib/a-commons.rb', line 713
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
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
|
# File 'lib/a-commons.rb', line 656
def load_local_config(_create_if_not_exist=true)
local_file_config = File.join(local_dir,File.basename(self['applicationParams'].config_file))
if FileTest.exist?(local_file_config)
self['conf'].update(self.properties_file2hash(local_file_config))
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 = "Locad dir "+'"'+local_dir+'"'+" must be writable!"
Arcadia.dialog(self, 'type'=>'ok','title' => '(Arcadia)', 'msg' => msg, 'level'=>'error')
exit
end
end
end
|
#load_theme(_name = nil) ⇒ Object
683
684
685
686
687
688
689
690
691
692
693
694
695
696
|
# File 'lib/a-commons.rb', line 683
def load_theme(_name=nil)
_theme_file = "conf/theme-#{_name}.conf" if !_name.nil?
if _theme_file && File.exist?(_theme_file)
self['conf'].update(self.properties_file2hash(_theme_file))
_theme_res_file = "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
698
699
700
701
702
703
704
705
706
707
708
709
710
711
|
# File 'lib/a-commons.rb', line 698
def local_dir
_local_dir = File.join(ENV["HOME"],'.'+self['applicationParams'].name) if ENV["HOME"]
if _local_dir && !File.exist?(_local_dir)
if FileTest.exist?(ENV["HOME"])
Dir.mkdir(_local_dir)
@first_run = true
else
msg = "Locad dir "+'"'+ENV["HOME"]+'"'+" must be writable!"
Arcadia.dialog(self, 'type'=>'ok', 'title' => "(#{self['applicationParams'].name})", 'msg' => msg, 'level'=>'error')
exit
end
end
return _local_dir
end
|
#objects(_name) ⇒ Object
717
718
719
|
# File 'lib/a-commons.rb', line 717
def objects(_name)
return @objs[_name]
end
|
#prepare ⇒ Object
643
644
|
# File 'lib/a-commons.rb', line 643
def prepare
end
|
#publish(_name, _obj) ⇒ Object
646
647
648
649
650
651
652
653
|
# File 'lib/a-commons.rb', line 646
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
736
737
|
# File 'lib/a-commons.rb', line 736
def run
end
|
#sys_info ⇒ Object
622
623
624
|
# File 'lib/a-commons.rb', line 622
def sys_info
"[Platform = #{RUBY_PLATFORM}] [Ruby version = #{RUBY_VERSION}]"
end
|