Class: Glimmer::DSL::StaticExpression

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

Overview

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 Method Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

#add_content, #around, dsl, #interpret, #textual?

Class Method Details

.capitalized(value) ⇒ Object Also known as: capitalize, capital


75
76
77
78
# File 'lib/glimmer/dsl/static_expression.rb', line 75

def capitalized(value)
  @capitalized = value
  Glimmer::DSL::Engine.add_capitalized_static_expression(new) if @capitalized
end

.capitalized?Boolean Also known as: capitalize?, capital?

Returns:

  • (Boolean)

82
83
84
# File 'lib/glimmer/dsl/static_expression.rb', line 82

def capitalized?
  @capitalized
end

.case_insensitive(value) ⇒ Object


88
89
90
91
92
93
94
95
96
97
98
# File 'lib/glimmer/dsl/static_expression.rb', line 88

def case_insensitive(value)
  if value
    self.downcased(true)
    self.upcased(true)
    self.capitalized(true)
  else
    self.downcased(true)
    self.upcased(false)
    self.capitalized(false)
  end
end

.case_insensitive?Boolean

Returns:

  • (Boolean)

100
101
102
# File 'lib/glimmer/dsl/static_expression.rb', line 100

def case_insensitive?
  downcased? && upcased? && capitalized?
end

.downcased(value) ⇒ Object Also known as: downcase


52
53
54
55
# File 'lib/glimmer/dsl/static_expression.rb', line 52

def downcased(value)
  @downcased = value
  Glimmer::DSL::Engine.add_downcased_static_expression(new) if @downcased
end

.downcased?Boolean Also known as: downcase?

Returns:

  • (Boolean)

58
59
60
61
# File 'lib/glimmer/dsl/static_expression.rb', line 58

def downcased?
  # default is true when no attributes are set
  @downcased.nil? && @upcased.nil? && @capitalized.nil? ? true : @downcased
end

.inherited(base) ⇒ Object


43
44
45
46
# File 'lib/glimmer/dsl/static_expression.rb', line 43

def inherited(base)
  Glimmer::DSL::Engine.add_static_expression(base.new)
  super
end

.keywordObject


48
49
50
# File 'lib/glimmer/dsl/static_expression.rb', line 48

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

.upcased(value) ⇒ Object Also known as: upcase


64
65
66
67
# File 'lib/glimmer/dsl/static_expression.rb', line 64

def upcased(value)
  @upcased = value
  Glimmer::DSL::Engine.add_upcased_static_expression(new) if @upcased
end

.upcased?Boolean Also known as: upcase?

Returns:

  • (Boolean)

70
71
72
# File 'lib/glimmer/dsl/static_expression.rb', line 70

def upcased?
  @upcased
end

Instance Method Details

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

Subclasses may optionally implement, but by default it only ensures that the keyword matches lower case static expression class name minus `Expression`

Returns:

  • (Boolean)

107
108
109
110
111
112
113
# File 'lib/glimmer/dsl/static_expression.rb', line 107

def can_interpret?(parent, keyword, *args, &block)
  result = false
  result ||= keyword.downcase == keyword if self.class.downcased?
  result ||= keyword.upcase == keyword if self.class.upcased?
  result ||= keyword.capitalize == keyword if self.class.capitalized?
  result
end