Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an implicit partial for every V2 view #488

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

jhollinger
Copy link
Contributor

@jhollinger jhollinger commented Nov 19, 2024

I've been thinking about an impendance mismatch between V1 and V2 that will make upgrading more difficult (whether manual or scripted). This is an attempt to patch over it without changing any of V2's semantics. Curious what everyone thinks.

Consider the following V1 Blueprint:

class WidgetBlueprint < Blueprinter::Base
  view :normal do
    field :name
  end

  view :extended do
    include_view :normal
    field :description
  end
end

There are currently two ways to represent this in V2: inheritance and partials.

# Inheritance has the drawback that the extended view's name will change to
# "normal.extended". This will require callsites to be updated with the new name. 
class WidgetBlueprint < Blueprinter::V2::Base
  view :normal do
    field :name

    view :extended do
      field :description
    end
  end
end

# Using partials avoids that, but looks...not great. A converted codebase would be
# full of Blueprints defined like this:
class WidgetBlueprint < Blueprinter::V2::Base
  partial :normal do
    field :name
  end

  view :normal do
    use :normal
  end

  view :extended do
    use :normal
    field :description
  end
end

What this PR adds

This PR automatically creates a partial for every view, allowing V2 to act much like V1 w/r/t to "including" other views.

class WidgetBlueprint < Blueprinter::V2::Base
  view :normal do
    field :name
  end

  view :extended do
    use :normal
    field :description
  end
end

@jhollinger jhollinger marked this pull request as ready for review November 19, 2024 22:26
@jhollinger jhollinger requested review from ritikesh and a team as code owners November 19, 2024 22:26
@jhollinger jhollinger merged commit 37a2383 into release-2.0 Dec 11, 2024
1 check passed
@jhollinger jhollinger deleted the jh/implicit-partials branch December 11, 2024 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants