Class: Foobara::Manifest::Model
- Inherits:
-
Type
- Object
- BaseManifest
- Type
- Foobara::Manifest::Model
- Defined in:
- foobara-0.5.8/projects/manifest/src/model.rb
Direct Known Subclasses
Constant Summary
Constants included from TruncatedInspect
Instance Attribute Summary
Attributes inherited from BaseManifest
#manifest_path, #root_manifest
Class Method Summary collapse
Instance Method Summary collapse
- #attribute_names ⇒ Object
- #attributes_type ⇒ Object
- #full_model_name ⇒ Object
- #guaranteed_to_exist?(attribute_name) ⇒ Boolean
-
#has_associations?(type = attributes_type) ⇒ Boolean
TODO: rename.
Methods inherited from Type
#array?, #associative_array?, #attributes?, #base_type, #builtin?, #custom?, #detached_entity?, #entity?, #extends_symbol?, #full_type_name, #model?, new, #primitive?, #target_class, #to_type_declaration_from_declaration_data, #tuple?, #type_manifest, #type_name, #type_symbol, #types_depended_on
Methods inherited from BaseManifest
#==, #[], category_to_manifest_class, #domain, #domain_reference, #eql?, #find_type, #global_domain, #global_organization, #hash, #initialize, #key?, #method_missing, optional_key, #optional_key?, optional_key_defaults, optional_keys, #organization, #parent, #parent_category, #parent_name, #path, #relevant_manifest, #respond_to_missing?, #scoped_category, #symbol_path
Methods included from TruncatedInspect
Constructor Details
This class inherits a constructor from Foobara::Manifest::BaseManifest
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Foobara::Manifest::BaseManifest
Class Method Details
.associations(type, path = DataPath.new, result = {}, initial: true) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'projects/manifest/src/model.rb', line 7 def associations(type, path = DataPath.new, result = {}, initial: true) if type.detached_entity? && !initial type = type.to_type if type.is_a?(TypeDeclaration) result[path.to_s] = type elsif type.model? type = type.to_type if type.is_a?(TypeDeclaration) associations(type.attributes_type, path, result, initial: false) elsif type.tuple? type = type.to_type_declaration_from_declaration_data if type.is_a?(Type) type.element_types&.each&.with_index do |element_type, index| associations(element_type, path.append(index), result, initial: false) end elsif type.array? type = type.to_type_declaration_from_declaration_data if type.is_a?(Type) element_type = type.element_type if element_type associations(element_type, path.append(:"#"), result, initial: false) end elsif type.attributes? type = type.to_type_declaration_from_declaration_data if type.is_a?(Type) type.attribute_declarations.each_pair do |attribute_name, element_type| associations(element_type, path.append(attribute_name), result, initial: false) end # :nocov: elsif type.associative_array? if contains_associations?(type) raise "Associative array types with associations in them are not currently supported. " \ "Use attributes type if you can or set the key_type and/or value_type to duck type" end end # :nocov: result end |
Instance Method Details
#attribute_names ⇒ Object
64 65 66 |
# File 'projects/manifest/src/model.rb', line 64 def attribute_names attributes_type.attribute_names end |
#attributes_type ⇒ Object
50 51 52 |
# File 'projects/manifest/src/model.rb', line 50 def attributes_type Attributes.new(root_manifest, [*manifest_path, :declaration_data, :attributes_declaration]) end |
#full_model_name ⇒ Object
68 69 70 |
# File 'projects/manifest/src/model.rb', line 68 def full_model_name scoped_full_name end |
#guaranteed_to_exist?(attribute_name) ⇒ Boolean
54 55 56 57 58 59 60 61 62 |
# File 'projects/manifest/src/model.rb', line 54 def guaranteed_to_exist?(attribute_name) return true if attributes_type.required?(attribute_name) guaranteed_to_exist = DataPath.value_at([:delegates, :guaranteed_to_exist], relevant_manifest) return false unless guaranteed_to_exist guaranteed_to_exist.include?(attribute_name.to_sym) || guaranteed_to_exist.include?(attribute_name.to_s) end |
#has_associations?(type = attributes_type) ⇒ Boolean
TODO: rename
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'projects/manifest/src/model.rb', line 73 def has_associations?(type = attributes_type) case type when Entity true when Model has_associations?(type.attributes_type) when Attributes type.attribute_declarations.values.any? do |attribute_declaration| has_associations?(attribute_declaration) end when Array has_associations?(type.element_type) when TypeDeclaration has_associations?(type.to_type) when Type type.entity? else # :nocov: raise "not sure how to proceed with #{type}" # :nocov: end end |