trabajo-afectivo/app/models/channel.rb

27 lines
1,015 B
Ruby
Raw Normal View History

2014-02-03 19:23:00 +00:00
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Channel < ApplicationModel
store :options
2012-04-10 14:06:46 +00:00
def self.fetch
channels = Channel.where( 'active = ? AND area LIKE ?', true, '%::Inbound' )
channels.each { |channel|
2012-04-10 14:06:46 +00:00
begin
# we need to require each channel backend individually otherwise we get a
# 'warning: toplevel constant Twitter referenced by Channel::Twitter' error e.g.
# so we have to convert the channel name to the filename via Rails String.underscore
# http://stem.ps/rails/2015/01/25/ruby-gotcha-toplevel-constant-referenced-by.html
require "channel/#{channel[:adapter].underscore}"
channel_object = Object.const_get("Channel::#{channel[:adapter]}")
channel_instance = channel_object.new
channel_instance.fetch(channel)
rescue => e
logger.error "Can't use Channel::#{channel[:adapter]}"
2015-05-04 18:58:28 +00:00
logger.error e.inspect
logger.error e.backtrace
2012-04-10 14:06:46 +00:00
end
}
end
end