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
Added update_or_create method #4
Conversation
This new method allows us to use multiple keys to identify records, it replaces the implementation of `.refresh`. Fixes abletech#2
README.md
Outdated
Easy::ReferenceData.refresh User, :system_code, 'nigel', name: 'Nigel Ramsay', email: 'nigel.ramsay@mailinator.com' | ||
Easy::ReferenceData.refresh User, :system_code, 'fred', name: 'Fred Schmitt', email: 'fred.schmitt@mailinator.com' | ||
Easy::ReferenceData.refresh User, :system_code, 'bert', name: 'Bert Symthe', email: 'bert.smythe@mailinator.com' | ||
Easy::ReferenceData.update_or_create User, system_code: 'nigel', name: 'Nigel Ramsay', email: 'nigel.ramsay@mailinator.com', keys: [:system_code] |
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.
Should these examples be adjusted to separate the keys
option from the User
attributes? Eg:
Easy::ReferenceData.update_or_create User, {system_code: 'nigel', name: 'Nigel Ramsay', email: 'nigel.ramsay@mailinator.com'}, keys: [:system_code]
At the moment, it looks as if keys
is just another attribute of User
.
lib/easy/reference_data/refresh.rb
Outdated
puts "..creating #{clazz}(#{unique_attribute_value})" | ||
elsif record.changed? | ||
puts "..updating #{clazz}(#{unique_attribute_value})" | ||
puts "..creating #{clazz}(#{attributes.slice(*unique_attribute_keys)})" |
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.
at the moment, these puts
statements are all writing to $stdout
be default. I believe Unix convention is for these sort of debug/progress messages to write to $stderr
. I suggest we change this at the same time.
lib/easy/reference_data/version.rb
Outdated
@@ -1,5 +1,5 @@ | |||
module Easy | |||
module ReferenceData | |||
VERSION = "0.1.2" | |||
VERSION = "0.2.0" |
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.
maybe we should just go straight to version 1.0.0
?
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.
Just a few minor remarks. Looks good though!
This new method allows us to use multiple keys to identify records, it replaces the implementation of
.refresh
.Fixes #2