Module: MatrixSdk::Extensions

Included in:
Api, Bot::Base, Client, Event, Room, User, Util::AccountDataCache, Util::StateEventCache, Util::TinycacheAdapter
Defined in:
lib/matrix_sdk/util/extensions.rb

Instance Method Summary collapse

Instance Method Details

#events(*symbols) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/matrix_sdk/util/extensions.rb', line 13

def events(*symbols)
  module_name = "#{name}Events"

  initializers = []
  readers = []
  methods = []

  symbols.each do |sym|
    name = sym.to_s

    initializers << "
      @on_#{name} = MatrixSdk::EventHandlerArray.new
    "
    readers << ":on_#{name}"
    methods << "
      def fire_#{name}(ev, filter = nil)
        @on_#{name}.fire(ev, filter)
        when_#{name}(ev) if !ev.handled?
      end

      def when_#{name}(ev); end
    "
  end

  class_eval "
    module #{module_name}
      attr_reader #{readers.join ', '}

      def event_initialize
        #{initializers.join}
      end

      #{methods.join}
    end

    include #{module_name}
  ", __FILE__, __LINE__ - 12
end

#ignore_inspect(*symbols) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/matrix_sdk/util/extensions.rb', line 52

def ignore_inspect(*symbols)
  require 'pp'

  class_eval %*
    def pretty_print_instance_variables
      instance_variables
        .reject { |f| %i[#{symbols.map { |s| "@#{s}" }.join ' '}].include? f }
        .sort
    end

    def pretty_print(pp)
      return pp.pp(self) if respond_to? :mocha_inspect

      pp.pp_object(self)
    end

    alias inspect pretty_print_inspect
  *, __FILE__, __LINE__ - 14
end