Class: Rails::SourceAnnotationExtractor::Annotation

Inherits:
Struct
  • Object
show all
Defined in:
railties/lib/rails/source_annotation_extractor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

#as_json

Instance Attribute Details

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



43
44
45
# File 'railties/lib/rails/source_annotation_extractor.rb', line 43

def line
  @line
end

#tagObject

Returns the value of attribute tag

Returns:

  • (Object)

    the current value of tag



43
44
45
# File 'railties/lib/rails/source_annotation_extractor.rb', line 43

def tag
  @tag
end

#textObject

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



43
44
45
# File 'railties/lib/rails/source_annotation_extractor.rb', line 43

def text
  @text
end

Class Method Details

.directoriesObject



44
45
46
# File 'railties/lib/rails/source_annotation_extractor.rb', line 44

def self.directories
  @@directories ||= %w(app config db lib test)
end

.extensionsObject



64
65
66
# File 'railties/lib/rails/source_annotation_extractor.rb', line 64

def self.extensions
  @@extensions ||= {}
end

.register_directories(*dirs) ⇒ Object

Registers additional directories to be included

Rails::SourceAnnotationExtractor::Annotation.register_directories("spec", "another")


50
51
52
# File 'railties/lib/rails/source_annotation_extractor.rb', line 50

def self.register_directories(*dirs)
  directories.push(*dirs)
end

.register_extensions(*exts, &block) ⇒ Object

Registers new Annotations File Extensions

Rails::SourceAnnotationExtractor::Annotation.register_extensions("css", "scss", "sass", "less", "js") { |tag| /\/\/\s*(#{tag}):?\s*(.*)$/ }


70
71
72
# File 'railties/lib/rails/source_annotation_extractor.rb', line 70

def self.register_extensions(*exts, &block)
  extensions[/\.(#{exts.join("|")})$/] = block
end

.register_tags(*additional_tags) ⇒ Object

Registers additional tags

Rails::SourceAnnotationExtractor::Annotation.register_tags("TESTME", "DEPRECATEME")


60
61
62
# File 'railties/lib/rails/source_annotation_extractor.rb', line 60

def self.register_tags(*additional_tags)
  tags.push(*additional_tags)
end

.tagsObject



54
55
56
# File 'railties/lib/rails/source_annotation_extractor.rb', line 54

def self.tags
  @@tags ||= %w(OPTIMIZE FIXME TODO)
end

Instance Method Details

#to_s(options = {}) ⇒ Object

Returns a representation of the annotation that looks like this:

[126] [TODO] This algorithm is simple and clearly correct, make it faster.

If options has a flag :tag the tag is shown as in the example above. Otherwise the string contains just line and text.



100
101
102
103
104
# File 'railties/lib/rails/source_annotation_extractor.rb', line 100

def to_s(options = {})
  s = +"[#{line.to_s.rjust(options[:indent])}] "
  s << "[#{tag}] " if options[:tag]
  s << text
end