Sha256: 75cc7a881b4217ad6c58cbce60a2ddef22b8dff8fb089dfd0c78e0895675ae18

Contents?: true

Size: 798 Bytes

Versions: 11

Compression:

Stored size: 798 Bytes

Contents

require 'glimmer/dsl/static_expression'
require 'glimmer/data_binding/observer'
require 'glimmer/data_binding/model_binding'

module Glimmer
  module DSL
    class ObserveExpression < StaticExpression
      REGEX_NESTED_OR_INDEXED_PROPERTY = /([^\[]+)(\[[^\]]+\])?/

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

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
glimmer-0.5.11 lib/glimmer/dsl/observe_expression.rb
glimmer-0.5.10 lib/glimmer/dsl/observe_expression.rb
glimmer-0.5.9 lib/glimmer/dsl/observe_expression.rb
glimmer-0.5.8 lib/glimmer/dsl/observe_expression.rb
glimmer-0.5.7 lib/glimmer/dsl/observe_expression.rb
glimmer-0.5.6 lib/glimmer/dsl/observe_expression.rb
glimmer-0.5.5 lib/glimmer/dsl/observe_expression.rb
glimmer-0.5.4 lib/glimmer/dsl/observe_expression.rb
glimmer-0.5.3 lib/glimmer/dsl/observe_expression.rb
glimmer-0.5.2 lib/glimmer/dsl/observe_expression.rb
glimmer-0.5.0 lib/glimmer/dsl/observe_expression.rb