Module: Seedable::Importer::ClassMethods

Defined in:
lib/seedable/importer.rb

Overview

Seedable methods for loading serialized objects of unknown or disperse types into objects.

Use from_seedable here to load arrays of one or multiple types, or when you do not know what type of object the JSON represents to have it return the appropriate object.

Instance Method Summary collapse

Instance Method Details

#from_seedable(json) ⇒ Object

Takes JSON and builds objects from it. Returns either the object, or array of objects depending on input.

Parameters

  • json - A block of JSON.

Examples

array_of_objects = Seedable.from_seedable(json_containing_array_of_hashes)
object = Seedable.from_seedable(json_for_one_object)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/seedable/importer.rb', line 28

def from_seedable(json)
  objects = Helpers.parse_seedable(json)

  if Array === objects
    objects.map do |object| 
      objects_from_serialized_hash(object)
    end
  else
    objects_from_serialized_hash(objects)
  end
end