-
Notifications
You must be signed in to change notification settings - Fork 0
Add raise_on_unknown_attributes configuration option #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
650ecdd
1f7ac04
a5ec52a
fa9bca5
53f052e
a181cfc
3d71024
a5feceb
0765ab9
7e725e3
ecdc128
5c56c77
b4a6280
9153062
9e9ecfd
5b3607d
27c3293
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,6 @@ def move_changes | |
|
|
||
| def changes_applied | ||
| move_changes | ||
| super | ||
| end | ||
|
|
||
| def reset_object! | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,7 +155,18 @@ def update_attribute(name, value) | |
|
|
||
| def assign_attributes(hash) | ||
| hash = hash.with_indifferent_access if hash.is_a?(Hash) | ||
| super(hash.except("type")) | ||
|
|
||
| # Filter unknown attributes if raise_on_unknown_attributes is false | ||
| if !self.class.raise_on_unknown_attributes | ||
| known_attrs = hash.slice(*self.class.attribute_names).except("type") | ||
| unknown_attrs = hash.keys - self.class.attribute_names - ["type"] | ||
| if unknown_attrs.any? | ||
| CouchbaseOrm.logger.warn "Ignoring unknown attribute(s) for #{self.class.name}: #{unknown_attrs.join(', ')}" | ||
| end | ||
| super(known_attrs) | ||
| else | ||
| super(hash.except("type")) | ||
| end | ||
| end | ||
|
Comment on lines
156
to
170
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
|
|
||
| # Updates the attributes of the model from the passed-in hash and saves the | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,10 @@ module Types | |
| class Timestamp < ActiveModel::Type::DateTime | ||
| def cast(value) | ||
| return nil if value.nil? | ||
| return Time.at(value) if value.is_a?(Integer) || value.is_a?(Float) | ||
| return Time.at(value.to_i) if value.is_a?(String) && value =~ /^[0-9]+$/ | ||
| return value.utc if value.is_a?(Time) | ||
| super(value).utc | ||
| return Time.at(value).floor if value.is_a?(Integer) || value.is_a?(Float) | ||
| return Time.at(value.to_i).floor if value.is_a?(String) && value =~ /^[0-9]+$/ | ||
| return value.utc.floor if value.is_a?(Time) | ||
| super(value).utc.floor | ||
| end | ||
|
Comment on lines
4
to
10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The addition of def cast(value)
return nil if value.nil?
return Time.at(value) if value.is_a?(Integer) || value.is_a?(Float)
return Time.at(value.to_i) if value.is_a?(String) && value =~ /^[0-9]+$/
return value.utc if value.is_a?(Time)
super(value).utc
end |
||
|
|
||
| def serialize(value) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change in module inclusion order appears to introduce a bug.
ActiveModel::AttributesincludesActiveModel::Dirty. By includingChangeablebeforeActiveModel::Attributes, the methods inActiveModel::Dirty(likechanges_applied) will override the ones inChangeable. The original code and its comment indicated thatChangeableis intended to overrideActiveModel::Dirty's behavior. To restore the correct override behavior,Changeableshould be included afterActiveModel::Attributes.