Sha256: 80e53e8f59844101325cc63a1972669d976311f962ddbfb135b9f2ef16db82e6

Contents?: true

Size: 1 KB

Versions: 5

Compression:

Stored size: 1 KB

Contents

require 'pleiades/core/util'
require 'freeezer'

module Line
  module Bot
    module Event
      class Base
        using Freeezer

        def initialize(src)
          @src = Pleiades::Util.define_reader src

          # moduleにする
          # /^[a-z]+_event\?$/
          #  => トークタイプの判定メソッドに反応する。
          #
          # @src.source.type => 'user'
          #   user_event? => true
          #   room_event? => false
          #   hoge_event? => false
          #
          @src.define_singleton_method(:method_missing) do |method, *_|
            return super() unless /^[a-z]+_event\?$/ =~ method

            source.type == method.to_s.split('_').first
          end
          @src.deep_freeze
        end

        private

        def method_missing(method, *_)
          @src.respond_to?(method) || super
          @src.__send__ method
        end

        def respond_to_missing?(method, *_)
          @src.respond_to?(method) || super
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pleiades-0.1.6 lib/pleiades/core_ext/line/bot/event/base.rb
pleiades-0.1.5 lib/pleiades/core_ext/line/bot/event/base.rb
pleiades-0.1.4 lib/pleiades/core_ext/line/bot/event/base.rb
pleiades-0.1.3 lib/pleiades/core_ext/line/bot/event/base.rb
pleiades-0.1.2 lib/pleiades/core_ext/line/bot/event/base.rb