Class: Foobara::Manifest::TypeDeclaration

Inherits:
BaseManifest show all
Defined in:
foobara-0.0.110/projects/manifest/src/foobara/manifest/type_declaration.rb

Direct Known Subclasses

Array, Attributes

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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type_declaration.rb', line 9

def new(root_manifest, path)
  type_declaration = super

  if self == TypeDeclaration
    case type_declaration.type.to_sym
    when :attributes
      Attributes.new(type_declaration.root_manifest, type_declaration.path)
    when :array
      Array.new(type_declaration.root_manifest, type_declaration.path)
    else
      type_declaration
    end
  else
    type_declaration
  end
end

Instance Method Details

#allows_nil?Boolean

Returns:

  • (Boolean)


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

def allows_nil?
  allow_nil
end

#array?Boolean

Returns:

  • (Boolean)


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

def array?
  type.to_sym == :array
end

#attribute?Boolean

rubocop:disable Naming/MemoizedInstanceVariableName TODO: create an Attribute class to encapsulate this situation

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type_declaration.rb', line 33

def attribute?
  return @is_attribute if defined?(@is_attribute)

  parent_path_atom = path[2..][-2]
  @is_attribute = [:element_type_declarations, "element_type_declarations"].include?(parent_path_atom)
end

#attribute_nameObject



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

def attribute_name
  return @attribute_name if defined?(@attribute_name)

  raise "Not an attribute" unless attribute?

  @attribute_name = path[-1]
end

#attributes?Boolean

Returns:

  • (Boolean)


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

def attributes?
  type.to_sym == :attributes
end

#custom?Boolean

Returns:

  • (Boolean)


87
88
89
90
91
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type_declaration.rb', line 87

def custom?
  return @custom if defined?(@custom)

  @custom = to_type.custom?
end

#defaultObject



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

def default
  parent_attributes.default_for(attribute_name)
end

#detached_entity?Boolean

Returns:

  • (Boolean)


103
104
105
106
107
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type_declaration.rb', line 103

def detached_entity?
  return @detached_entity if defined?(@detached_entity)

  @detached_entity = to_type.detached_entity?
end

#entity?Boolean

Returns:

  • (Boolean)


120
121
122
123
124
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type_declaration.rb', line 120

def entity?
  return @entity if defined?(@entity)

  @entity = to_type.entity?
end

#model?Boolean

Returns:

  • (Boolean)


81
82
83
84
85
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type_declaration.rb', line 81

def model?
  return @model if defined?(@model)

  @model = to_type.model?
end

#parent_attributesObject

rubocop:enable Naming/MemoizedInstanceVariableName



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

def parent_attributes
  return @parent_attributes if defined?(@parent_attributes)

  raise "Not an attribute" unless attribute?

  @parent_attributes = Attributes.new(root_manifest, path[0..-3])
end

#required?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type_declaration.rb', line 57

def required?
  parent_attributes.required?(attribute_name)
end

#sensitive?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type_declaration.rb', line 27

def sensitive?
  sensitive || sensitive_exposed
end

#to_detached_entityObject



109
110
111
112
113
114
115
116
117
118
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type_declaration.rb', line 109

def to_detached_entity
  raise "not an detached_entity" unless detached_entity?
  raise "detached_entity extension instead of an detached_entity" unless relevant_manifest.size == 1

  type = to_type

  raise "not an detached_entity" unless type.detached_entity?

  type
end

#to_entityObject



126
127
128
129
130
131
132
133
134
135
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type_declaration.rb', line 126

def to_entity
  raise "not an entity" unless entity?
  raise "entity extension instead of an entity" unless relevant_manifest.size == 1

  type = to_type

  raise "not an entity" unless type.entity?

  type
end

#to_modelObject



93
94
95
96
97
98
99
100
101
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type_declaration.rb', line 93

def to_model
  raise "not an model" unless model?

  type = to_type

  raise "not an model" unless type.model?

  type
end

#to_typeObject



137
138
139
140
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/type_declaration.rb', line 137

def to_type
  # awkward??
  @to_type ||= find_type(self)
end

#type_declaration_manifestObject



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

def type_declaration_manifest
  relevant_manifest
end