Module: ActiveFacts::API::Value

Includes:
Instance
Defined in:
lib/activefacts/api/value.rb

Overview

All Value instances include the methods defined here

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary

Attributes included from Instance

#constellation

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Instance

#check_identification_change_legality, #instance_index, #is_a?, #related_entities, #retract

Class Method Details

.included(klass) ⇒ Object

:nodoc:



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/activefacts/api/value.rb', line 137

def self.included klass #:nodoc:
  klass.send :extend, ClassMethods

  if !klass.respond_to?(:new_instance)
    class << klass
      def new_instance constellation, *args
        instance = allocate
        instance.instance_variable_set(@@constellation_variable_name ||= "@constellation", constellation)
        instance.send(:initialize, *args)
        instance
      end
    end
  end

  # Register ourselves with the parent module, which has become a Vocabulary:
  vocabulary = klass.modspace
  unless vocabulary.respond_to? :object_type  # Extend module with Vocabulary if necessary
    vocabulary.send :extend, Vocabulary
  end
  vocabulary.__add_object_type(klass)
end

Instance Method Details

#identifying_role_values(klass = nil) ⇒ Object

A value is its own key, unless it’s a delegate for a raw value



30
31
32
33
# File 'lib/activefacts/api/value.rb', line 30

def identifying_role_values(klass = nil) #:nodoc:
  # The identifying role value for the supertype of a value type is always the same as for the subtype
  respond_to?(:__getobj__) ? __getobj__ : self
end

#initialize(*args) ⇒ Object

Value instance methods:



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

def initialize(*args) #:nodoc:
  arg_hash = args[-1].is_a?(Hash) ? args.pop.clone : nil

  super(args)
end

#verbalise(role_name = nil) ⇒ Object

verbalise this Value



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

def verbalise(role_name = nil)
  "#{role_name || self.class.basename} '#{to_s}'"
end