Top Level Namespace

Defined Under Namespace

Modules: MatrixSdk, URI Classes: Object

Instance Method Summary collapse

Instance Method Details

#events(*symbols) ⇒ Object



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
51
52
53
54
55
56
57
58
59
60
# File 'lib/matrix_sdk/extensions.rb', line 23

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



62
63
64
65
66
67
68
69
70
71
# File 'lib/matrix_sdk/extensions.rb', line 62

def ignore_inspect(*symbols)
  class_eval %*
    def inspect
      reentrant = caller_locations.any? { |l| l.absolute_path == __FILE__ && l.label == 'inspect' }
      "\#{to_s[0..-2]} \#{instance_variables
        .reject { |f| %i[#{symbols.map { |s| "@#{s}" }.join ' '}].include? f }
        .map { |f| "\#{f}=\#{reentrant ? instance_variable_get(f) : instance_variable_get(f).inspect}" }.join " " }}>"
    end
  *, __FILE__, __LINE__ - 7
end