Class: Countless::Annotations::Annotation
- Inherits:
-
Struct
- Object
- Struct
- Countless::Annotations::Annotation
- Defined in:
- lib/countless/annotations.rb
Overview
A single annotation representation.
Instance Attribute Summary collapse
-
#line ⇒ Object
Returns the value of attribute line.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
-
.directories ⇒ Array<String>
Returns the currently configured directories.
-
.extensions ⇒ Hash<RegExp => Proc>
Returns the currently configured file extension handlers.
-
.extensions_regexp(exts, files = []) ⇒ RegExp
Build a new extension regexp of the given extensions.
-
.files ⇒ Array<String>
Returns the currently configured files.
-
.register_directories(*dirs) ⇒ Object
Registers additional directories to be included.
-
.register_extensions(*exts, &block) ⇒ Object
Registers new annotations file extension handlers.
-
.register_files(*dirs) ⇒ Object
Registers additional files to be included.
-
.register_tags(*additional_tags) ⇒ Object
Registers additional tags.
-
.tags ⇒ Array<String>
Returns the currently configured tags.
Instance Method Summary collapse
-
#to_s(options = {}) ⇒ Object
Returns a representation of the annotation that looks like this:.
Instance Attribute Details
#line ⇒ Object
Returns the value of attribute line
143 144 145 |
# File 'lib/countless/annotations.rb', line 143 def line @line end |
#tag ⇒ Object
Returns the value of attribute tag
143 144 145 |
# File 'lib/countless/annotations.rb', line 143 def tag @tag end |
#text ⇒ Object
Returns the value of attribute text
143 144 145 |
# File 'lib/countless/annotations.rb', line 143 def text @text end |
Class Method Details
.directories ⇒ Array<String>
Returns the currently configured directories.
162 163 164 165 |
# File 'lib/countless/annotations.rb', line 162 def self.directories @directories ||= \ Countless.configuration.annotations_directories.deep_dup end |
.extensions ⇒ Hash<RegExp => Proc>
Returns the currently configured file extension handlers.
193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/countless/annotations.rb', line 193 def self.extensions @extensions ||= begin patterns = Countless.configuration.annotation_patterns.values patterns.map do |conf| [ extensions_regexp(conf[:extensions], conf[:files] || []), conf[:regex] ] end.to_h end end |
.extensions_regexp(exts, files = []) ⇒ RegExp
Build a new extension regexp of the given extensions.
218 219 220 221 222 223 |
# File 'lib/countless/annotations.rb', line 218 def self.extensions_regexp(exts, files = []) exts = /\.(#{exts.join('|')})$/ return exts if files.empty? Regexp.union(/^#{files.join('|')}$/, exts) end |
.files ⇒ Array<String>
Returns the currently configured files.
147 148 149 150 |
# File 'lib/countless/annotations.rb', line 147 def self.files @files ||= \ Countless.configuration.annotations_files.deep_dup end |
.register_directories(*dirs) ⇒ Object
Registers additional directories to be included.
170 171 172 |
# File 'lib/countless/annotations.rb', line 170 def self.register_directories(*dirs) directories.push(*dirs) end |
.register_extensions(*exts, &block) ⇒ Object
Registers new annotations file extension handlers.
209 210 211 |
# File 'lib/countless/annotations.rb', line 209 def self.register_extensions(*exts, &block) extensions[extensions_regexp(exts)] = block end |
.register_files(*dirs) ⇒ Object
Registers additional files to be included.
155 156 157 |
# File 'lib/countless/annotations.rb', line 155 def self.register_files(*dirs) files.push(*dirs) end |
.register_tags(*additional_tags) ⇒ Object
Registers additional tags.
186 187 188 |
# File 'lib/countless/annotations.rb', line 186 def self.(*) .push(*) end |
.tags ⇒ Array<String>
Returns the currently configured tags.
177 178 179 180 181 |
# File 'lib/countless/annotations.rb', line 177 def self. ||= Countless.configuration..deep_dup.map do |tag| "@?#{tag}" end end |
Instance Method Details
#to_s(options = {}) ⇒ Object
Returns a representation of the annotation that looks like this:
[126] [TODO] This algorithm is nice and simple, 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. When options has a value for :indent the line number block will be right-justified.
235 236 237 238 239 |
# File 'lib/countless/annotations.rb', line 235 def to_s( = {}) s = +"[#{line.to_s.rjust(options[:indent])}] " s << "[#{tag}] " if [:tag] s << text end |