Sha256: 4abc891fea3e2d72c694d7579e0e9ea51a758a27eea65997451ef834c8264095

Contents?: true

Size: 995 Bytes

Versions: 2

Compression:

Stored size: 995 Bytes

Contents

# -*- encoding : utf-8 -*-
module MDWA
  module DSL

    # singleton class
    class Entities
      
      attr_accessor :nodes
      
      def initialize
        @nodes ||= {}
      end
      
      def self.instance
        @__instance__ ||= new
      end
      
      #
      # Register a new entity in the list.
      #
      def register( name )
        # retrive or initialize a entity
        e = element(name) || Entity.new( name )
        yield e
        add_node e # add to the list
      end
    
      #
      # Add note to the entity list
      # Prevents entity duplication
      #
      def add_node(node)
        @nodes[node.name] = node
      end
      
      def element(e)
        @nodes[e]
      end
      
      def all
        @nodes.values
      end

    end # class entitites
    
    # return the entities instance
    def self.entities
      Entities.instance
    end
    
    def self.entity(name)
      self.entities.element(name)
    end

    
  end # dsl
end # mdd

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mdd-3.0.2 lib/mdwa/dsl/entities.rb
mdd-3.0.1 lib/mdwa/dsl/entities.rb