Sha256: 5755a4a3fb973bc2b5f05f6a45b4344491ad5c0886e04fed0d80004dd1b1c9a5

Contents?: true

Size: 1.32 KB

Versions: 36

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module LinkedRails
  module Policy
    module AttributeConditions
      extend ActiveSupport::Concern

      private

      def check_has_properties(properties)
        properties.all? { |k, v| @record.send(k).nil? != v }
      end

      def check_has_values(values)
        values.all? { |k, v| @record.send(k) == v }
      end

      def check_new_record(boolean)
        @record.new_record? == boolean
      end

      module ClassMethods
        private

        def has_properties_shapes(properties)
          properties.map do |key, boolean|
            SHACL::PropertyShape.new(
              path: policy_class.predicate_for_key(key),
              max_count: boolean ? nil : 0,
              min_count: boolean ? 1 : nil
            )
          end
        end

        def has_values_shapes(values)
          values.map do |key, value|
            enum = RDF::Serializers.serializer_for(policy_class).enum_options(key).try(:[], value)
            santized_value = enum ? -> { enum.iri } : value

            SHACL::PropertyShape.new(
              path: policy_class.predicate_for_key(key),
              has_value: santized_value
            )
          end
        end

        def new_record_shapes(boolean)
          has_properties_shapes(created_at: !boolean)
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

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