Class: Makitzo::World::NamedEntity

Inherits:
Object
  • Object
show all
Includes:
ApplicationAware, Settings
Defined in:
lib/makitzo/world/named_entity.rb

Overview

NamedEntity is a base class for categories of objects uniquely identified by name. Equality is defined based on name and class.

Direct Known Subclasses

Host, Role

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Settings

#[], #[]=, #memo, #read, #set, #settings

Methods included from ApplicationAware

#app, #config, #logger, #store

Constructor Details

#initialize(app, name, options = {}) ⇒ NamedEntity

Returns a new instance of NamedEntity.



22
23
24
25
26
27
# File 'lib/makitzo/world/named_entity.rb', line 22

def initialize(app, name, options = {})
  @app, @name = app, name.to_s
  options.each do |k,v|
    send(:"#{k}=", v)
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/makitzo/world/named_entity.rb', line 17

def name
  @name
end

Class Method Details

.setting_accessor(*syms) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/makitzo/world/named_entity.rb', line 8

def self.setting_accessor(*syms)
  syms.each do |sym|
    class_eval <<-CODE
      def #{sym};         read(:#{sym});        end
      def #{sym}=(value); set(:#{sym}, value);  end
    CODE
  end
end

Instance Method Details

#<=>(other) ⇒ Object



29
# File 'lib/makitzo/world/named_entity.rb', line 29

def <=>(other);   name <=> other.name;                            end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


31
# File 'lib/makitzo/world/named_entity.rb', line 31

def eql?(other);  other.is_a?(self.class) && other.name == name;  end

#hashObject



30
# File 'lib/makitzo/world/named_entity.rb', line 30

def hash;         name.hash;                                      end

#read!(key) ⇒ Object



35
36
37
38
39
# File 'lib/makitzo/world/named_entity.rb', line 35

def read!(key)
  val = read(key)
  raise MissingPropertyError if val.nil?
  val
end

#to_sObject



33
# File 'lib/makitzo/world/named_entity.rb', line 33

def to_s; name; end