Module: ActiveRecord::RelationsAnnotations::ClassMethods

Defined in:
lib/active_record/relations_annotations.rb

Instance Method Summary collapse

Instance Method Details

#annotate(**values) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/active_record/relations_annotations.rb', line 12

def annotate(**values)
  annotated.tap do |relation|
    values.each do |key, value|
      relation.instance_variable_get(:@_annotations)[key.to_sym] = value
    end
  end
end

#annotatedObject

This should never be explicitly called, but if done, nothing should happen



26
27
28
29
30
31
32
# File 'lib/active_record/relations_annotations.rb', line 26

def annotated
  all.tap do |relation|
    if relation.instance_variable_get(:@_annotations).nil?
      relation.instance_variable_set(:@_annotations, OpenStruct.new)
    end
  end
end

#annotationsObject



20
21
22
# File 'lib/active_record/relations_annotations.rb', line 20

def annotations
  annotated.instance_variable_get(:@_annotations)
end