Module: Forcast::Controller::RuleEngine::ActionEngine
- Extended by:
- ActiveSupport::Concern
- Included in:
- Api::ActionsController
- Defined in:
- lib/forcast/controllers/controller/rule_engine/action_engine.rb
Instance Method Summary collapse
- #convert_params_to_hash(parameters) ⇒ Object
- #create ⇒ Object
- #params_for_are_missing(required_params) ⇒ Object
- #update ⇒ Object
- #validate_attr_model(model, attributes) ⇒ Object
- #validation_for(action_type) ⇒ Object
- #validation_for_callback ⇒ Object
- #validation_for_email(required_email_params) ⇒ Object
Instance Method Details
#convert_params_to_hash(parameters) ⇒ Object
71 72 73 74 75 |
# File 'lib/forcast/controllers/controller/rule_engine/action_engine.rb', line 71 def convert_params_to_hash(parameters) new_params = params.permit(parameters) new_params[:attributes] = params[:attributes] params[:action_params] = new_params end |
#create ⇒ Object
12 13 14 15 16 17 |
# File 'lib/forcast/controllers/controller/rule_engine/action_engine.rb', line 12 def create raise Forcast::Application::Error::General.new(t("error_action_type_dont_permit")) unless Action.action_type_allowed.include?(@action_type) raise Forcast::Application::Error::General.new(t("error_action_params_dont_permit")) unless validation_for(@action_type) params[:active?] = true super end |
#params_for_are_missing(required_params) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/forcast/controllers/controller/rule_engine/action_engine.rb', line 62 def params_for_are_missing(required_params) validation = false required_params.each do |key| next if params.include?(key) validation = true end validation end |
#update ⇒ Object
19 20 21 |
# File 'lib/forcast/controllers/controller/rule_engine/action_engine.rb', line 19 def update super end |
#validate_attr_model(model, attributes) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/forcast/controllers/controller/rule_engine/action_engine.rb', line 77 def validate_attr_model(model,attributes) model = model.classify.constantize attributes.each do |attribute| next if attribute == "all" if model.column_names.include?(attribute) return true else raise Forcast::Application::Error::General.new(t("error_modelo_attr_doesn't_exist")) end end end |
#validation_for(action_type) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/forcast/controllers/controller/rule_engine/action_engine.rb', line 23 def validation_for(action_type) case action_type when "callback" return validation_for_callback when "email" required_email_params = ['owner_email','target_email','attributes'] validation_for_email(required_email_params) convert_params_to_hash(required_email_params) when "telegram" return true else return false end end |
#validation_for_callback ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/forcast/controllers/controller/rule_engine/action_engine.rb', line 38 def validation_for_callback begin action_params = JSON.parse(@action_params) rescue puts "Error Parser JSON" return false end puts action_params unless action_params && action_params["url"] && action_params["attr"] return false else return false unless action_params["attr"].is_a?(Array) model = Rule.find(@rule_id).rule_model validate_attr_model(model,action_params["attr"]) return true end end |
#validation_for_email(required_email_params) ⇒ Object
56 57 58 59 60 |
# File 'lib/forcast/controllers/controller/rule_engine/action_engine.rb', line 56 def validation_for_email(required_email_params) raise Forcast::Application::Error::General.new(t("error_params_email_are_missing")) if params_for_are_missing(required_email_params) model = Rule.find(@rule_id).rule_model validate_attr_model(model,@attributes) end |