-
-
Notifications
You must be signed in to change notification settings - Fork 300
Open
Labels
Back endDSL-relatedDeveloper Experience (DX)Needs researchTaskSomething to get doneSomething to get done
Description
In Avo we use blocks in many places and one of the caveats we noticed is that it's difficult to DRY them up. You'd have to create a new class or module, then a method and that method to return a block, which is not very nice.
module Extracted
def formatter
-> { format_this_value value }
end
end
field :name, as: :name, format_using: Extracted.formatterWe'd like to use anonymous classes for that
class Hey
def self.call
value.downcase
end
def self.to_proc
method(:call).to_proc
end
end
field :name, as: :name, format_using: HeyThis strategy should work, but it might give us trouble in blocks where we use nesting.
# avo.rb
self.main_menu = -> {
section do
group "name" do
link_to ...
end
end
}We need to do some kind of sorcery to support that. I believe @Paul-Bob did it with def fields.
We also need to abstract away some of that boilerplate, including the self.to_proc method.
I'm thinking about providing a class which the users can extend and just add their own call method on it and we can do the "sorcery" and the to_proc.
class Hey < Avo::BaseSomething
def self.call
value.downcase
end
end
field :name, as: :name, format_using: Hey
field :city, as: :name, format_using: HeyIn the menu example users can do something like this:
if user.admin?
AdminMenu.new(user).build
elsif user.manager?
ManagerMenu.new(user).build
else
OtherMenu.new(user).build
end
# config.main_menu = HeyMetadata
Metadata
Assignees
Labels
Back endDSL-relatedDeveloper Experience (DX)Needs researchTaskSomething to get doneSomething to get done
Type
Projects
Status
Triage