Module: Seedable::Exporter::InstanceMethods

Defined in:
lib/seedable/exporter.rb

Overview

Extensions to all ActiveRecord classes to enable this class for import and export of data.

Use acts_as_seedable here to enable your classes to use this functionality.

Use from_seedable and to_seedable here to perform the serialization and deserialization.

Instance Method Summary collapse

Instance Method Details

#as_seedableObject

Returns hash of objects attributes and all included associations attributes.

Examples

json = @garage.as_seedable.to_json


143
144
145
146
147
148
# File 'lib/seedable/exporter.rb', line 143

def as_seedable
  includable = Helpers.traverse_includable_associations_from_instance(self)
  exceptions = Helpers.filterable_attributes(self)

  self.as_json(:include => includable, :except => exceptions)
end

#to_seedableObject

Performs render of as_seedable content into properly formatted JSON.

Examples

json = @garage.to_seedable


157
158
159
# File 'lib/seedable/exporter.rb', line 157

def to_seedable
  as_seedable.to_json
end