Module: ActiveFacts::API::Value::ClassMethods
- Includes:
- Instance::ClassMethods
- Defined in:
- lib/activefacts/api/value.rb
Overview
All ValueType classes include the methods defined here
Instance Method Summary collapse
-
#assert_instance(constellation, args) ⇒ Object
:nodoc:.
-
#identifying_role_values(*args) ⇒ Object
:nodoc:.
-
#index_instance(instance, key = nil) ⇒ Object
:nodoc:.
-
#inherited(other) ⇒ Object
:nodoc:.
-
#initialise_value_type(*args, &block) ⇒ Object
:nodoc:.
-
#verbalise ⇒ Object
verbalise this ValueType.
Methods included from Concept
#__absorb, #columns, #has_one, #is_a?, #is_table, #maybe, #one_to_one, #realise_role, #roles, #subtypes, #supertypes, #supertypes_transitive, #table, #vocabulary
Instance Method Details
#assert_instance(constellation, args) ⇒ Object
:nodoc:
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/activefacts/api/value.rb', line 72 def assert_instance(constellation, args) #:nodoc: # Build the key for this instance from the args # The key of an instance is the value or array of keys of the identifying values. # The key values aren't necessarily present in the constellation, even after this. key = (*args) #puts "#{klass} key is #{key.inspect}" # Find and return an existing instance matching this key instances = constellation.instances[self] # All instances of this class in this constellation instance = instances[key] # DEBUG: puts "assert #{self.basename} #{key.inspect} #{instance ? "exists" : "new"}" return instance, key if instance # A matching instance of this class instance = new(*args) instance.constellation = constellation return *index_instance(instance) end |
#identifying_role_values(*args) ⇒ Object
:nodoc:
62 63 64 65 66 67 68 69 70 |
# File 'lib/activefacts/api/value.rb', line 62 def (*args) #:nodoc: # If the single arg is the correct class or a subclass, use it directly #puts "#{basename}.identifying_role_values#{args.inspect}" if (args.size == 1 and (arg = args[0]).is_a?(self.class)) # No secondary supertypes allowed for value types arg = arg.__getobj__ if RoleProxy === arg return arg end new(*args) end |
#index_instance(instance, key = nil) ⇒ Object
:nodoc:
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/activefacts/api/value.rb', line 91 def index_instance(instance, key = nil) #:nodoc: instances = instance.constellation.instances[self] key = instance. instances[key] = instance # DEBUG: puts "indexing value #{basename} using #{key.inspect} in #{constellation.object_id}" # Index the instance for each supertype: supertypes.each do |supertype| supertype.index_instance(instance, key) end return instance, key end |
#inherited(other) ⇒ Object
:nodoc:
105 106 107 108 109 110 111 |
# File 'lib/activefacts/api/value.rb', line 105 def inherited(other) #:nodoc: #puts "REVISIT: ValueType #{self} < #{self.superclass} was inherited by #{other}; not implemented" #+"from #{caller*"\n\t"}" # Copy the type parameters here, etc? other.send :realise_supertypes, self vocabulary.add_concept(other) super end |
#initialise_value_type(*args, &block) ⇒ Object
:nodoc:
36 37 38 39 |
# File 'lib/activefacts/api/value.rb', line 36 def initialise_value_type *args, &block #:nodoc: # REVISIT: args could be a hash, with keys :length, :scale, :unit, :allow #raise "value_type args unexpected" if args.size > 0 end |
#verbalise ⇒ Object
verbalise this ValueType
56 57 58 59 60 |
# File 'lib/activefacts/api/value.rb', line 56 def verbalise # REVISIT: Add length and scale here, if set # REVISIT: Set vocabulary name of superclass if not same as this "#{basename} = #{superclass.basename}();" end |