Skip to content

Instantly share code, notes, and snippets.

@fmiopensource
Created October 5, 2009 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmiopensource/202187 to your computer and use it in GitHub Desktop.
Save fmiopensource/202187 to your computer and use it in GitHub Desktop.
# add value from param to task if:
# - its in the list
# - its in the params so sending nil will nil it but sending nothing will leave it alone
# do some conversion on the value as well
{"hours" => ->(hours){hours_points_converter(hours)},
"parked" => ->(parked){parked == "1" ? true : false},
"description" => nil,
"tag_list" => nil,
"status_id" => ->(id){id.to_i},
"position" => ->(p){p.to_i}
}.each{|key, value| task[key] = value.nil? ? params[key] :
value.call(params[key]) if params.keys.include?(key)}
def hours_points_converter(hours)
# something here
hours
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment