Class: Foobara::Manifest::TypeDeclaration

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

Direct Known Subclasses

Array

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, #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
# File 'foobara-0.2.2/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)


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

def allows_nil?
  allow_nil
end

#array?Boolean

Returns:

  • (Boolean)


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

def array?
  type.to_sym == :array
end

#attribute?Boolean

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

Returns:

  • (Boolean)


37
38
39
40
41
42
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 37

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



53
54
55
56
57
58
59
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 53

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)


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

def attributes?
  type.to_sym == :attributes
end

#custom?Boolean

Returns:

  • (Boolean)


91
92
93
94
95
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 91

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

  @custom = to_type.custom?
end

#defaultObject



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

def default
  parent_attributes.default_for(attribute_name)
end

#detached_entity?Boolean

Returns:

  • (Boolean)


113
114
115
116
117
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 113

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

  @detached_entity = to_type.detached_entity?
end

#entity?Boolean

Returns:

  • (Boolean)


135
136
137
138
139
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 135

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

  @entity = to_type.entity?
end

#model?Boolean

Returns:

  • (Boolean)


85
86
87
88
89
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 85

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

  @model = to_type.model?
end

#parent_attributesObject

rubocop:enable Naming/MemoizedInstanceVariableName



45
46
47
48
49
50
51
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 45

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

#primitive?Boolean

Returns:

  • (Boolean)


97
98
99
100
101
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 97

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

#reference?Boolean

Returns:

  • (Boolean)


186
187
188
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 186

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

#required?Boolean

Returns:

  • (Boolean)


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

def required?
  parent_attributes.required?(attribute_name)
end

#sensitiveObject



170
171
172
173
174
175
176
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 170

def sensitive
  if reference?
    false
  else
    super
  end
end

#sensitive?Boolean

Returns:

  • (Boolean)


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

def sensitive?
  sensitive || sensitive_exposed
end

#sensitive_exposedObject



178
179
180
181
182
183
184
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 178

def sensitive_exposed
  if reference?
    false
  else
    super
  end
end

#to_detached_entityObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 119

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



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 141

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



103
104
105
106
107
108
109
110
111
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 103

def to_model
  raise "not an model" unless model?

  type = to_type

  raise "not an model" unless type.model?

  type
end

#to_typeObject



157
158
159
160
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 157

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

#typeObject



162
163
164
165
166
167
168
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 162

def type
  if reference?
    relevant_manifest
  else
    super
  end
end

#type_declaration_manifestObject



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

def type_declaration_manifest
  relevant_manifest
end

#type_symbolObject



31
32
33
# File 'foobara-0.2.2/projects/manifest/src/foobara/manifest/type_declaration.rb', line 31

def type_symbol
  to_type.type_symbol
end