Sha256: 3cdda221ffa5259ad6af5eca96014e02ea5a75a27638b9d772f0a7fb836977a6
Contents?: true
Size: 1.11 KB
Versions: 6
Compression:
Stored size: 1.11 KB
Contents
class PersistentTrigger < ActiveRecord::Base self.inheritance_column = nil serialize :value, Houston::Serializer.new serialize :params, Houston::ParamsSerializer.new TYPES = [:on, :every].freeze validates :type, inclusion: { in: TYPES, message: "{value} is not valid Trigger type; use #{TYPES.map(&:inspect).to_sentence(two_words_connector: " or ", last_word_connector: ", or ")}" } validate :action_must_be_defined after_create :register! TYPES.each do |type| instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{type}(value, action, params={}) self.new(type: :#{type}, value: value, action: action, params: params) end RUBY end def self.load_all all.find_each(&:register!) end def type super && super.to_sym end def register! trigger = Houston.config.triggers.build(type, value, action, params) Houston.config.triggers.push(trigger) unless Houston.config.triggers.member?(trigger) end private def action_must_be_defined return if Houston.config.actions.exists?(action) errors.add :action, "#{action.inspect} is not defined" end end
Version data entries
6 entries across 6 versions & 1 rubygems