Class: Ree::LinkValidator
Instance Method Summary collapse
-
#call(object, link) ⇒ nil
Validates existance and uniqueness of linked object.
-
#initialize(packages_facade) ⇒ LinkValidator
constructor
A new instance of LinkValidator.
Constructor Details
#initialize(packages_facade) ⇒ LinkValidator
Returns a new instance of LinkValidator.
4 5 6 |
# File 'lib/ree/core/link_validator.rb', line 4 def initialize(packages_facade) @packages_facade = packages_facade end |
Instance Method Details
#call(object, link) ⇒ nil
Validates existance and uniqueness of linked object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ree/core/link_validator.rb', line 12 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 |