Class: Glimmer::DSL::StaticExpression
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
.capitalized? ⇒ Boolean
Also known as:
capitalize?, capital?
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
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
.downcased? ⇒ Boolean
Also known as:
downcase?
58
59
60
61
|
# File 'lib/glimmer/dsl/static_expression.rb', line 58
def downcased?
@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
|
.keyword ⇒ Object
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
.upcased? ⇒ Boolean
Also known as:
upcase?
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`
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
|