Skip to content

Commit

Permalink
delegate missing methods to view_context
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed Jun 26, 2023
1 parent f6e2b3f commit 93f323e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/avo/execution_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def initialize(**args)
end
end

# If you want this block to behave like a view you can delegate the missing methods to the view_context
#
# Ex: Avo::ExecutionContext.new(target: ..., delegate_missing_to: :view_context).handle
if args[:delegate_missing_to].present?
self.class.send(:delegate_missing_to, args[:delegate_missing_to])
end

# If target doesn't respond to call, we don't need to initialize the others attr_accessors.
return unless (@target = args[:target]).respond_to? :call

Expand Down
2 changes: 1 addition & 1 deletion lib/avo/fields/base_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def value(property = nil)

if @format_using.present?
# Apply the changes in the
Avo::ExecutionContext.new(target: @format_using, model: model, key: property, value: final_value, resource: resource, view: view, field: self).handle
Avo::ExecutionContext.new(target: @format_using, model: model, key: property, value: final_value, resource: resource, view: view, field: self, delegate_missing_to: :view_context).handle
else
final_value
end
Expand Down

0 comments on commit 93f323e

Please sign in to comment.