Class: SyntaxTree::CLI::CTags
Overview
An action of the CLI that generates ctags for the given source.
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Attributes inherited from Action
Instance Method Summary collapse
-
#initialize(options) ⇒ CTags
constructor
A new instance of CTags.
- #run(item) ⇒ Object
- #success ⇒ Object
Methods inherited from Action
Constructor Details
#initialize(options) ⇒ CTags
Returns a new instance of CTags.
166 167 168 169 |
# File 'lib/syntax_tree/cli.rb', line 166 def initialize() super @entries = [] end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
164 165 166 |
# File 'lib/syntax_tree/cli.rb', line 164 def entries @entries end |
Instance Method Details
#run(item) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/syntax_tree/cli.rb', line 171 def run(item) lines = item.source.lines(chomp: true) SyntaxTree .index(item.source) .each do |entry| line = lines[entry.location.line - 1] pattern = "/^#{line.gsub("\\", "\\\\\\\\").gsub("/", "\\/")}$/;\"" entries << case entry when SyntaxTree::Index::ModuleDefinition parts = [entry.name, item.filepath, pattern, "m"] if entry.nesting != [[entry.name]] parts << "class:#{entry.nesting.flatten.tap(&:pop).join(".")}" end parts.join("\t") when SyntaxTree::Index::ClassDefinition parts = [entry.name, item.filepath, pattern, "c"] if entry.nesting != [[entry.name]] parts << "class:#{entry.nesting.flatten.tap(&:pop).join(".")}" end unless entry.superclass.empty? inherits = entry.superclass.join(".").delete_prefix(".") parts << "inherits:#{inherits}" end parts.join("\t") when SyntaxTree::Index::MethodDefinition parts = [entry.name, item.filepath, pattern, "f"] unless entry.nesting.empty? parts << "class:#{entry.nesting.flatten.join(".")}" end parts.join("\t") when SyntaxTree::Index::SingletonMethodDefinition parts = [entry.name, item.filepath, pattern, "F"] unless entry.nesting.empty? parts << "class:#{entry.nesting.flatten.join(".")}" end parts.join("\t") when SyntaxTree::Index::AliasMethodDefinition parts = [entry.name, item.filepath, pattern, "a"] unless entry.nesting.empty? parts << "class:#{entry.nesting.flatten.join(".")}" end parts.join("\t") when SyntaxTree::Index::ConstantDefinition parts = [entry.name, item.filepath, pattern, "C"] unless entry.nesting.empty? parts << "class:#{entry.nesting.flatten.join(".")}" end parts.join("\t") end end end |
#success ⇒ Object
238 239 240 241 242 243 244 245 |
# File 'lib/syntax_tree/cli.rb', line 238 def success puts(" !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;\" to lines/\n !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/\n HEADER\n\n entries.sort.each { |entry| puts(entry) }\nend\n") |