Module: Configurable
- Included in:
- AgMultiEditor, Application
- Defined in:
- lib/a-commons.rb
Class Method Summary collapse
Instance Method Summary collapse
- #properties_file2hash(_property_file, _link_hash = nil) ⇒ Object
- #resolve_link(_value, _hash_source, _link_symbol = '>>>', _add_symbol = '+++') ⇒ Object
- #resolve_properties_link(_hash_target, _hash_source, _link_symbol = '>>>', _add_symbol = '+++') ⇒ Object
Class Method Details
.properties_group(_group, _hash_source) ⇒ Object
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/a-commons.rb', line 529 def Configurable.properties_group(_group, _hash_source) @@conf_groups = Hash.new if !defined?(@@conf_groups) if @@conf_groups[_group].nil? @@conf_groups[_group] = Hash.new glen=_group.length _hash_source.keys.sort.each{|k| if k[0..glen] == "#{_group}." @@conf_groups[_group][k[glen+1..-1]]=_hash_source[k] elsif @@conf_groups[_group].length > 0 break end } end Hash.new.update(@@conf_groups[_group]) end |
Instance Method Details
#properties_file2hash(_property_file, _link_hash = nil) ⇒ Object
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
# File 'lib/a-commons.rb', line 481 def properties_file2hash(_property_file, _link_hash=nil) r_hash = Hash.new if _property_file && FileTest::exist?(_property_file) f = File::open(_property_file,'r') begin _lines = f.readlines _lines.each{|_line| _strip_line = _line.strip if (_strip_line.length > 0)&&(_strip_line[0,1]!='#') var_plat = _line.split('::') if var_plat.length > 1 if (RUBY_PLATFORM.include?(var_plat[0])) _line = var_plat[1] var_plat[2..-1].collect{|x| _line=_line+'::'+x} if var_plat.length > 2 else _line = '' end end var_ruby_version = _line.split(':@:') if var_ruby_version.length > 1 version = var_ruby_version[0] if (RUBY_VERSION[0..version.length-1]==version) _line = var_ruby_version[1] else _line = '' end end var = _line.split('=') if var.length > 1 _value = var[1].strip var[2..-1].collect{|x| _value=_value+'='+x} if var.length > 2 if _link_hash _value = resolve_link(_value, _link_hash) end r_hash[var[0].strip]=_value end end } ensure f.close unless f.nil? end return r_hash else puts 'warning--file does not exist', _property_file end end |
#resolve_link(_value, _hash_source, _link_symbol = '>>>', _add_symbol = '+++') ⇒ Object
546 547 548 549 550 551 552 553 554 555 556 557 |
# File 'lib/a-commons.rb', line 546 def resolve_link(_value, _hash_source, _link_symbol='>>>', _add_symbol='+++') if _value.length > 0 _v, _vadd = _value.split(_add_symbol) else _v = _value end if _v.length > 3 && _v[0..2]==_link_symbol _v=_hash_source[_v[3..-1]] if _hash_source[_v[3..-1]] _v=_v+_vadd if _vadd end return _v end |
#resolve_properties_link(_hash_target, _hash_source, _link_symbol = '>>>', _add_symbol = '+++') ⇒ Object
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 |
# File 'lib/a-commons.rb', line 559 def resolve_properties_link(_hash_target, _hash_source, _link_symbol='>>>', _add_symbol='+++') loop_level_max = 10 # _hash_adding = Hash.new _keys_to_extend = Array.new _hash_target.each{|k,value| loop_level = 0 if value.length > 0 v, vadd = value.split(_add_symbol) else v= value end # p "value=#{value} class=#{value.class}" # p "v=#{v} class=#{v.class}" # p "vadd=#{vadd}" while loop_level < loop_level_max && v.length > 3 && v[0..2]==_link_symbol if k[-1..-1]=='.' _keys_to_extend << k break elsif _hash_source[v[3..-1]] v=_hash_source[v[3..-1]] v=v+vadd if vadd else break end loop_level = loop_level + 1 end _hash_target[k]=v if loop_level == loop_level_max raise("Link loop found for property : #{k}") end } _keys_to_extend.each do |k| v=_hash_target[k] g=Configurable.properties_group(v[3..-1], _hash_target) g.each do |key,value| _hash_target["#{k[0..-2]}.#{key}"]=value if !_hash_target["#{k[0..-2]}.#{key}"] end _hash_target.delete(k) end end |