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) {|self| ... } ⇒ Object

Parameters:

  • json (String)

    json to be parsed into attributes

Yields:

  • (self)

    Yields self after attributes from json have been assigned but before callbacks and before the object is frozen.



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/active_fedora/loadable_from_json.rb', line 121

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?

  yield self if block_given?

  run_callbacks :find
  run_callbacks :initialize
  freeze
  self
end