Class: Foobara::Manifest::TypeDeclaration

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

Direct Known Subclasses

Array, Attributes, Tuple

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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'projects/manifest/src/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.manifest_path)
    when :array
      Array.new(type_declaration.root_manifest, type_declaration.manifest_path)
    when :tuple
      Tuple.new(type_declaration.root_manifest, type_declaration.manifest_path)
    else
      type_declaration
    end
  else
    type_declaration
  end
end

Instance Method Details

#allows_nil?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'projects/manifest/src/type_declaration.rb', line 71

def allows_nil?
  allow_nil
end

#array?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'projects/manifest/src/type_declaration.rb', line 83

def array?
  type.to_sym == :array
end

#associative_array?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'projects/manifest/src/type_declaration.rb', line 91

def associative_array?
  type.to_sym == :associative_array
end

#attribute?Boolean

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

Returns:

  • (Boolean)


39
40
41
42
43
44
# File 'projects/manifest/src/type_declaration.rb', line 39

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

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

#attribute_nameObject



55
56
57
58
59
60
61
# File 'projects/manifest/src/type_declaration.rb', line 55

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

  raise "Not an attribute" unless attribute?

  @attribute_name = manifest_path[-1]
end

#attributes?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'projects/manifest/src/type_declaration.rb', line 79

def attributes?
  type.to_sym == :attributes
end

#custom?Boolean

Returns:

  • (Boolean)


101
102
103
104
105
# File 'projects/manifest/src/type_declaration.rb', line 101

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

  @custom = to_type.custom?
end

#defaultObject



67
68
69
# File 'projects/manifest/src/type_declaration.rb', line 67

def default
  parent_attributes.default_for(attribute_name)
end

#detached_entity?Boolean

Returns:

  • (Boolean)


123
124
125
126
127
# File 'projects/manifest/src/type_declaration.rb', line 123

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

  @detached_entity = to_type.detached_entity?
end

#entity?Boolean

Returns:

  • (Boolean)


145
146
147
148
149
# File 'projects/manifest/src/type_declaration.rb', line 145

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

  @entity = to_type.entity?
end

#model?Boolean

Returns:

  • (Boolean)


95
96
97
98
99
# File 'projects/manifest/src/type_declaration.rb', line 95

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

  @model = to_type.model?
end

#parent_attributesObject

rubocop:enable Naming/MemoizedInstanceVariableName



47
48
49
50
51
52
53
# File 'projects/manifest/src/type_declaration.rb', line 47

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

  raise "Not an attribute" unless attribute?

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

#primitive?Boolean

Returns:

  • (Boolean)


107
108
109
110
111
# File 'projects/manifest/src/type_declaration.rb', line 107

def primitive?
  if reference?
    to_type.primitive?
  end
end

#reference?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'projects/manifest/src/type_declaration.rb', line 196

def reference?
  relevant_manifest.is_a?(::Symbol) || relevant_manifest.is_a?(::String)
end

#required?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'projects/manifest/src/type_declaration.rb', line 63

def required?
  parent_attributes.required?(attribute_name)
end

#sensitiveObject



180
181
182
183
184
185
186
# File 'projects/manifest/src/type_declaration.rb', line 180

def sensitive
  if reference?
    false
  else
    super
  end
end

#sensitive?Boolean

Returns:

  • (Boolean)


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

def sensitive?
  sensitive || sensitive_exposed
end

#sensitive_exposedObject



188
189
190
191
192
193
194
# File 'projects/manifest/src/type_declaration.rb', line 188

def sensitive_exposed
  if reference?
    false
  else
    super
  end
end

#to_detached_entityObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'projects/manifest/src/type_declaration.rb', line 129

def to_detached_entity
  raise "not an detached_entity" unless detached_entity?

  if to_type.primitive?
    # :nocov:
    raise "detached_entity extension instead of an detached_entity"
    # :nocov:
  end

  type = to_type

  raise "not an detached_entity" unless type.detached_entity?

  type
end

#to_entityObject



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'projects/manifest/src/type_declaration.rb', line 151

def to_entity
  raise "not an entity" unless entity?

  if to_type.primitive?
    # :nocov:
    raise "entity extension instead of an entity"
    # :nocov:
  end

  type = to_type

  raise "not an entity" unless type.entity?

  type
end

#to_modelObject



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

def to_model
  raise "not an model" unless model?

  type = to_type

  raise "not an model" unless type.model?

  type
end

#to_typeObject



167
168
169
170
# File 'projects/manifest/src/type_declaration.rb', line 167

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

#tuple?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'projects/manifest/src/type_declaration.rb', line 87

def tuple?
  type.to_sym == :tuple
end

#typeObject



172
173
174
175
176
177
178
# File 'projects/manifest/src/type_declaration.rb', line 172

def type
  if reference?
    relevant_manifest
  else
    super
  end
end

#type_declaration_manifestObject



75
76
77
# File 'projects/manifest/src/type_declaration.rb', line 75

def type_declaration_manifest
  relevant_manifest
end

#type_symbolObject



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

def type_symbol
  to_type.type_symbol
end