Class: SourceAnnotationExtractor::Annotation

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



18
19
20
# File 'lib/rails/source_annotation_extractor.rb', line 18

def line
  @line
end

#tagObject

Returns the value of attribute tag

Returns:

  • (Object)

    the current value of tag



18
19
20
# File 'lib/rails/source_annotation_extractor.rb', line 18

def tag
  @tag
end

#textObject

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



18
19
20
# File 'lib/rails/source_annotation_extractor.rb', line 18

def text
  @text
end

Class Method Details

.directoriesObject



19
20
21
# File 'lib/rails/source_annotation_extractor.rb', line 19

def self.directories
  @@directories ||= %w(app config db lib test) + (ENV["SOURCE_ANNOTATION_DIRECTORIES"] || "").split(",")
end

.extensionsObject



29
30
31
# File 'lib/rails/source_annotation_extractor.rb', line 29

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

.register_directories(*dirs) ⇒ Object

Registers additional directories to be included

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


25
26
27
# File 'lib/rails/source_annotation_extractor.rb', line 25

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

.register_extensions(*exts, &block) ⇒ Object

Registers new Annotations File Extensions

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


35
36
37
# File 'lib/rails/source_annotation_extractor.rb', line 35

def self.register_extensions(*exts, &block)
  extensions[/\.(#{exts.join("|")})$/] = block
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.



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

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