Class: DbAccessor::Updater
- Inherits:
-
Db_Accessor::Base
- Object
- Db_Accessor::Base
- DbAccessor::Updater
- Defined in:
- lib/dbAccessor.rb,
lib/dbAccessor/updater/updater.rb
Constant Summary
Constants inherited from Db_Accessor::Base
Db_Accessor::Base::APP_MODEL, Db_Accessor::Base::ENGINE_DATA_MODEL, Db_Accessor::Base::ENGINE_MODEL, Db_Accessor::Base::USER_MODEL
Class Method Summary collapse
Methods inherited from Db_Accessor::Base
get_model_name, is_model?, return_response, valid_attributes_values?, valid_class?, valid_hash?, valid_keys?, valid_object_columns?, validate_argument, verify_keys
Class Method Details
.update_all_objects(given_param, condition = "") ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# 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 |