Class: Objc2swiftAssistant::DirectoryNode

Inherits:
Object
  • Object
show all
Defined in:
lib/objc2swift_assistant/file_sets.rb

Direct Known Subclasses

ObjCDirectoryNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, file_set) ⇒ DirectoryNode

Returns a new instance of DirectoryNode.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/objc2swift_assistant/file_sets.rb', line 119

def initialize(path, file_set)
  @full_path = path
  @file_set = file_set

  if file_set.root == @full_path
    @parent_node = nil
  else
    @parent_node = file_set.directory_node_for_path( path.parent )
  end

  @relative_path = @full_path.relative_path_from( file_set.root )

  @child_directories = {}
  @file_nodes = {}
  @pruned = false
  @file_nodes_by_name = {}

  #todo: Apply settings

  unless @parent_node.nil?
    @parent_node.add_child_directory( self )
  end
end

Instance Attribute Details

#child_directoriesObject

Returns the value of attribute child_directories.



115
116
117
# File 'lib/objc2swift_assistant/file_sets.rb', line 115

def child_directories
  @child_directories
end

#file_nodes_by_nameObject

Returns the value of attribute file_nodes_by_name.



112
113
114
# File 'lib/objc2swift_assistant/file_sets.rb', line 112

def file_nodes_by_name
  @file_nodes_by_name
end

#file_setObject

Returns the value of attribute file_set.



111
112
113
# File 'lib/objc2swift_assistant/file_sets.rb', line 111

def file_set
  @file_set
end

#full_pathObject

Returns the value of attribute full_path.



113
114
115
# File 'lib/objc2swift_assistant/file_sets.rb', line 113

def full_path
  @full_path
end

#parent_nodeObject

Returns the value of attribute parent_node.



116
117
118
# File 'lib/objc2swift_assistant/file_sets.rb', line 116

def parent_node
  @parent_node
end

#prunedObject

Returns the value of attribute pruned.



117
118
119
# File 'lib/objc2swift_assistant/file_sets.rb', line 117

def pruned
  @pruned
end

#relative_pathObject

Returns the value of attribute relative_path.



114
115
116
# File 'lib/objc2swift_assistant/file_sets.rb', line 114

def relative_path
  @relative_path
end

Instance Method Details

#add_child_directory(child_node) ⇒ Object

Add a child directory. Mark the child as pruned if this node is pruned. Note that this keeps pruned nodes around which is desirable for reporting the effects of code generation



145
146
147
148
# File 'lib/objc2swift_assistant/file_sets.rb', line 145

def add_child_directory( child_node )
  @child_directories[ child_node.relative_path.basename().to_s ] = child_node
  child_node.pruned = @pruned
end

#dump(indent, tab, errors_only) ⇒ Object



150
151
152
153
154
155
156
# File 'lib/objc2swift_assistant/file_sets.rb', line 150

def dump( indent, tab, errors_only )
  puts( indent + "Path: #{@relative_path.to_s}")
  puts( indent + "Files:") unless @file_nodes_by_name.length == 0
  @file_nodes_by_name.each_value { |file| file.dump( indent+tab, tab, errors_only ) }
  puts( "\n" + indent + "Child Directories:") unless @child_directories.length == 0
  @child_directories.each_value { |dir| dir.dump( indent+tab, tab, errors_only ) }
end