class DbAccessor::Updater
Public Class Methods
update_all_objects(given_param,condition="")
click to toggle source
# File lib/dbAccessor/updater/updater.rb, line 20 def self.update_all_objects(given_param,condition="") waited_keys = [:model_name,:attributes] if validate(given_param,waited_keys) && valid_object_columns?(given_param[:model_name],given_param[:attributes]) && valid_attributes_values?(given_param[:attributes]) model_name=Object.const_get(given_param[:model_name]) list = model_name.all if condition.empty? list = model_name.where(condition) if condition.is_a?(Hash) && !condition.empty? result = false list.each do |o| hash = {model_name: model_name.to_s,attributes:{ o.id => given_param[:attributes]}} result = update_by_id(hash) break if !result end result ? return_response(200,"Successfully updated") : return_response(400,"Not updated") else return_response(400,"Not updated") end end
update_by_id(given_object)
click to toggle source
# File lib/dbAccessor/updater/updater.rb, line 7 def self.update_by_id(given_object) waited_keys = [:model_name,:attributes] if validate(given_object,waited_keys) && valid_attributes_pattern?(given_object[:model_name],given_object[:attributes]) var = get_model_name(given_object).update(get_attributes(given_object).keys,get_attributes(given_object).values) return_response(200,"Succesfully updated") else return_response(400,"Not updated") end rescue ActiveRecord::RecordNotFound => e return_response(400,"Not updated") end