Class: UniversalID::Extensions::ActiveRecordBasePacker

Inherits:
Object
  • Object
show all
Defined in:
lib/universalid/extensions/active_record/base_packer.rb

Constant Summary collapse

HAS_MANY_ASSOCIATIONS =

TODO: implement support for has_one

ActiveRecord::Reflection::HasOneReflection

TODO: implement support for has_and_belongs_to_many

ActiveRecord::Reflection::HasAndBelongsToManyReflection
[
  ActiveRecord::Reflection::HasManyReflection
]
DESCENDANTS_KEY =
"uid:descendants"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ ActiveRecordBasePacker

Returns a new instance of ActiveRecordBasePacker.



22
23
24
# File 'lib/universalid/extensions/active_record/base_packer.rb', line 22

def initialize(record)
  @record = record
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



20
21
22
# File 'lib/universalid/extensions/active_record/base_packer.rb', line 20

def record
  @record
end

Instance Method Details

#pack_with(packer) ⇒ Object



26
27
28
29
# File 'lib/universalid/extensions/active_record/base_packer.rb', line 26

def pack_with(packer)
  packer.write record.class.name
  packer.write packable_attributes
end

#prepack_database_optionsObject



37
38
39
# File 'lib/universalid/extensions/active_record/base_packer.rb', line 37

def prepack_database_options
  prepack_options.database_options
end

#prepack_optionsObject



31
32
33
34
35
# File 'lib/universalid/extensions/active_record/base_packer.rb', line 31

def prepack_options
  options = record.instance_variable_get(:@_uid_prepack_options)
  options = UniversalID::PrepackOptions.new unless options.is_a?(UniversalID::PrepackOptions)
  options
end