Sha256: 695fd6c5a6918aac1f9571159b5eedca61e058139fdc2a56367a3a0dcc6f8db4

Contents?: true

Size: 1.04 KB

Versions: 17

Compression:

Stored size: 1.04 KB

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
        entity = element(name) || Entity.new( name )
        yield(entity) if block_given?
        entity.after_declaration
        add_node entity # 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

17 entries across 17 versions & 1 rubygems

Version Path
mdd-3.1.4 lib/mdwa/dsl/entities.rb
mdd-3.1.2 lib/mdwa/dsl/entities.rb
mdd-3.1.1 lib/mdwa/dsl/entities.rb
mdd-3.1.0 lib/mdwa/dsl/entities.rb
mdd-3.0.20 lib/mdwa/dsl/entities.rb
mdd-3.0.19 lib/mdwa/dsl/entities.rb
mdd-3.0.18 lib/mdwa/dsl/entities.rb
mdd-3.0.17 lib/mdwa/dsl/entities.rb
mdd-3.0.16 lib/mdwa/dsl/entities.rb
mdd-3.0.15 lib/mdwa/dsl/entities.rb
mdd-3.0.14 lib/mdwa/dsl/entities.rb
mdd-3.0.13 lib/mdwa/dsl/entities.rb
mdd-3.0.10 lib/mdwa/dsl/entities.rb
mdd-3.0.9 lib/mdwa/dsl/entities.rb
mdd-3.0.8 lib/mdwa/dsl/entities.rb
mdd-3.0.7 lib/mdwa/dsl/entities.rb
mdd-3.0.6 lib/mdwa/dsl/entities.rb