Class: Glimmer::DSL::Swing::ListenerExpression

Inherits:
Expression
  • Object
show all
Defined in:
lib/glimmer/dsl/swing/listener_expression.rb

Overview

Widget, Shape, and Display listener experssion

Instance Method Summary collapse

Instance Method Details

#can_interpret?(parent, keyword, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (Glimmer::Error)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/glimmer/dsl/swing/listener_expression.rb', line 29

def can_interpret?(parent, keyword, *args, &block)
  Glimmer::Config.logger.debug {"keyword starts with on_: #{keyword.start_with?('on_')}"}
  return false unless keyword.start_with?('on_')
  proper_parent = parent.respond_to?(:original)
  Glimmer::Config.logger.debug {"parent #{parent} is a widget, shape, or display: #{proper_parent}"}
  return false unless proper_parent
  Glimmer::Config.logger.debug {"block exists?: #{!block.nil?}"}
  raise Glimmer::Error, "Listener is missing block for keyword: #{keyword}" unless block_given?
  Glimmer::Config.logger.debug {"args are empty?: #{args.empty?}"}
  raise Glimmer::Error, "Invalid listener arguments for keyword: #{keyword}(#{args})" unless args.empty?
  result = parent.can_handle_observation_request?(keyword)
  Glimmer::Config.logger.debug {"can add listener? #{result}"}
  raise Glimmer::Error, "Invalid listener keyword: #{keyword}" unless result
  true
end

#interpret(parent, keyword, *args, &block) ⇒ Object



45
46
47
# File 'lib/glimmer/dsl/swing/listener_expression.rb', line 45

def interpret(parent, keyword, *args, &block)
  parent.handle_observation_request(keyword, &block)
end