Class: Delayed::PsychExt::YAMLTree

Inherits:
Psych::Visitors::YAMLTree
  • Object
show all
Defined in:
lib/delayed/psych_ext.rb

Instance Method Summary collapse

Instance Method Details

#accept(target) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/delayed/psych_ext.rb', line 31

def accept(target)
  if defined?(ActiveRecord::Base) && target.is_a?(ActiveRecord::Base)
    tag = ['!ruby/ActiveRecord', target.class.name].compact.join(':')
    map = @emitter.start_mapping(nil, tag, false, Psych::Nodes::Mapping::BLOCK)
    register(target, map)
    @emitter.scalar('attributes', nil, nil, true, false, Psych::Nodes::Mapping::ANY)
    accept target.attributes.slice(target.class.primary_key)

    @emitter.end_mapping
  else
    super
  end
end