Skip to content

Commit

Permalink
Memoize the ActiveForce::Mapping#mappings Hash since it is based on… (
Browse files Browse the repository at this point in the history
#41)

* Memoize the `ActiveForce::Mapping#mappings` Hash since it is based on the fields and those are generally only set when the class is loaded.  Also use `Hash#key` which returns the key for a value rather than `Hash#invert` which creates a new Hash with key/value inverted.

* Update CHANGELOG.
  • Loading branch information
asedge authored May 1, 2023
1 parent 1d315b0 commit 896823c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Not released

- Add `.to_json` and `.as_json` to `SObject` to allow JSON serialization (https://github.com/Beyond-Finance/active_force/pull/37)
- Memoize the `ActiveForce::Mapping#mappings` Hash since it is based on the fields and those are generally only set when the class is loaded. Also use `Hash#key` which returns the key for a value rather than `Hash#invert` which creates a new Hash with key/value inverted. (https://github.com/Beyond-Finance/active_force/pull/41)

## 0.13.0

Expand Down
2 changes: 1 addition & 1 deletion lib/active_force/mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize model
end

def mappings
Hash[fields.map { |field, attr| [field, attr.sfdc_name] }]
@mappings ||= Hash[fields.map { |field, attr| [field, attr.sfdc_name] }]
end

def sfdc_names
Expand Down
2 changes: 1 addition & 1 deletion lib/active_force/sobject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def write_value key, value
field = key
else
# Assume key is an SFDC column
field = mappings.invert[key]
field = mappings.key(key)
end
send "#{field}=", value if field && respond_to?(field)
end
Expand Down

0 comments on commit 896823c

Please sign in to comment.