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.
194 195 196 |
# File 'lib/rbbt/annotations.rb', line 194 def annotations @annotations end |
#masked_annotations ⇒ Object
Returns the value of attribute masked_annotations.
194 195 196 |
# File 'lib/rbbt/annotations.rb', line 194 def masked_annotations @masked_annotations end |
Class Method Details
.extended(object) ⇒ Object
310 311 312 313 314 |
# File 'lib/rbbt/annotations.rb', line 310 def self.extended(object) object.module_eval do include Annotated end end |
Instance Method Details
#annotation(*list) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/rbbt/annotations.rb', line 208 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
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/rbbt/annotations.rb', line 239 def clean_and_setup_hash(object, hash) object.instance_variable_set(:@annotation_values, nil) if object.instance_variable_get(:@annotation_values).nil? 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.include? "|" 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
303 304 305 306 307 308 |
# File 'lib/rbbt/annotations.rb', line 303 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
316 317 318 319 |
# File 'lib/rbbt/annotations.rb', line 316 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
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/rbbt/annotations.rb', line 286 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) setup_positional(object, *values[0..-2]) if values.length > 1 clean_and_setup_hash(object, hash) else setup_positional(object, *values) end object end |
#setup_hash(object, values) ⇒ Object
232 233 234 235 236 237 |
# File 'lib/rbbt/annotations.rb', line 232 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
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/rbbt/annotations.rb', line 265 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
204 205 206 |
# File 'lib/rbbt/annotations.rb', line 204 def unmasked_annotations annotations - masked_annotations end |