Sha256: eb272527ae04b7a1bc3c3b6c333289b2ed20f98b582b96368bb1a0a198b5b335

Contents?: true

Size: 1.11 KB

Versions: 33

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal  = true

class Ree::LinkValidator
  def initialize(packages_facade)
    @packages_facade = packages_facade
  end
  
  # Validates existance and uniqueness of linked object
  # @param [Ree::Object] object
  # @param [Ree::ObjectLink] link
  # @return [nil]
  def call(object, link)
    link_package = @packages_facade.get_package(link.package_name)
    link_object = link_package.get_object(link.object_name)

    if !link_object
      msg = <<~DOC
        object: :#{object.name}
        path: #{Ree::PathHelper.abs_object_path(object)}
        error: Unable to find  :#{link.object_name} in :#{link.package_name} package
      DOC

      raise Ree::Error.new(msg, :invalid_dsl_usage)
    end

    existing_link = link_object.links.detect do |inj|
      inj.object_name == link.object_name && inj.package_name == link.package_name
    end

    if existing_link
      msg = <<~DOC
        object: :#{object.name}
        path: #{Ree::PathHelper.abs_object_path(object)}
        error: Duplicate link :#{link.object_name}
      DOC

      raise Ree::Error.new(msg, :invalid_dsl_usage)
    end

    nil
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
ree-1.0.32 lib/ree/core/link_validator.rb
ree-1.0.31 lib/ree/core/link_validator.rb
ree-1.0.30 lib/ree/core/link_validator.rb
ree-1.0.29 lib/ree/core/link_validator.rb
ree-1.0.28 lib/ree/core/link_validator.rb
ree-1.0.27 lib/ree/core/link_validator.rb
ree-1.0.26 lib/ree/core/link_validator.rb
ree-1.0.25 lib/ree/core/link_validator.rb
ree-1.0.24 lib/ree/core/link_validator.rb
ree-1.0.23 lib/ree/core/link_validator.rb
ree-1.0.22 lib/ree/core/link_validator.rb
ree-1.0.21 lib/ree/core/link_validator.rb
ree-1.0.20 lib/ree/core/link_validator.rb
ree-1.0.19 lib/ree/core/link_validator.rb
ree-1.0.18 lib/ree/core/link_validator.rb
ree-1.0.17 lib/ree/core/link_validator.rb
ree-1.0.16 lib/ree/core/link_validator.rb
ree-1.0.15 lib/ree/core/link_validator.rb
ree-1.0.14 lib/ree/core/link_validator.rb
ree-1.0.13 lib/ree/core/link_validator.rb