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

Use trailblazer-option over declarative-option and upgrade declarative-builder #492

Merged
merged 2 commits into from
Jun 11, 2021

Conversation

yogeshjain999
Copy link
Member

  • Upgrade declarative-builder version (referring to the reported issue)
  • Replace declarative-option with trailblazer-option as declarative-builder uses same.

# This is identical to `Representable::Option`.
module Cell
# Extend `Trailblazer::Option` to support static values as callables too.
class Option < ::Trailblazer::Option
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apotonick This is identical to Representable::Option.

Should we move Cell::Option and Cell::Options in trb-option instead ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, do we have use on a generic level?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, kind of.

  1. Handling static values might be needed somewhere else.
  2. But Cell::Options isn't generic. We can keep it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is, do we have the static requirement anywhere else (e.g. Reform)? If yes, we can extract it. On the other hand, we can always do that later. 🥱

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, we've the static requirement in reform, disposable and representer. Currently, it is done in representer itself and it's being used in other 2.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, supporting Callable objects between these 2 types of gems (representable, reform, cells etc and trb-activity, DSL etc) is little different i.e.

  1. Extending Uber::Callable for identifying callable object.
  2. trb-activity and friends doesn't need static type support.

So other way is we should not mix these 2 types in trb-option but keep separate. If it's ok, then we can keep Cell::Option here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Reg. Uber::Callable, that one we should dump ASAP. Isn't it better if we always treat an object callable, anyway?
  2. Hm, but it also doesn't hurt to have it there instead of maintaining 4 different Options, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm yeah. The problem with treating every object callable is we can't distinguish between them and static options (some static options also includes modules, classes etc), apart from call method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, ok right, so that was why I initially introduced Uber::Callable, damn! Hm... how could we do that in the future?

Ok, in that case, we won't move that behavior to TRB, for now. 🍰

Copy link
Member Author

@yogeshjain999 yogeshjain999 Jun 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct (i.e. distinction between static and callable objects isn't needed in TRB). So we can merge this PR.

Uber::Callable is a nice alternative to mark callables for cells and representable friends for now.
In future versions, maybe we can have restrictions on static options (or ways to avoid them) ?

# Extend `Trailblazer::Option` to support static values as callables too.
class Option < ::Trailblazer::Option
def self.callable?(value)
[Proc, Symbol, Uber::Callable].any?{ |kind| value.is_a?(kind) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this change. We quite frequently pass symbols as cell options, is this going to to try and evaluate them as a method name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samstickland This behaviour is same as the previous Declatative::Option. The difference with Trailblazer::Option in the API only, and it's compatible with Ruby-3.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yogeshjain999 We do have static values covered in the cells suite, I guess? 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh really ? I thought those are covered in declarative-option directly.

@yogeshjain999 yogeshjain999 merged commit e20413e into trailblazer:master Jun 11, 2021
@yogeshjain999 yogeshjain999 deleted the use-trb-option branch June 11, 2021 03:27
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