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
138 139 140 |
# File 'lib/countless/annotations.rb', line 138 def line @line end |
#tag ⇒ Object
Returns the value of attribute tag
138 139 140 |
# File 'lib/countless/annotations.rb', line 138 def tag @tag end |
#text ⇒ Object
Returns the value of attribute text
138 139 140 |
# File 'lib/countless/annotations.rb', line 138 def text @text end |
Class Method Details
.directories ⇒ Array<String>
Returns the currently configured directories.
157 158 159 160 |
# File 'lib/countless/annotations.rb', line 157 def self.directories @directories ||= Countless.configuration.annotations_directories.deep_dup end |
.extensions ⇒ Hash<RegExp => Proc>
Returns the currently configured file extension handlers.
188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/countless/annotations.rb', line 188 def self.extensions @extensions ||= begin patterns = Countless.configuration.annotation_patterns.values patterns.to_h do |conf| [ extensions_regexp(conf[:extensions], conf[:files] || []), conf[:regex] ] end end end |
.extensions_regexp(exts, files = []) ⇒ RegExp
Build a new extension regexp of the given extensions.
213 214 215 216 217 218 |
# File 'lib/countless/annotations.rb', line 213 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.
142 143 144 145 |
# File 'lib/countless/annotations.rb', line 142 def self.files @files ||= Countless.configuration.annotations_files.deep_dup end |
.register_directories(*dirs) ⇒ Object
Registers additional directories to be included.
165 166 167 |
# File 'lib/countless/annotations.rb', line 165 def self.register_directories(*dirs) directories.push(*dirs) end |
.register_extensions(*exts, &block) ⇒ Object
Registers new annotations file extension handlers.
204 205 206 |
# File 'lib/countless/annotations.rb', line 204 def self.register_extensions(*exts, &block) extensions[extensions_regexp(exts)] = block end |
.register_files(*dirs) ⇒ Object
Registers additional files to be included.
150 151 152 |
# File 'lib/countless/annotations.rb', line 150 def self.register_files(*dirs) files.push(*dirs) end |
.register_tags(*additional_tags) ⇒ Object
Registers additional tags.
181 182 183 |
# File 'lib/countless/annotations.rb', line 181 def self.(*) .push(*) end |
.tags ⇒ Array<String>
Returns the currently configured tags.
172 173 174 175 176 |
# File 'lib/countless/annotations.rb', line 172 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.
230 231 232 233 234 |
# File 'lib/countless/annotations.rb', line 230 def to_s( = {}) s = "[#{line.to_s.rjust(options[:indent])}] " s << "[#{tag}] " if [:tag] s << text end |