Class: Foobara::Manifest::BaseManifest

Inherits:
Object
  • Object
show all
Includes:
TruncatedInspect
Defined in:
foobara-0.5.8/projects/manifest/src/base_manifest.rb

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TruncatedInspect

#inspect, truncating

Constructor Details

#initialize(root_manifest, manifest_path) ⇒ BaseManifest

Returns a new instance of BaseManifest.



53
54
55
56
57
58
59
60
61
62
# File 'projects/manifest/src/base_manifest.rb', line 53

def initialize(root_manifest, manifest_path)
  self.root_manifest = root_manifest
  self.manifest_path = manifest_path

  if relevant_manifest.nil?
    # :nocov:
    raise InvalidPath, "invalid path #{manifest_path}"
    # :nocov:
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
# File 'projects/manifest/src/base_manifest.rb', line 123

def method_missing(method_name, *, &)
  if key?(method_name)
    self[method_name]
  elsif optional_key?(method_name)
    self.class.optional_key_defaults[method_name.to_sym]
  else
    # :nocov:
    super
    # :nocov:
  end
end

Class Attribute Details

.category_symbolObject

Returns the value of attribute category_symbol.



11
12
13
# File 'projects/manifest/src/base_manifest.rb', line 11

def category_symbol
  @category_symbol
end

Instance Attribute Details

#manifest_pathObject

Returns the value of attribute manifest_path.



8
9
10
# File 'projects/manifest/src/base_manifest.rb', line 8

def manifest_path
  @manifest_path
end

#root_manifestObject

Returns the value of attribute root_manifest.



8
9
10
# File 'projects/manifest/src/base_manifest.rb', line 8

def root_manifest
  @root_manifest
end

Class Method Details

.category_to_manifest_class(category_symbol) ⇒ Object



44
45
46
47
48
49
50
# File 'projects/manifest/src/base_manifest.rb', line 44

def category_to_manifest_class(category_symbol)
  category_symbol = category_symbol.to_sym

  Util.descendants(BaseManifest).find do |manifest_class|
    manifest_class.category_symbol == category_symbol
  end
end

.optional_key(value, default: nil) ⇒ Object



40
41
42
# File 'projects/manifest/src/base_manifest.rb', line 40

def optional_key(value, default: nil)
  optional_keys(value, default:)
end

.optional_key_defaultsObject



36
37
38
# File 'projects/manifest/src/base_manifest.rb', line 36

def optional_key_defaults
  @optional_key_defaults ||= {}
end

.optional_keys(*values, default: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'projects/manifest/src/base_manifest.rb', line 13

def optional_keys(*values, default: nil)
  if values.empty?
    @optional_keys ||= if superclass == Object
                         Set.new
                       else
                         superclass.optional_keys.dup
                       end
  else
    if default
      default = default.freeze
    end

    values.each do |value|
      value = value.to_sym
      optional_keys << value

      if default
        optional_key_defaults[value] = default
      end
    end
  end
end

Instance Method Details

#==(other) ⇒ Object



158
159
160
# File 'projects/manifest/src/base_manifest.rb', line 158

def ==(other)
  other.class == self.class && other.symbol_path == symbol_path
end

#[](method_name) ⇒ Object



135
136
137
138
139
140
141
# File 'projects/manifest/src/base_manifest.rb', line 135

def [](method_name)
  if relevant_manifest.key?(method_name.to_sym)
    relevant_manifest[method_name.to_sym]
  elsif relevant_manifest.key?(method_name.to_s)
    relevant_manifest[method_name.to_s]
  end
end

#domainObject



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

def domain
  Domain.new(root_manifest, [:domain, domain_reference])
end

#domain_referenceObject



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

def domain_reference
  self[:domain]
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


162
163
164
# File 'projects/manifest/src/base_manifest.rb', line 162

def eql?(other)
  self == other
end

#find_type(type_declaration) ⇒ Object



109
110
111
112
113
# File 'projects/manifest/src/base_manifest.rb', line 109

def find_type(type_declaration)
  type_symbol = type_declaration.type

  Type.new(root_manifest, [:type, type_symbol])
end

#global_domainObject



115
116
117
# File 'projects/manifest/src/base_manifest.rb', line 115

def global_domain
  Domain.new(root_manifest, [:domain, :"global_organization::global_domain"])
end

#global_organizationObject



119
120
121
# File 'projects/manifest/src/base_manifest.rb', line 119

def global_organization
  Organization.new(root_manifest, [:organization, :global_organization])
end

#hashObject



170
171
172
# File 'projects/manifest/src/base_manifest.rb', line 170

def hash
  @hash ||= [self.class, symbol_path].hash
end

#key?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


143
144
145
# File 'projects/manifest/src/base_manifest.rb', line 143

def key?(method_name)
  relevant_manifest.key?(method_name.to_sym) || relevant_manifest.key?(method_name.to_s)
end

#optional_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


147
148
149
150
151
# File 'projects/manifest/src/base_manifest.rb', line 147

def optional_key?(key)
  if key.is_a?(::Symbol) || key.is_a?(::String)
    self.class.optional_keys.include?(key.to_sym)
  end
end

#organizationObject



79
80
81
82
83
# File 'projects/manifest/src/base_manifest.rb', line 79

def organization
  organization_reference = self[:organization]

  Organization.new(root_manifest, [:organization, organization_reference])
end

#parentObject



85
86
87
88
89
90
91
# File 'projects/manifest/src/base_manifest.rb', line 85

def parent
  if parent_category
    parent_class = self.class.category_to_manifest_class(parent_category)

    parent_class&.new(root_manifest, self[:parent])
  end
end

#parent_categoryObject



93
94
95
# File 'projects/manifest/src/base_manifest.rb', line 93

def parent_category
  self[:parent]&.first
end

#parent_nameObject



97
98
99
# File 'projects/manifest/src/base_manifest.rb', line 97

def parent_name
  self[:parent]&.last
end

#pathObject



64
65
66
67
68
69
# File 'projects/manifest/src/base_manifest.rb', line 64

def path
  # :nocov:
  warn "[DEPRECATION] `path` is deprecated. Please use `manifest_path` instead."
  manifest_path
  # :nocov:
end

#relevant_manifestObject



105
106
107
# File 'projects/manifest/src/base_manifest.rb', line 105

def relevant_manifest
  @relevant_manifest ||= Foobara::DataPath.values_at(manifest_path, root_manifest).first
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


153
154
155
156
# File 'projects/manifest/src/base_manifest.rb', line 153

def respond_to_missing?(method_name, include_private = false)
  relevant_manifest.key?(method_name.to_sym) || relevant_manifest.key?(method_name.to_s) ||
    optional_key?(method_name) || super
end

#scoped_categoryObject



101
102
103
# File 'projects/manifest/src/base_manifest.rb', line 101

def scoped_category
  self[:scoped_category]
end

#symbol_pathObject



166
167
168
# File 'projects/manifest/src/base_manifest.rb', line 166

def symbol_path
  @symbol_path ||= manifest_path.map(&:to_sym)
end