module SheepAst::FactoryBase

This object is base object of the sheep fuctory pattern Factory abstract/wrap instanciation process and it absorb change impact inside the framework

@api private

Attributes

action_factory[RW]
ctime[RW]
data_store[RW]
match_factory[RW]
my_factory[RW]
my_name[RW]
root_node[R]

Public Class Methods

new() click to toggle source
Calls superclass method SheepAst::Log::new
# File lib/sheep_ast/factory_base.rb, line 42
def initialize
  @ctime = Time.new
  @id_store = []
  @name_hash = {}
  @current_id = -1
  super()
end

Public Instance Methods

bind_name(name, id) click to toggle source
# File lib/sheep_ast/factory_base.rb, line 99
def bind_name(name, id)
  if @name_hash.key?(name)
    application_error "same name is already registered '#{name}'"
  end

  @name_hash[name] = id
end
create_id(obj, name = nil) click to toggle source
# File lib/sheep_ast/factory_base.rb, line 61
def create_id(obj, name = nil)
  @current_id += 1
  @id_store.push obj
  obj.my_id = @current_id

  unless name.nil?
    bind_name(name, @current_id)
  end

  ldebug? and ldebug2 "id = #{@current_id}, obj.my_id = #{obj.my_id}"\
    " registrated object_id = #{obj.object_id}, name = '#{name}'"
  return @current_id
end
from_id(id) click to toggle source
# File lib/sheep_ast/factory_base.rb, line 76
def from_id(id)
  ids = @id_store[id]

  ldebug? and ldebug2 "id = #{id}, obj.my_id = #{ids.my_id}, returned object_id = #{ids.object_id}"
  return ids
end
from_name(name) click to toggle source
# File lib/sheep_ast/factory_base.rb, line 84
def from_name(name)
  id = @name_hash[name]
  application_error "specified name = '#{name}' does not exist" if id.nil?

  return from_id(id)
end
get_factory(name) click to toggle source
# File lib/sheep_ast/factory_base.rb, line 108
def get_factory(name)
  @factories.each do |fac|
    if fac.my_name == name
      return fac
    end
  end
  application_error 'factory not found'
end
inspect() click to toggle source
# File lib/sheep_ast/factory_base.rb, line 51
def inspect
  "custom inspect <#{self.class.name} object_id = #{object_id}, my_name = #{@my_name}>"
end
name_defined?(name) click to toggle source
# File lib/sheep_ast/factory_base.rb, line 92
def name_defined?(name)
  return true if @name_hash.key?(name)

  return false
end