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.
192 193 194 |
# File 'lib/rbbt/annotations.rb', line 192 def annotations @annotations end |
#masked_annotations ⇒ Object
Returns the value of attribute masked_annotations.
192 193 194 |
# File 'lib/rbbt/annotations.rb', line 192 def masked_annotations @masked_annotations end |
Class Method Details
.extended(object) ⇒ Object
308 309 310 311 312 |
# File 'lib/rbbt/annotations.rb', line 308 def self.extended(object) object.module_eval do include Annotated end end |
Instance Method Details
#annotation(*list) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/rbbt/annotations.rb', line 206 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
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/rbbt/annotations.rb', line 237 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
301 302 303 304 305 306 |
# File 'lib/rbbt/annotations.rb', line 301 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
314 315 316 317 |
# File 'lib/rbbt/annotations.rb', line 314 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
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/rbbt/annotations.rb', line 284 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
230 231 232 233 234 235 |
# File 'lib/rbbt/annotations.rb', line 230 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
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/rbbt/annotations.rb', line 263 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
202 203 204 |
# File 'lib/rbbt/annotations.rb', line 202 def unmasked_annotations annotations - masked_annotations end |