Module: ActiveFedora::LoadableFromJson

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/active_fedora/loadable_from_json.rb

Defined Under Namespace

Classes: SolrBackedMetadataFile, SolrBackedResource

Instance Method Summary collapse

Instance Method Details

#init_with_json(json) ⇒ Object

Parameters:

  • json (String)

    json to be parsed into attributes


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/active_fedora/loadable_from_json.rb', line 101

def init_with_json(json)
  attrs = JSON.parse(json)
  id = attrs.delete('id')

  @ldp_source = build_ldp_resource(id)
  @association_cache = {}
  datastream_keys = self.class.child_resource_reflections.keys
  datastream_keys.each do |key|
    attached_files[key] = SolrBackedMetadataFile.new
  end
  @resource = SolrBackedResource.new(self.class)
  self.attributes = attrs.slice(*self.class.attribute_names)
  # TODO Should we clear the change tracking, or make this object Read-only?

  run_callbacks :find
  run_callbacks :initialize
  freeze
  self
end