Class: Puppet_X::EnterpriseModules::WebLogic::BeanPath
- Inherits:
-
Object
- Object
- Puppet_X::EnterpriseModules::WebLogic::BeanPath
- Defined in:
- lib/puppet_x/enterprisemodules/weblogic/bean_path.rb
Constant Summary collapse
- VARIABLE_REGEXP =
/%<(.*)>/.freeze
Instance Method Summary collapse
- #==(other) ⇒ Object
- #contains_variables? ⇒ Boolean
-
#initialize(path) ⇒ BeanPath
constructor
A new instance of BeanPath.
- #segments ⇒ Object
- #subst(hash) ⇒ Object
- #to_s ⇒ Object
- #unassigned(path) ⇒ Object
- #up ⇒ Object
- #variables(path) ⇒ Object
Constructor Details
#initialize(path) ⇒ BeanPath
Returns a new instance of BeanPath.
12 13 14 |
# File 'lib/puppet_x/enterprisemodules/weblogic/bean_path.rb', line 12 def initialize(path) @path = path end |
Instance Method Details
#==(other) ⇒ Object
69 70 71 |
# File 'lib/puppet_x/enterprisemodules/weblogic/bean_path.rb', line 69 def ==(other) @path == other end |
#contains_variables? ⇒ Boolean
16 17 18 |
# File 'lib/puppet_x/enterprisemodules/weblogic/bean_path.rb', line 16 def contains_variables? !@path.scan(VARIABLE_REGEXP).empty? end |
#segments ⇒ Object
65 66 67 |
# File 'lib/puppet_x/enterprisemodules/weblogic/bean_path.rb', line 65 def segments @path.split('/') - [''] end |
#subst(hash) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/puppet_x/enterprisemodules/weblogic/bean_path.rb', line 46 def subst(hash) filled_in_segments = [] segments.each do |segment| substituted_value = segment % hash # # When String % is called with a non-existing key_name # in the Hash, it should throw an error. Don't know why, # but sometimes this doesn't happen. To make sure it still works # we do an extra check # break if VARIABLE_REGEXP.match?(substituted_value) filled_in_segments << substituted_value rescue KeyError break end "/#{filled_in_segments.join('/')}" end |
#to_s ⇒ Object
73 74 75 |
# File 'lib/puppet_x/enterprisemodules/weblogic/bean_path.rb', line 73 def to_s @path end |
#unassigned(path) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/puppet_x/enterprisemodules/weblogic/bean_path.rb', line 20 def unassigned(path) result = [] current_segments = path.split('/') - [''] segments.each_with_index do |segment, i| variable_name = segment.scan(VARIABLE_REGEXP).flatten.first current_value = current_segments[i] result << variable_name.to_sym if variable_name && !current_value end result end |
#up ⇒ Object
31 32 33 |
# File 'lib/puppet_x/enterprisemodules/weblogic/bean_path.rb', line 31 def up segments.empty? ? '/' : "/#{segments[0..-2].join('/')}" end |
#variables(path) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/puppet_x/enterprisemodules/weblogic/bean_path.rb', line 35 def variables(path) result = {} current_segments = path.split('/') - [''] segments.each_with_index do |segment, i| variable_name = segment.scan(VARIABLE_REGEXP).flatten.first current_value = current_segments[i] result[variable_name.to_sym] = current_value if variable_name && current_value end result end |