Skip to content

Commit

Permalink
refactor: rename model to record in fill_field methods (#3033)
Browse files Browse the repository at this point in the history
* refactor: rename `model` to `record` in `fill_field` methods

* lint
  • Loading branch information
Paul-Bob authored Jul 24, 2024
1 parent b47c312 commit 2585b05
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
14 changes: 7 additions & 7 deletions lib/avo/fields/belongs_to_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,25 +195,25 @@ def to_permitted_param
foreign_key.to_sym
end

def fill_field(model, key, value, params)
return model unless model.methods.include? key.to_sym
def fill_field(record, key, value, params)
return record unless record.methods.include? key.to_sym

if polymorphic_as.present?
valid_model_class = valid_polymorphic_class params[:"#{polymorphic_as}_type"]

model.send(:"#{polymorphic_as}_type=", valid_model_class)
record.send(:"#{polymorphic_as}_type=", valid_model_class)

# If the type is blank, reset the id too.
if valid_model_class.blank?
model.send(:"#{polymorphic_as}_id=", nil)
record.send(:"#{polymorphic_as}_id=", nil)
else
model.send(:"#{polymorphic_as}_id=", params["#{polymorphic_as}_id"])
record.send(:"#{polymorphic_as}_id=", params["#{polymorphic_as}_id"])
end
else
model.send("#{key}=", value)
record.send(:"#{key}=", value)
end

model
record
end

def valid_polymorphic_class(possible_class)
Expand Down
12 changes: 6 additions & 6 deletions lib/avo/fields/date_time_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ def edit_formatted_value
value.utc.iso8601
end

def fill_field(model, key, value, params)
def fill_field(record, key, value, params)
if value.in?(["", nil])
model.send(:"#{id}=", value)
record.send(:"#{id}=", value)

return model
return record
end

return model if value.blank?
return record if value.blank?

model.send(:"#{id}=", utc_time(value))
record.send(:"#{id}=", utc_time(value))

model
record
end

def utc_time(value)
Expand Down
8 changes: 4 additions & 4 deletions lib/avo/fields/files_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ def to_permitted_param
{"#{id}": []}
end

def fill_field(model, key, value, params)
return model unless model.methods.include? key.to_sym
def fill_field(record, key, value, params)
return record unless record.methods.include? key.to_sym

value.each do |file|
# Skip empty values
next unless file.present?

model.send(key).attach file
record.send(key).attach file
end

model
record
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/avo/fields/has_one_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ def frame_url
.to_s
end

def fill_field(model, key, value, params)
def fill_field(record, key, value, params)
if value.blank?
related_record = nil
else
related_class = model.class.reflections[name.to_s.downcase].class_name
related_class = record.class.reflections[name.to_s.downcase].class_name
related_resource = Avo.resource_manager.get_resource_by_model_class(related_class)
related_record = related_resource.find_record value
end

model.public_send(:"#{key}=", related_record)
record.public_send(:"#{key}=", related_record)

model
record
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/avo/fields/key_value_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ def options
}
end

def fill_field(model, key, value, params)
def fill_field(record, key, value, params)
begin
new_value = JSON.parse(value)
rescue
new_value = {}
end

model.send("#{key}=", new_value)
record.send(:"#{key}=", new_value)

model
record
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/avo/fields/location_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def as_lat_long_value(get)
def fill_field(record, key, value, params)
if value_as_array?
latitude_field, longitude_field = stored_as
record.send("#{latitude_field}=", value[latitude_field])
record.send("#{longitude_field}=", value[longitude_field])
record.send(:"#{latitude_field}=", value[latitude_field])
record.send(:"#{longitude_field}=", value[longitude_field])
record
else
super(record, key, value.split(","), params)
Expand Down Expand Up @@ -78,7 +78,7 @@ def assign_value(record:, value:)
return super if stored_as.blank?

stored_as.each_with_index do |database_id, index|
record.send("#{database_id}=", value[index])
record.send(:"#{database_id}=", value[index])
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/avo/fields/time_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ def edit_formatted_value
value.utc.iso8601
end

def fill_field(model, key, value, params)
def fill_field(record, key, value, params)
if value.in?(["", nil])
model.send(:"#{id}=", value)
record.send(:"#{id}=", value)

return model
return record
end

return model if value.blank?
return record if value.blank?

model.send(:"#{id}=", utc_time(value))
record.send(:"#{id}=", utc_time(value))

model
record
end
end
end
Expand Down

0 comments on commit 2585b05

Please sign in to comment.