Module: ActiveFacts::API::Value::ClassMethods
- Includes:
- Instance::ClassMethods
- Defined in:
- lib/activefacts/api/value.rb
Overview
All ValueType classes include the methods defined here
Constant Summary
Constants included from ObjectType
ObjectType::CHECKED_IDENTIFYING_ROLE, ObjectType::SKIP_MUTUAL_PROPAGATION
Instance Method Summary collapse
- #assert_instance(constellation, args) ⇒ Object
-
#identifying_role_values(constellation, args) ⇒ Object
:nodoc:.
-
#index_instance(constellation, instance) ⇒ Object
:nodoc:.
-
#inherited(other) ⇒ Object
:nodoc:.
-
#value_type(*args, &block) ⇒ Object
:nodoc:.
-
#verbalise ⇒ Object
verbalise this ValueType.
Methods included from ObjectType
#add_role, #all_role, #all_role_transitive, #check_identifying_role_has_valid_cardinality, #has_one, #maybe, #one_to_one, #realise_role, #subtypes, #subtypes_transitive, #supertypes, #supertypes_transitive, #vocabulary
Instance Method Details
#assert_instance(constellation, args) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/activefacts/api/value.rb', line 100 def assert_instance(constellation, args) new_identifier = args == [:new] key = (constellation, args) # args are now normalized to an array containing a single Hash element arg_hash = args[0] if new_identifier instance = key # AutoCounter is its own key else instance_index = constellation.instances[self] unless instance = constellation.has_candidate(self, key) || instance_index[key] instance = new_instance(constellation, key) constellation.candidate(instance) end end # Assign any extra roles that may have been passed. # These assignments only take effect after the candidate object have been asserted. # An exception here means the object is asserted but the role not assigned. arg_hash.each do |k, v| constellation.when_admitted { instance.send(:"#{k}=", v) } end instance end |
#identifying_role_values(constellation, args) ⇒ Object
:nodoc:
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/activefacts/api/value.rb', line 86 def (constellation, args) #:nodoc: # Normalise positional arguments into an arguments hash (this changes the passed parameter) arg_hash = args[-1].is_a?(Hash) ? args.pop : {} # If a single arg is already the correct class or a subclass, # use it directly, otherwise create one. # This appears to be the only way to handle e.g. Date correctly unless args.size == 1 and instance = args[0] and instance.is_a?(self) instance = new_instance(constellation, *args) end args.replace([arg_hash]) instance.(self) end |
#index_instance(constellation, instance) ⇒ Object
:nodoc:
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/activefacts/api/value.rb', line 128 def index_instance(constellation, instance) #:nodoc: # Index the instance in the constellation's InstanceIndex for this class: instances = constellation.instances[self] key = instance.(self) instances[key] = instance # Index the instance for each supertype: supertypes.each do |supertype| supertype.index_instance(constellation, instance) end instance end |
#inherited(other) ⇒ Object
:nodoc:
142 143 144 145 146 147 148 |
# File 'lib/activefacts/api/value.rb', line 142 def inherited(other) #:nodoc: # Copy the type parameters here, etc? other.send :realise_supertypes, self TypeInheritanceFactType.new(self, other) vocabulary.__add_object_type(other) super end |
#value_type(*args, &block) ⇒ Object
:nodoc:
53 54 55 56 57 58 59 |
# File 'lib/activefacts/api/value.rb', line 53 def value_type *args, &block #:nodoc: = (args[-1].is_a?(Hash) ? args.pop : {}) .each do |key, value| raise UnrecognisedOptionsException.new('ValueType', basename, key) unless respond_to?(key) send(key, value) end end |
#verbalise ⇒ Object
verbalise this ValueType
82 83 84 |
# File 'lib/activefacts/api/value.rb', line 82 def verbalise "#{basename} < #{superclass.basename}();" end |