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

ApplicationBlueprinter pattern #80

Closed
toobulkeh opened this issue May 18, 2018 · 6 comments
Closed

ApplicationBlueprinter pattern #80

toobulkeh opened this issue May 18, 2018 · 6 comments
Labels
enhancement New feature or request help wanted Anyone is welcome to open a pull request to fix this issue

Comments

@toobulkeh
Copy link

Is there any reason not to use the Application pattern with Blueprinter?

application_blueprint.rb:

class ApplicationBlueprint < Blueprinter::Base
  identifier :id
end

user_blueprint.rb:

class UserBlueprint < ApplicationBlueprint
  fields :name
end
@philipqnguyen
Copy link
Contributor

Definitely! There is no reason not to use the ApplicationBlueprint pattern. It is already a pattern that Procore is using internally as well and I highly recommend using that pattern in your projects.

@toobulkeh
Copy link
Author

Apparently extending a blueprint with an identifier removes it from the returned value. Is that expected?

IE, I had to add this line back to all of our blueprints:

identifier :id

@philipqnguyen
Copy link
Contributor

I did a short test of your example locally and I can confirm you're correct and that it does not work. Will have to look into it further.

@Systho
Copy link

Systho commented Aug 28, 2018

The problem is the view collection is a class instance variable, thus it's not the same in the parent class and in the subclass.

I've personally fixed the problem with this snippet in my BaseBlueprint

  class BaseBlueprint < Blueprinter::Base

    def self.inherited(sub_class)
      sub_class.identifier :id
    end

end

@philipqnguyen
Copy link
Contributor

@Systho you're right, class instance variable is the problem. I think you have the right solution.

@philipqnguyen philipqnguyen added enhancement New feature or request help wanted Anyone is welcome to open a pull request to fix this issue good first PR labels Aug 28, 2018
@philipqnguyen
Copy link
Contributor

resolved by #105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Anyone is welcome to open a pull request to fix this issue
Projects
None yet
Development

No branches or pull requests

3 participants