Module: Annotation
- Defined in:
- lib/rbbt/annotations.rb
Overview
{{{ ANNOTATION
Instance Attribute Summary collapse
-
#annotations ⇒ Object
Returns the value of attribute annotations.
-
#masked_annotations ⇒ Object
Returns the value of attribute masked_annotations.
Class Method Summary collapse
Instance Method Summary collapse
- #annotation(*list) ⇒ Object
- #clean_and_setup_hash(object, hash) ⇒ Object
- #fast_setup(object, hash, shared = false) ⇒ Object
- #included(mod) ⇒ Object
- #setup(object, *values) ⇒ Object
- #setup_hash(object, values) ⇒ Object
- #setup_positional(object, *values) ⇒ Object
- #unmasked_annotations ⇒ Object
Instance Attribute Details
#annotations ⇒ Object
Returns the value of attribute annotations.
187 188 189 |
# File 'lib/rbbt/annotations.rb', line 187 def annotations @annotations end |
#masked_annotations ⇒ Object
Returns the value of attribute masked_annotations.
187 188 189 |
# File 'lib/rbbt/annotations.rb', line 187 def masked_annotations @masked_annotations end |
Class Method Details
.extended(object) ⇒ Object
301 302 303 304 305 |
# File 'lib/rbbt/annotations.rb', line 301 def self.extended(object) object.module_eval do include Annotated end end |
Instance Method Details
#annotation(*list) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/rbbt/annotations.rb', line 201 def annotation(*list) list.each do |annot| next if annotations.include? annot.to_sym annotations << annot.to_sym # Getter self.send(:define_method, annot.to_s) do annotation_values[annot] end # Setter self.send(:define_method, "#{ annot}=") do |value| if @shared_annotations detach_annotations # avoid side effects end reset annotation_values[annot] = value end end end |
#clean_and_setup_hash(object, hash) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/rbbt/annotations.rb', line 232 def clean_and_setup_hash(object, hash) annotation_values = object.instance_variable_get(:@annotation_values) annotation_values = annotation_values.nil? ? {} : annotation_values.dup annotation_values.instance_variable_set(:@annotation_md5, nil) hash.each do |key, value| begin next unless @annotations.include?(key = key.to_sym) rescue next end value = value.split("|") if String === value and value.index "|" annotation_values[key] = value end object.instance_variable_set(:@annotation_values, annotation_values) object.instance_variable_set(:@shared_annotations, false) object.reset object end |
#fast_setup(object, hash, shared = false) ⇒ Object
294 295 296 297 298 299 |
# File 'lib/rbbt/annotations.rb', line 294 def fast_setup(object, hash, shared = false) object.extend self object.extend AnnotatedArray if Array === object object.instance_variable_set(:@annotation_values, hash) object.instance_variable_set(:@shared_annotations, true) if shared end |
#included(mod) ⇒ Object
307 308 309 310 |
# File 'lib/rbbt/annotations.rb', line 307 def included(mod) mod.instance_variable_set(:@annotations, self.annotations.dup) mod.instance_variable_set(:@masked_annotations, self.masked_annotations.dup) end |
#setup(object, *values) ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/rbbt/annotations.rb', line 278 def setup(object, *values) return object if object.nil? object.extend self object.extend AnnotatedArray if Array === object object.instance_variable_set(:@annotation_types, nil) if Hash === (hash = values.last) clean_and_setup_hash(object, hash) else setup_positional(object, *values) end object end |
#setup_hash(object, values) ⇒ Object
225 226 227 228 229 230 |
# File 'lib/rbbt/annotations.rb', line 225 def setup_hash(object, values) object.instance_variable_set(:@annotation_values, values) object.instance_variable_set(:@shared_annotations, true) object.reset object end |
#setup_positional(object, *values) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/rbbt/annotations.rb', line 257 def setup_positional(object, *values) annotation_values = object.instance_variable_get(:@annotation_values) annotation_values = annotation_values.nil? ? {} : annotation_values.dup annotation_values.instance_variable_set(:@annotation_md5, nil) annotations.each_with_index do |name,i| value = values[i] value = value.split("|") if String === value and value.include? "|" annotation_values[name] = value end object.instance_variable_set(:@annotation_values, annotation_values) object.reset object end |
#unmasked_annotations ⇒ Object
197 198 199 |
# File 'lib/rbbt/annotations.rb', line 197 def unmasked_annotations annotations - masked_annotations end |