-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is almost a straight 1 for 1 conversion, and performs much better than our implementation: MiqHashStruct. * * * There is a small portion of this that I had to make a change on, and I _think_ it is correct, but here is the explaination for it: There was a chunk of code in this model that silently did nothing when it was an MiqHashStruct because of how often it relied on method_missing to function: field_values[:values].each do |tz| if tz[1].to_i_with_method == val.to_i_with_method # Save [value, description] for timezones array init_values[field_name] = [val, tz[0]] end end If `tz` in the above was a MiqHashStruct, and when `tz[1]` is called, it hit's `method_missing` with `:[]` as the method argument. This of course will almost never have a match in the underlying `@hash` in the MiqHashStruct, return nil and not blow up at the very least. When it is an OpenStruct, this fails with an error since `1` can't be converted to a symbol properly. Since the `tz` object can also potentially be an `Array`, I added a simple check to the code: field_values[:values].each do |tz| next unless tz.kind_of?(Array) # changed this line if tz[1].to_i_with_method == val.to_i_with_method # Save [value, description] for timezones array init_values[field_name] = [val, tz[0]] end end That allowed this to work when it should, and skip over when it wouldn't.
- Loading branch information
1 parent
f827149
commit 361e2b5
Showing
5 changed files
with
19 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters