Class: Glimmer::Specification::Element

Inherits:
Object
  • Object
show all
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

Fact, Scenario, Specification, UseCase

Defined Under Namespace

Classes: Fact, Scenario, Specification, UseCase

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#argsObject (readonly)

Returns the value of attribute args.



39
40
41
# File 'lib/glimmer/specification/element.rb', line 39

def args
  @args
end

#blockObject (readonly)

Returns the value of attribute block.



39
40
41
# File 'lib/glimmer/specification/element.rb', line 39

def block
  @block
end

#keywordObject (readonly)

Returns the value of attribute keyword.



39
40
41
# File 'lib/glimmer/specification/element.rb', line 39

def keyword
  @keyword
end

#parentObject (readonly)

Returns the value of attribute parent.



39
40
41
# File 'lib/glimmer/specification/element.rb', line 39

def parent
  @parent
end

#titleObject

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

Returns:

  • (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

#ancestorsObject

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

#childrenObject



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

Returns:

  • (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)

Returns:

  • (Boolean)


66
67
68
# File 'lib/glimmer/specification/element.rb', line 66

def executable?
  !!@executable
end

#post_add_contentObject



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

#runObject

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

#scenariosObject



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_sObject



114
115
116
# File 'lib/glimmer/specification/element.rb', line 114

def to_s
  ancestors.reverse.map(&:title).join(' - ')
end

#verified?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/glimmer/specification/element.rb', line 57

def verified?
  @verified
end