Skip to content

Commit

Permalink
Create a separate resource class for each ActiveFedora::Base subclass
Browse files Browse the repository at this point in the history
This ensures that the schemas from different AF::Base subclasses don't
end up merged onto the ActiveTriples::Resource class
  • Loading branch information
jcoyne committed Nov 3, 2014
1 parent 58991c6 commit 3e37ca0
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/active_fedora/fedora_attributes.rb
Expand Up @@ -52,17 +52,23 @@ def uri
#
# set_value, get_value, and property accessors are delegated to this object.
def resource
@resource ||= begin
r = @orm.graph
r.class.properties.merge(self.class.properties).each do |property, config|
r.class.property(config.term,
predicate: config.predicate,
class_name: config.class_name,
multivalue: config.multivalue)
end
r
end
@resource ||= resource_class.new(@orm.graph.rdf_subject, @orm.graph)
end

private
# We make a unique class, because properties belong to a class.
# This keeps properties from different objects separate.
def resource_class
@generated_resource_class ||= begin
klass = self.class.const_set(:GeneratedResourceSchema, Class.new(ActiveTriples::Resource))
klass.properties.merge(self.class.properties).each do |property, config|
klass.property(config.term,
predicate: config.predicate,
class_name: config.class_name,
multivalue: config.multivalue)
end
klass
end
end
end
end

0 comments on commit 3e37ca0

Please sign in to comment.