Module: Hatio::ExtensionLogic::ClassMethods

Defined in:
lib/hatio-core/active_record/extension_logic.rb

Instance Method Summary collapse

Instance Method Details

#run_class_logic(logic_name, params) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/hatio-core/active_record/extension_logic.rb', line 13

def run_class_logic(logic_name, params)
  entity = Entity.find_by_name(self.name)
  raise Hatio::Exception::MisConfigured, (I18n.translate 'errors.messages.x_not_found', :x => "Entity (#{self.name})") unless entity
  logic = entity.entity_logics.where("level = ? and name = ?", :class.to_s, logic_name).first
  raise Hatio::Exception::MisConfigured, (I18n.translate 'errors.messages.x_not_found', :x => "EntityLogic (#{logic_name}) of Entity (#{self.name})") unless logic
  raise Hatio::Exception::MisConfigured, (I18n.translate 'errors.messages.empty_x_not_allowed', :x => "EntityLogic (#{logic_name}) of Entity (#{self.name})") if (logic.logic.nil? || logic.logic.empty?)
  return self.instance_eval logic.logic
end