class Objc2swiftAssistant::FileHierarchicalConfigNode
Attributes
child_nodes[RW]
configuration[RW]
configuration_hash[RW]
parent_node[RW]
path_from_parent[RW]
path_from_root[RW]
wildcard_nodes[RW]
Public Class Methods
new( configuration, node_hash, relative_path, parent:nil, is_wildcard:false )
click to toggle source
# 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
Public Instance Methods
add_to_parent( parent )
click to toggle source
# 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 )
click to toggle source
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
# 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 )
click to toggle source
# 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()
click to toggle source
# File lib/objc2swift_assistant/file_hierarchical_config.rb, line 126 def post_process_config() # Hook for subclasses end