Module: ActiveBehavior::RecordHelper::ClassMethods

Defined in:
lib/active-behavior/record_helper.rb

Instance Method Summary collapse

Instance Method Details

#behaviors(*names) ⇒ Object



13
14
15
16
17
# File 'lib/active-behavior/record_helper.rb', line 13

def behaviors(*names)
  @behaviors = names.flatten.compact.uniq
  
  include_behaviors
end

#include_behaviorsObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active-behavior/record_helper.rb', line 19

def include_behaviors
  return unless @behaviors.present?
  
  @behaviors.each do |behavior|
    begin
      include "::#{self.name}::#{behavior.to_s.camelize}".constantize
    rescue Exception => e
      puts "#{e.inspect}\n#{e.backtrace.join("\n")}" unless e.inspect =~ /uninitialized constant/
      include "::Shared::#{behavior.to_s.camelize}".constantize rescue nil
    end
  end
end