Module: ActiveFacts::API::Instance

Included in:
Entity, Value
Defined in:
lib/activefacts/api/instance.rb

Overview

Every Instance of a Concept (A Value type or an Entity type) includes the methods of this module:

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#constellationObject

What constellation does this Instance belong to (if any):



14
15
16
# File 'lib/activefacts/api/instance.rb', line 14

def constellation
  @constellation
end

Class Method Details

.included(other) ⇒ Object

:nodoc:



51
52
53
# File 'lib/activefacts/api/instance.rb', line 51

def Instance.included other #:nodoc:
  other.send :extend, ClassMethods
end

Instance Method Details

#deleteObject

De-assign all functional roles and remove from constellation, if any.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/activefacts/api/instance.rb', line 31

def delete
  # Delete from the constellation first, so it can remember our identifying role values
  @constellation.delete(self) if @constellation

  # Now, for all roles (from this class and all supertypes), assign nil to all functional roles
  # The counterpart roles get cleared automatically.
  ([self.class]+self.class.supertypes_transitive).each do |klass|
    klass.roles.each do |role_name, role|
      next if role.unary?
      next if !role.unique
      send "#{role.name}=", nil
    end
  end
end

#initialize(args = []) ⇒ Object

:nodoc:



16
17
18
19
20
21
22
# File 'lib/activefacts/api/instance.rb', line 16

def initialize(args = []) #:nodoc:
  unless (self.class.respond_to?(:identifying_role_names))
  #if (self.class.superclass != Object)
    # puts "constructing #{self.class.superclass} with #{args.inspect}"
    super(*args)
  end
end

#verbaliseObject

Verbalise this instance



25
26
27
28
# File 'lib/activefacts/api/instance.rb', line 25

def verbalise
  # This method should always be overridden in subclasses
  raise "#{self.class} Instance verbalisation needed"
end