module Gearbox::AdHocProperties
Allows a model instance to add a new property at runtime.
This is a (small) tip of the hat towards the flexibility offered by using a graph instead of a schema to govern the data store.
Attributes
id[RW]
Getter and setter for an id property. Will be adjusted when I decide whether to mixin ActiveModel
Public Instance Methods
add_property(accessor, predicate, object)
click to toggle source
Add a property without defining it on the class. This will stay, will use the subject, and the regular infrastructure. @param [Symbol] accessor, the new field being created. @param [RDF::Statement] predicate, the predicate for the new field. @param [Any] The value to store
# File lib/gearbox/mixins/ad_hoc_properties.rb, line 35 def add_property(accessor, predicate, object) new_property = RDF::Statement.new(bnode, predicate, object) attributes_list[accessor] = new_property end
attributes_list()
click to toggle source
Stored attributes @return [RDFCollection]
# File lib/gearbox/mixins/ad_hoc_properties.rb, line 16 def attributes_list @attributes_list ||= RDFCollection.new end
bnode()
click to toggle source
Generates or gets a blank node, based on the id. Will be replaced by subject. @return [RDF::Node]
# File lib/gearbox/mixins/ad_hoc_properties.rb, line 23 def bnode return @bnode if @bnode self.id ||= UUID.generate safe_id = "#{self.class.name}_#{id}".gsub(/[^A-Za-z0-9\-_]/, '_') @bnode = RDF::Node(safe_id) end