Class: MDWA::DSL::Entities

Inherits:
Object
  • Object
show all
Defined in:
lib/mdwa/dsl/entities.rb

Overview

singleton class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEntities

Returns a new instance of Entities.



10
11
12
# File 'lib/mdwa/dsl/entities.rb', line 10

def initialize
  @nodes ||= {}
end

Instance Attribute Details

#nodesObject

Returns the value of attribute nodes.



8
9
10
# File 'lib/mdwa/dsl/entities.rb', line 8

def nodes
  @nodes
end

Class Method Details

.instanceObject



14
15
16
# File 'lib/mdwa/dsl/entities.rb', line 14

def self.instance
  @__instance__ ||= new
end

Instance Method Details

#add_node(node) ⇒ Object

Add note to the entity list Prevents entity duplication



33
34
35
# File 'lib/mdwa/dsl/entities.rb', line 33

def add_node(node)
  @nodes[node.name] = node
end

#allObject



41
42
43
# File 'lib/mdwa/dsl/entities.rb', line 41

def all
  @nodes.values
end

#element(e) ⇒ Object



37
38
39
# File 'lib/mdwa/dsl/entities.rb', line 37

def element(e)
  @nodes[e]
end

#register(name) {|entity| ... } ⇒ Object

Register a new entity in the list.

Yields:



21
22
23
24
25
26
27
# File 'lib/mdwa/dsl/entities.rb', line 21

def register( name )
  # retrive or initialize a entity
  entity = element(name) || Entity.new( name )
  yield(entity) if block_given?
  entity.after_declaration
  add_node entity # add to the list
end