TheProlog / prolog-use_cases

Use-case layer for Meldd/Prolog application.
0 stars 0 forks source link

Update to current dry-rb Gems #60

Closed jdickey closed 7 years ago

jdickey commented 8 years ago

dry-types 0.8.0 (which dry-validation 0.8.0 depends on) changes the meaning of a Dry::Types::Value from

Create a value object where, once instantiated, the attribute values cannot be changed; e.g., by assigning a new value to an attribute.

to

Create a "deep frozen" value object where, once instantiated, the attribute values cannot be changed, and each attribute value references an immutable object instance.

That's significantly different, and will bite code such as this class

# frozen_string_literal: true

require 'prolog/support/dry_types_setup'

module Prolog
  module UseCases
    # Reports whether a current user is authorised to Respond to a Proposed
    # Contribution and that the Proposal has not yet been Responded to.
    class AuthoriseContributionResponse
      # Collect all collaborators for Authorise Contribution Response use case
      # in a value object.
      class Collaborators < Dry::Types::Value
        attribute :article_repo, Types::Class
        attribute :authoriser, Types::Class
        attribute :contribution_repo, Types::Class
      end # class Prolog::UseCases::AuthoriseContributionResponse::Collaborators
    end # class Prolog::UseCases::AuthoriseContributionResponse
  end
end

Here, the article_repo and contribution_repo are deeply frozen when, fairly obviously, there might well be cases when that's not desirable (adding or updating records would probably mutate the state of the object instances).

This issue is a reminder that we should rethink our usage of Dry::Types::Value in cases like this. In other cases where the update to 0.8.0 Broke Things, the broken code should be fixed.