Class: Glimmer::Web::EventProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/glimmer/web/event_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listener:, js_event: nil) ⇒ EventProxy

Instantiates EventProxy When js_event is nil, it is a custom event



31
32
33
34
# File 'lib/glimmer/web/event_proxy.rb', line 31

def initialize(listener:, js_event: nil)
  @listener = listener
  @js_event = js_event
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/glimmer/web/event_proxy.rb', line 52

def method_missing(method_name, *args, &block)
  property_name = method_name.to_s.camelcase
  if js_event.respond_to?(method_name, true)
    js_event.send(method_name, *args, &block)
  elsif (original_event && `#{property_name} in #{original_event.to_n}`)
    original_event[property_name]
  else
    super(method_name, *args, &block)
  end
end

Instance Attribute Details

#js_eventObject (readonly)

Returns the value of attribute js_event.



27
28
29
# File 'lib/glimmer/web/event_proxy.rb', line 27

def js_event
  @js_event
end

#listenerObject (readonly)

Returns the value of attribute listener.



27
28
29
# File 'lib/glimmer/web/event_proxy.rb', line 27

def listener
  @listener
end

Instance Method Details

#elementObject



36
# File 'lib/glimmer/web/event_proxy.rb', line 36

def element = listener.element

#event_attributeObject



38
# File 'lib/glimmer/web/event_proxy.rb', line 38

def event_attribute = listener.event_attribute

#event_nameObject



37
# File 'lib/glimmer/web/event_proxy.rb', line 37

def event_name = listener.event_name

#original_eventObject



40
41
42
43
# File 'lib/glimmer/web/event_proxy.rb', line 40

def original_event
  return if js_event.nil?
  Native(`#{js_event.to_n}.originalEvent`)
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
# File 'lib/glimmer/web/event_proxy.rb', line 45

def respond_to_missing?(method_name, include_private = false)
  property_name = method_name.to_s.camelcase
  super(method_name, include_private) ||
    js_event.respond_to?(method_name, include_private) ||
    (original_event && `#{property_name} in #{original_event.to_n}`)
end