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



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/active_fedora/loadable_from_json.rb', line 109

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 = adapt_attributes(attrs)
  # TODO Should we clear the change tracking, or make this object Read-only?

  run_callbacks :find
  run_callbacks :initialize
  freeze
  self
end