Class: Foobara::Manifest::Type

Inherits:
BaseManifest show all
Defined in:
foobara-0.5.8/projects/manifest/src/type.rb

Overview

TODO: override new to return Entity when it’s an entity

Direct Known Subclasses

Model

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary

Attributes inherited from BaseManifest

#manifest_path, #root_manifest

Class Method Summary collapse

Instance Method Summary collapse

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

#inspect, truncating

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

.new(root_manifest, path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'projects/manifest/src/type.rb', line 8

def new(root_manifest, path)
  type = super

  if self == Type
    if type.entity?
      type = Entity.new(type.root_manifest, type.manifest_path)
    elsif type.detached_entity?
      type = DetachedEntity.new(type.root_manifest, type.manifest_path)
    elsif type.model?
      type = Model.new(type.root_manifest, type.manifest_path)
    end
  end

  type
end

Instance Method Details

#array?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'projects/manifest/src/type.rb', line 41

def array?
  !builtin? && extends_symbol?(:array)
end

#associative_array?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'projects/manifest/src/type.rb', line 49

def associative_array?
  !builtin? && extends_symbol?(:associative_array)
end

#attributes?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'projects/manifest/src/type.rb', line 45

def attributes?
  !builtin? && extends_symbol?(:attributes)
end

#base_typeObject



57
58
59
60
61
62
63
# File 'projects/manifest/src/type.rb', line 57

def base_type
  base_type_symbol = self[:base_type]

  if base_type_symbol
    Type.new(root_manifest, [:type, self[:base_type]])
  end
end

#builtin?Boolean

TODO: replace this with primitive?

Returns:

  • (Boolean)


94
95
96
# File 'projects/manifest/src/type.rb', line 94

def builtin?
  BuiltinTypes.builtin_reference?(reference) || self[:builtin]
end

#custom?Boolean

This name is confusing. This represents a type that is 1) registered 2) not primitive 3) does not inherit from :model Because this is a Manifest::Type it is registered by definition. Non-registered types are represented in the manifest only as type declarations scattered the other categories where needed.

Returns:

  • (Boolean)


107
108
109
# File 'projects/manifest/src/type.rb', line 107

def custom?
  !primitive? && !extends_symbol?(:model)
end

#detached_entity?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'projects/manifest/src/type.rb', line 33

def detached_entity?
  !builtin? && extends_symbol?(:detached_entity)
end

#entity?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'projects/manifest/src/type.rb', line 29

def entity?
  !builtin? && extends_symbol?(:entity)
end

#extends_symbol?(symbol) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
114
115
116
117
118
119
120
121
# File 'projects/manifest/src/type.rb', line 111

def extends_symbol?(symbol)
  type = base_type

  while type
    return true if type.reference.to_sym == symbol

    type = type.base_type
  end

  false
end

#full_type_nameObject



89
90
91
# File 'projects/manifest/src/type.rb', line 89

def full_type_name
  scoped_full_name
end

#model?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'projects/manifest/src/type.rb', line 37

def model?
  !builtin? && extends_symbol?(:model)
end

#primitive?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'projects/manifest/src/type.rb', line 98

def primitive?
  declaration_data.is_a?(::String) || declaration_data.is_a?(::Symbol)
end

#target_classObject



65
66
67
68
69
70
71
72
73
# File 'projects/manifest/src/type.rb', line 65

def target_class
  if target_classes.size != 1
    # :nocov:
    raise "Can only use #target_class for types with one target class but #{name} has #{target_classes.size}"
    # :nocov:
  end

  target_classes.first
end

#to_type_declaration_from_declaration_dataObject



123
124
125
# File 'projects/manifest/src/type.rb', line 123

def to_type_declaration_from_declaration_data
  TypeDeclaration.new(root_manifest, [*manifest_path, :declaration_data])
end

#tuple?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'projects/manifest/src/type.rb', line 53

def tuple?
  !builtin? && extends_symbol?(:tuple)
end

#type_manifestObject



25
26
27
# File 'projects/manifest/src/type.rb', line 25

def type_manifest
  relevant_manifest
end

#type_nameObject



81
82
83
# File 'projects/manifest/src/type.rb', line 81

def type_name
  scoped_name
end

#type_symbolObject



85
86
87
# File 'projects/manifest/src/type.rb', line 85

def type_symbol
  scoped_full_name.to_sym
end

#types_depended_onObject



75
76
77
78
79
# File 'projects/manifest/src/type.rb', line 75

def types_depended_on
  @types_depended_on ||= self[:types_depended_on].map do |type_reference|
    Type.new(root_manifest, [:type, type_reference])
  end
end