Module: Glimmer::DSL::ObserveExpression

Defined in:
lib/glimmer/dsl/observe_expression.rb

Constant Summary collapse

REGEX_NESTED_OR_INDEXED_PROPERTY =
/([^\[]+)(\[[^\]]+\])?/

Instance Method Summary collapse

Instance Method Details

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

Returns:

  • (Boolean)

30
31
32
33
34
35
# File 'lib/glimmer/dsl/observe_expression.rb', line 30

def can_interpret?(parent, keyword, *args, &block)
  keyword == 'observe' and
    block_given? and
    (args.size == 2) and
    textual?(args[1])
end

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


37
38
39
40
41
42
43
44
45
# File 'lib/glimmer/dsl/observe_expression.rb', line 37

def interpret(parent, keyword, *args, &block)
  observer = DataBinding::Observer.proc(&block)
  if args[1].to_s.match(REGEX_NESTED_OR_INDEXED_PROPERTY)
    observer_registration = observer.observe(DataBinding::ModelBinding.new(args[0], args[1]))
  else
    observer_registration = observer.observe(args[0], args[1])
  end
  observer_registration
end