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
Class Method Summary collapse
-
.included(klass) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#identifying_role_values(klass = nil) ⇒ Object
A value is its own key, unless it’s a delegate for a raw value.
-
#initialize(*args) ⇒ Object
Value instance methods:.
- #plays_no_role ⇒ Object
-
#verbalise(role_name = nil) ⇒ Object
verbalise this Value.
Methods included from Instance
#instance_index, #is_a?, #related_entities, #retract
Class Method Details
.included(klass) ⇒ Object
:nodoc:
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/activefacts/api/value.rb', line 149 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 (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 |
#plays_no_role ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/activefacts/api/value.rb', line 35 def plays_no_role # REVISIT: Some Value Types are independent, and so must always be regarded as playing a role self.class.all_role.all? do |n, role| case when role.fact_type.is_a?(ActiveFacts::API::TypeInheritanceFactType) true # No need to consider subtyping/supertyping roles here when role.unique send(role.getter) == nil else send(role.getter).empty? end end 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 |