Sha256: 9b7be44777ad50803392054cd581acde384c3b3178536af6169a020489a5bb38

Contents?: true

Size: 1.16 KB

Versions: 11

Compression:

Stored size: 1.16 KB

Contents

require 'facets/string/underscore'

require 'glimmer/error'
require 'glimmer/dsl/engine'
require 'glimmer/dsl/expression'

module Glimmer
  module DSL
    # Represents a StaticExpression for expressions where
    # the keyword does not vary dynamically. These static keywords are then
    # predefined as methods in Glimmer instead of needing method_missing
    #
    # StaticExpression subclasses may optionally implement `#can_interpret?`
    # (not needed if it only checks for keyword)
    #
    # StaticExpression subclasses must define `#interpret`.
    # 
    # The direct parent namespace of a StaticExpression subclass must match the DSL name (case-insensitive)
    # (e.g. Glimmer::DSL::SWT::WidgetExpression has a DSL of :swt)
    class StaticExpression < Expression
      class << self  
        def inherited(base)
          Glimmer::DSL::Engine.add_static_expression(base.new)
          super
        end

        def keyword
          @keyword ||= name.split(/::/).last.sub(/Expression$/, '').underscore
        end
      end

      # Subclasses may optionally implement
      def can_interpret?(parent, keyword, *args, &block)
        true
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
glimmer-0.10.4 lib/glimmer/dsl/static_expression.rb
glimmer-0.10.3 lib/glimmer/dsl/static_expression.rb
glimmer-0.10.2 lib/glimmer/dsl/static_expression.rb
glimmer-0.10.1 lib/glimmer/dsl/static_expression.rb
glimmer-0.10.0 lib/glimmer/dsl/static_expression.rb
glimmer-0.9.5 lib/glimmer/dsl/static_expression.rb
glimmer-0.9.4 lib/glimmer/dsl/static_expression.rb
glimmer-0.9.3 lib/glimmer/dsl/static_expression.rb
glimmer-0.9.2 lib/glimmer/dsl/static_expression.rb
glimmer-0.9.1 lib/glimmer/dsl/static_expression.rb
glimmer-0.9.0 lib/glimmer/dsl/static_expression.rb