Sha256: 16b2b933314150ae8174b63424bde925e230e5c339a744aa2a0bff8425f2bb4a

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module Populus
  class Accepter
    # TODO: validators
    class Base
      attr_accessor :condition, :runner, :metadata

      def initialize(cond: nil, runs: nil, metadata: {})
        self.condition = cond
        self.runner = runs
        self.metadata = metadata
      end

      def type?(t)
        current_type = self.class.name.downcase
          .split('::')
          .last
        current_type == t
      end

      def accept(data)
        if condition[data]
          Populus.logger.debug "Condition judged true: #{data.inspect}"
          runner[data]
          return true
        else
          Populus.logger.debug "Condition judged false: #{data.inspect}"
          return false
        end
      end
    end

    class Event < Base
      def has_name?(name)
        metadata[:name] == name
      end

      def create_thread
        _name = metadata[:name]
        Populus.logger.debug "Create thread: consul watch -type event -name #{_name}"
        Populus::WatchThread.consul_watch('-type', 'event', '-name', _name)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
populus-0.0.1 lib/populus/accepter.rb