Sha256: c9e5651ed4e29d155243491359c7e91e864ff67bef1b1d09e74fac54e9bda173

Contents?: true

Size: 1014 Bytes

Versions: 9

Compression:

Stored size: 1014 Bytes

Contents

require 'active_support'
require 'active_support/core_ext/module/delegation'

module ActiveTriples::Identifiable
  extend ActiveSupport::Concern

  delegate :rdf_subject, :type, to: :resource

  ##
  # @return [ActiveTriples::Resource] a resource that contains this object's
  # graph.
  def resource
   @resource ||= resource_class.new(to_uri)
  end

  def parent
    @parent ||= resource.parent
  end

  def parent=(val)
    @parent = val
  end

  ##
  # @return [String] a uri or slug
  def to_uri
    return id if respond_to? :id and !resource_class.base_uri.nil?
    raise NotImplementedError
  end

  private
    def resource_class
      self.class.resource_class
    end

  public

    module ClassMethods

      delegate :configure, :property, :properties, to: :resource_class

      def resource_class
        @resource_class ||= self.const_set(:GeneratedResourceSchema, Class.new(ActiveTriples::Resource))
      end

      def from_uri(uri, *args)
        raise NotImplementedError
      end
    end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
active-triples-0.7.6 lib/active_triples/identifiable.rb
active-triples-0.7.5 lib/active_triples/identifiable.rb
active-triples-0.7.4 lib/active_triples/identifiable.rb
active-triples-0.7.3 lib/active_triples/identifiable.rb
active-triples-0.7.2 lib/active_triples/identifiable.rb
active-triples-0.7.1 lib/active_triples/identifiable.rb
active-triples-0.8.1 lib/active_triples/identifiable.rb
active-triples-0.8.0 lib/active_triples/identifiable.rb
active-triples-0.7.0 lib/active_triples/identifiable.rb