Sha256: e988b6f9edd11db087889fef1cdf0c578bdc6b88473903cafa7061353aaed49f

Contents?: true

Size: 1.08 KB

Versions: 35

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module LinkedRails
  class Sequence
    attr_accessor :node, :parent, :raw_members, :scope, :user_context
    alias read_attribute_for_serialization send

    def initialize(members, **opts)
      self.node = opts[:id] || RDF::Node.new
      self.parent = opts[:parent]
      self.raw_members = members
      self.scope = opts[:scope]
      self.user_context = opts[:user_context]
    end

    def iri(**_opts)
      node
    end
    alias id iri

    def members
      @members ||= apply_scope(
        raw_members.respond_to?(:call) ? raw_members.call : raw_members
      )
    end

    def preview_includes
      [:members]
    end

    def rdf_type
      self.class.iri
    end

    private

    def apply_scope(association)
      return association if scope == false

      policy_scope = scope || Pundit::PolicyFinder.new(association).scope!

      policy_scope.new(user_context, association).resolve
    end

    def item_iri(item)
      item.is_a?(RDF::Resource) ? item : item.iri
    end

    class << self
      def iri
        RDF[:Seq]
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
linked_rails-0.0.4.pre.g3aeec2263 app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.gacd5f04d4 app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.gb0b6aea40 app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.g792a1b887 app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.g58af47992 app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.g0ec6e30ca app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.g9e3bcac55 app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.g222bfeeca app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.gb254a2893 app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.g2c6c26e86 app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.ge881247c3 app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.gfabf7e9f5 app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.g8c045be3a app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.g8d7195543 app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.gfe77aae19 app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.gc866c1806 app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.g3e8f5731a app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.g58e27be7f app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.g96885856b app/models/linked_rails/sequence.rb
linked_rails-0.0.4.pre.g1faca9643 app/models/linked_rails/sequence.rb