Class: Foobara::Manifest::Type

Inherits:
BaseManifest show all
Defined in:
foobara-0.0.110/projects/manifest/src/foobara/manifest/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

#path, #root_manifest

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseManifest

#==, #[], category_to_manifest_class, #domain, #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, #relevant_manifest, #respond_to_missing?, #scoped_category

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 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type.rb', line 8

def new(root_manifest, path)
  type = super

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

  type
end

Instance Method Details

#base_typeObject



41
42
43
44
45
46
47
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type.rb', line 41

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

Returns:

  • (Boolean)


73
74
75
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type.rb', line 73

def builtin?
  BuiltinTypes.builtin_reference?(reference)
end

#custom?Boolean

Not sure the best way to define this…

Returns:

  • (Boolean)


78
79
80
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type.rb', line 78

def custom?
  !builtin? && !model?
end

#detached_entity?Boolean

Returns:

  • (Boolean)


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

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

#entity?Boolean

Returns:

  • (Boolean)


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

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

#extends_symbol?(symbol) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
85
86
87
88
89
90
91
92
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type.rb', line 82

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



69
70
71
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type.rb', line 69

def full_type_name
  scoped_full_name
end

#model?Boolean

Returns:

  • (Boolean)


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

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

#target_classObject



49
50
51
52
53
54
55
56
57
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type.rb', line 49

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



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

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

#type_manifestObject



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

def type_manifest
  relevant_manifest
end

#type_nameObject



65
66
67
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type.rb', line 65

def type_name
  scoped_name
end

#types_depended_onObject



59
60
61
62
63
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type.rb', line 59

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