Sha256: 7702c29ba7b4a4112165a6baf0f41d4bc19a9878d3a78657aefd0572e3209f61

Contents?: true

Size: 892 Bytes

Versions: 2

Compression:

Stored size: 892 Bytes

Contents

module Hipbot
  module Reactable
    include Cache

    attr_cache :reactions, :default_reactions, :presence_reactions, :options_stack
    attr_cache :reaction_factory do
      ReactionFactory.new(self)
    end

    def on_presence *params, &block
      scope *params do
        presence_reactions << to_reaction(block)
      end
    end

    def on *params, &block
      scope *params do
        reactions << to_reaction(block)
      end
    end

    def default *params, &block
      scope *params do
        default_reactions << to_reaction(block)
      end
    end

    def scope *params, &block
      options_stack << reaction_factory.get_reaction_options(params)
      yield
      options_stack.pop
    end

    def desc text
      reaction_factory.description(text)
    end

    protected

    def to_reaction block
      reaction_factory.build(options_stack, block)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hipbot-1.0.4 lib/hipbot/reactable.rb
hipbot-1.0.3 lib/hipbot/reactable.rb