@@ -70,18 +70,19 @@ def initialize(id, **args, &block)
70
70
@summarizable = args [ :summarizable ] || false
71
71
@nullable = args [ :nullable ] || false
72
72
@null_values = args [ :null_values ] || [ nil , "" ]
73
- @format_using = args [ :format_using ] || nil
74
- @update_using = args [ :update_using ] || nil
73
+ @format_using = args [ :format_using ]
74
+ @update_using = args [ :update_using ]
75
+ @decorate = args [ :decorate ]
75
76
@placeholder = args [ :placeholder ]
76
- @autocomplete = args [ :autocomplete ] || nil
77
- @help = args [ :help ] || nil
78
- @default = args [ :default ] || nil
77
+ @autocomplete = args [ :autocomplete ]
78
+ @help = args [ :help ]
79
+ @default = args [ :default ]
79
80
@visible = args [ :visible ]
80
81
@as_avatar = args [ :as_avatar ] || false
81
- @html = args [ :html ] || nil
82
- @view = Avo ::ViewInquirer . new ( args [ :view ] ) || nil
83
- @value = args [ :value ] || nil
84
- @stacked = args [ :stacked ] || nil
82
+ @html = args [ :html ]
83
+ @view = Avo ::ViewInquirer . new ( args [ :view ] )
84
+ @value = args [ :value ]
85
+ @stacked = args [ :stacked ]
85
86
@for_presentation_only = args [ :for_presentation_only ] || false
86
87
@resource = args [ :resource ]
87
88
@action = args [ :action ]
@@ -154,45 +155,42 @@ def placeholder
154
155
def value ( property = nil )
155
156
return @value if @value . present?
156
157
157
- property ||= @for_attribute || id
158
+ property ||= @for_attribute || @ id
158
159
159
160
# Get record value
160
- final_value = record . send ( property ) if is_model? ( record ) && record . respond_to? ( property )
161
+ final_value = @ record. send ( property ) if is_model? ( @ record) && @ record. respond_to? ( property )
161
162
162
163
# On new views and actions modals we need to prefill the fields with the default value if value is nil
163
- if final_value . nil? && should_fill_with_default_value? && default . present?
164
+ if final_value . nil? && should_fill_with_default_value? && @ default. present?
164
165
final_value = computed_default_value
165
166
end
166
167
167
168
# Run computable callback block if present
168
- if computable && block . present?
169
- final_value = execute_block
169
+ if computable && @ block. present?
170
+ final_value = execute_context ( @block )
170
171
end
171
172
172
173
# Run the value through resolver if present
173
- if format_using . present?
174
- final_value = Avo ::ExecutionContext . new (
175
- target : format_using ,
176
- value : final_value ,
177
- record : record ,
178
- resource : resource ,
179
- view : view ,
180
- field : self ,
181
- include : self . class . included_modules
182
- ) . handle
174
+ if @format_using . present?
175
+ final_value = execute_context ( @format_using , value : final_value )
176
+ end
177
+
178
+ if @decorate . present? && @view . display?
179
+ final_value = execute_context ( @decorate , value : final_value )
183
180
end
184
181
185
182
final_value
186
183
end
187
184
188
- def execute_block
185
+ def execute_context ( target , ** extra_args )
189
186
Avo ::ExecutionContext . new (
190
- target : block ,
191
- record : record ,
192
- resource : resource ,
193
- view : view ,
187
+ target :,
188
+ record : @ record,
189
+ resource : @ resource,
190
+ view : @ view,
194
191
field : self ,
195
- include : self . class . included_modules
192
+ include : self . class . included_modules ,
193
+ **extra_args
196
194
) . handle
197
195
end
198
196
0 commit comments