Class: Glimmer::Specification::Element
- Defined in:
- lib/glimmer/specification/element.rb,
lib/glimmer/specification/element/fact.rb,
lib/glimmer/specification/element/scenario.rb,
lib/glimmer/specification/element/use_case.rb,
lib/glimmer/specification/element/specification.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Fact, Scenario, Specification, UseCase
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#keyword ⇒ Object
readonly
Returns the value of attribute keyword.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
- .element_class(keyword) ⇒ Object
- .element_class_name(keyword) ⇒ Object
- .element_exist?(keyword) ⇒ Boolean
Instance Method Summary collapse
-
#ancestors ⇒ Object
ancestors including self ordered from closest to farthest.
- #children ⇒ Object
-
#content(&block) ⇒ Object
Enables re-opening content and adding new shapes.
- #content_added? ⇒ Boolean
-
#executable? ⇒ Boolean
subclasses may override (e.g. Scenario).
-
#initialize(parent, keyword, *args, &block) ⇒ Element
constructor
A new instance of Element.
- #post_add_content ⇒ Object
- #post_initialize_child(child) ⇒ Object
-
#run ⇒ Object
runs children by default.
- #scenarios ⇒ Object
- #to_s ⇒ Object
- #verified? ⇒ Boolean
Constructor Details
#initialize(parent, keyword, *args, &block) ⇒ Element
Returns a new instance of Element.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/glimmer/specification/element.rb', line 42 def initialize(parent, keyword, *args, &block) @parent = parent @keyword = keyword @args = args @title = @args.first @block = block @children = children @parent&.post_initialize_child(self) post_add_content if @block.nil? end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
39 40 41 |
# File 'lib/glimmer/specification/element.rb', line 39 def args @args end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
39 40 41 |
# File 'lib/glimmer/specification/element.rb', line 39 def block @block end |
#keyword ⇒ Object (readonly)
Returns the value of attribute keyword.
39 40 41 |
# File 'lib/glimmer/specification/element.rb', line 39 def keyword @keyword end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
39 40 41 |
# File 'lib/glimmer/specification/element.rb', line 39 def parent @parent end |
#title ⇒ Object
Returns the value of attribute title.
40 41 42 |
# File 'lib/glimmer/specification/element.rb', line 40 def title @title end |
Class Method Details
.element_class(keyword) ⇒ Object
30 31 32 |
# File 'lib/glimmer/specification/element.rb', line 30 def element_class(keyword) const_get(element_class_name(keyword)) end |
.element_class_name(keyword) ⇒ Object
34 35 36 |
# File 'lib/glimmer/specification/element.rb', line 34 def element_class_name(keyword) keyword.to_s.camelcase(:upper).to_sym end |
.element_exist?(keyword) ⇒ Boolean
26 27 28 |
# File 'lib/glimmer/specification/element.rb', line 26 def element_exist?(keyword) constants.include?(element_class_name(keyword)) && element_class(keyword).respond_to?(:new) end |
Instance Method Details
#ancestors ⇒ Object
ancestors including self ordered from closest to farthest
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/glimmer/specification/element.rb', line 77 def ancestors if @ancestors.nil? @ancestors = [self] current = self while current.parent current = current.parent @ancestors << current end end @ancestors end |
#children ⇒ Object
53 54 55 |
# File 'lib/glimmer/specification/element.rb', line 53 def children @children ||= [] end |
#content(&block) ⇒ Object
Enables re-opening content and adding new shapes
99 100 101 |
# File 'lib/glimmer/specification/element.rb', line 99 def content(&block) Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Specification::ElementExpression.new, @keyword, &block) end |
#content_added? ⇒ Boolean
61 62 63 |
# File 'lib/glimmer/specification/element.rb', line 61 def content_added? @content_added end |
#executable? ⇒ Boolean
subclasses may override (e.g. Scenario)
66 67 68 |
# File 'lib/glimmer/specification/element.rb', line 66 def executable? !!@executable end |
#post_add_content ⇒ Object
93 94 95 96 |
# File 'lib/glimmer/specification/element.rb', line 93 def post_add_content # No Op (subclasses may override to do something at the closing of the element) @content_added = true end |
#post_initialize_child(child) ⇒ Object
89 90 91 |
# File 'lib/glimmer/specification/element.rb', line 89 def post_initialize_child(child) children << child end |
#run ⇒ Object
runs children by default. subclasses may override.
104 105 106 107 108 109 110 111 112 |
# File 'lib/glimmer/specification/element.rb', line 104 def run children.each(&:run) @verified = children.all?(&:verified?) if @verified puts Colours::GREEN + "VERIFIED: #{to_s}" else puts Colours::RED + "NOT VERIFIED: #{to_s}" end end |
#scenarios ⇒ Object
70 71 72 73 74 |
# File 'lib/glimmer/specification/element.rb', line 70 def scenarios children.map do |child| child.is_a?(Scenario) ? child : child.scenarios end.flatten end |
#to_s ⇒ Object
114 115 116 |
# File 'lib/glimmer/specification/element.rb', line 114 def to_s ancestors.reverse.map(&:title).join(' - ') end |
#verified? ⇒ Boolean
57 58 59 |
# File 'lib/glimmer/specification/element.rb', line 57 def verified? @verified end |