lib/active_triples/elasticsearch/serializable.rb
##
# Return a qname-based JSON representation
#
# @param [Hash] opts options for serializaiton
# @option opts [Boolean] :related whether to include related resources
# @return [Hash] a serialized 'qname' version of the resource
Return a qname-based JSON representation
Return a qname - based JSON representation
def as_qname(opts = {})
        qname_hash = type.empty? ? {} : { rdf: { type: type.first.pname } }
        resource_class.properties.each do |field_name, property|
          ns, name = property.predicate.qname
          qname_hash[ns] ||= {}
          if relations[field_name]
            qname_hash[ns][name] = opts[:related] ? send(field_name).to_a.map(&:as_qname) : send(field_name).to_a.map { |obj| "#{obj.class.name.underscore.pluralize}:#{obj.id}" }
          end
          if fields[field_name]
            qname_hash[ns][name] = read_attribute(field_name)
          end
          qname_hash[ns].delete_if { |_k, v| v.blank? }
        end
        { rdfs: { label: update_resource(opts.slice :related).rdf_label } }.merge qname_hash
      end
def as_qname ( opts = { } ) qname_hash = type . empty? ? { } : { rdf : { type : type . first . pname } } resource_class . properties . each do | field_name , property | ns , name = property . predicate . qname qname_hash [ ns ] ||= { } if relations [ field_name ] qname_hash [ ns ] [ name ] = opts [ :related ] ? send ( field_name ) . to_a . map ( & :as_qname ) : send ( field_name ) . to_a . map { | obj | "#{obj.class.name.underscore.pluralize}:#{obj.id}" } end if fields [ field_name ] qname_hash [ ns ] [ name ] = read_attribute ( field_name ) end qname_hash [ ns ] . delete_if { | _k , v | v . blank? } end { rdfs : { label : update_resource ( opts . slice :related ) . rdf_label } } . merge qname_hash end
Return a qname-based JSON representation
Return a qname - based JSON representation
# Remove empty/null values # Insert labels for boosting search score
a serialized 'qname' version of the resource
a serialized ' qname ' version of the resource
Hash
opts
:related whether to include related resources
: related whether to include related resources
opts options for serializaiton
opts options for serializaiton