Class: Objc2swiftAssistant::FileHierarchicalConfigNode
- Inherits:
-
Object
- Object
- Objc2swiftAssistant::FileHierarchicalConfigNode
- Defined in:
- lib/objc2swift_assistant/file_hierarchical_config.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#child_nodes ⇒ Object
Returns the value of attribute child_nodes.
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#configuration_hash ⇒ Object
Returns the value of attribute configuration_hash.
-
#parent_node ⇒ Object
Returns the value of attribute parent_node.
-
#path_from_parent ⇒ Object
Returns the value of attribute path_from_parent.
-
#path_from_root ⇒ Object
Returns the value of attribute path_from_root.
-
#wildcard_nodes ⇒ Object
Returns the value of attribute wildcard_nodes.
Instance Method Summary collapse
- #add_to_parent(parent) ⇒ Object
-
#config_value_for_key(key, path_str) ⇒ Object
def apply_wildcards( parent_wildcards=[] ) all_wildcards = @wildcard_nodes + parent_wildcards @child_nodes.clone.each { |node| node.apply_wildcards( all_wildcards ) }.
-
#initialize(configuration, node_hash, relative_path, parent: nil, is_wildcard: false) ⇒ FileHierarchicalConfigNode
constructor
A new instance of FileHierarchicalConfigNode.
- #make_child_node(path_str, child_hash) ⇒ Object
- #post_process_config ⇒ Object
Constructor Details
#initialize(configuration, node_hash, relative_path, parent: nil, is_wildcard: false) ⇒ FileHierarchicalConfigNode
Returns a new instance of FileHierarchicalConfigNode.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/objc2swift_assistant/file_hierarchical_config.rb', line 80 def initialize( configuration, node_hash, relative_path, parent:nil, is_wildcard:false ) @configuration = configuration @configuration_hash = node_hash || {} @path_from_parent = Pathname.new( relative_path ) #'.' is the "root" of relative Pathname. i.e. Pathname.parent.parent... @child_nodes = [] if( parent.nil? ) @path_from_root = Pathname.new( relative_path ) unless is_wildcard # Parents set on clones of this object @parent_node = nil else add_to_parent( parent ) end @wildcard_nodes = [] child_hashes = @configuration_hash[ "subdirs" ] || nil unless child_hashes.nil? child_hashes.each do |child_hash| path_str = child_hash['path'] make_child_node( path_str, child_hash ) end end post_process_config end |
Instance Attribute Details
#child_nodes ⇒ Object
Returns the value of attribute child_nodes.
75 76 77 |
# File 'lib/objc2swift_assistant/file_hierarchical_config.rb', line 75 def child_nodes @child_nodes end |
#configuration ⇒ Object
Returns the value of attribute configuration.
71 72 73 |
# File 'lib/objc2swift_assistant/file_hierarchical_config.rb', line 71 def configuration @configuration end |
#configuration_hash ⇒ Object
Returns the value of attribute configuration_hash.
77 78 79 |
# File 'lib/objc2swift_assistant/file_hierarchical_config.rb', line 77 def configuration_hash @configuration_hash end |
#parent_node ⇒ Object
Returns the value of attribute parent_node.
74 75 76 |
# File 'lib/objc2swift_assistant/file_hierarchical_config.rb', line 74 def parent_node @parent_node end |
#path_from_parent ⇒ Object
Returns the value of attribute path_from_parent.
72 73 74 |
# File 'lib/objc2swift_assistant/file_hierarchical_config.rb', line 72 def path_from_parent @path_from_parent end |
#path_from_root ⇒ Object
Returns the value of attribute path_from_root.
73 74 75 |
# File 'lib/objc2swift_assistant/file_hierarchical_config.rb', line 73 def path_from_root @path_from_root end |
#wildcard_nodes ⇒ Object
Returns the value of attribute wildcard_nodes.
76 77 78 |
# File 'lib/objc2swift_assistant/file_hierarchical_config.rb', line 76 def wildcard_nodes @wildcard_nodes end |
Instance Method Details
#add_to_parent(parent) ⇒ Object
120 121 122 123 124 |
# File 'lib/objc2swift_assistant/file_hierarchical_config.rb', line 120 def add_to_parent( parent ) @parent_node = parent @parent_node.child_nodes << self @path_from_root = parent.path_from_root.join( @path_from_parent ) end |
#config_value_for_key(key, path_str) ⇒ Object
def apply_wildcards( parent_wildcards=[] )
all_wildcards = @wildcard_nodes + parent_wildcards
@child_nodes.clone.each { |node| node.apply_wildcards( all_wildcards ) }
all_wildcards.each do |wildcard_node|
new_child = wildcard_node.clone
new_child.add_to_parent( self )
success, failure_reason = configuration.add_config_node( new_child ) #todo look for errors
end
end
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/objc2swift_assistant/file_hierarchical_config.rb', line 141 def config_value_for_key( key, path_str ) value = nil unless path_str.nil? || @wildcard_nodes.length == 0 catch :wildcard_value_found do @wildcard_nodes.each do |wildcard_node| pathname = Pathname.new( path_str ) until pathname.to_s == @path_from_root.to_s if pathname.to_s.end_with?( wildcard_node.path_from_parent.to_s ) value = wildcard_node.config_value_for_key( key, nil ) throw :wildcard_value_found end pathname = pathname.parent end end end end if value.nil? value = @configuration_hash[ key ] value ||= parent_node.config_value_for_key( key, path_str ) unless parent_node.nil? end value end |
#make_child_node(path_str, child_hash) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/objc2swift_assistant/file_hierarchical_config.rb', line 106 def make_child_node( path_str, child_hash ) m = path_str.match(/\*\*\/(?<path>.*)/) if m.nil? child = @configuration.node_class.new( @configuration, child_hash, path_str, parent: self ) success, failure_reason = configuration.add_config_node(child) @configuration.log_error("Could not add child configuration for path:#{child.path} to parent node with path:#{@path} - #{failure_reason})") unless success else path_str = m[ 'path' ] wild_child = @configuration.node_class.new(@configuration, child_hash, path_str, is_wildcard:true) @wildcard_nodes << wild_child end end |
#post_process_config ⇒ Object
126 127 128 |
# File 'lib/objc2swift_assistant/file_hierarchical_config.rb', line 126 def post_process_config() # Hook for subclasses end |