Class: Foobara::Manifest::RootManifest

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

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary collapse

Attributes inherited from BaseManifest

#manifest_path

Instance Method Summary collapse

Methods included from TruncatedInspect

#inspect, truncating

Methods inherited from BaseManifest

#==, #[], category_to_manifest_class, #domain, #domain_reference, #eql?, #find_type, #global_domain, #global_organization, #hash, #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

Constructor Details

#initialize(root_manifest) ⇒ RootManifest

Returns a new instance of RootManifest.



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

def initialize(root_manifest)
  super(root_manifest, [])
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Foobara::Manifest::BaseManifest

Instance Attribute Details

#root_manifestObject

Returns the value of attribute root_manifest.



6
7
8
# File 'projects/manifest/src/root_manifest.rb', line 6

def root_manifest
  @root_manifest
end

Instance Method Details

#command_by_name(name) ⇒ Object



84
85
86
# File 'projects/manifest/src/root_manifest.rb', line 84

def command_by_name(name)
  Command.new(root_manifest, [:command, name])
end

#commandsObject



24
25
26
# File 'projects/manifest/src/root_manifest.rb', line 24

def commands
  organizations.map(&:commands).flatten
end

#contains?(reference, category) ⇒ Boolean

TODO: this isn’t quite right. If the thing is there but is nil or false, this should be truthy. TODO: counter-intuitive that it is not category, reference but reverse order

Returns:

  • (Boolean)


98
99
100
# File 'projects/manifest/src/root_manifest.rb', line 98

def contains?(reference, category)
  !!DataPath.value_at([category, reference], root_manifest)
end

#detached_entitiesObject



38
39
40
# File 'projects/manifest/src/root_manifest.rb', line 38

def detached_entities
  organizations.map(&:detached_entities).flatten
end

#detached_entity_by_name(name) ⇒ Object



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

def detached_entity_by_name(name)
  type = type_by_name(name)

  raise "#{name} is not a detached entity" unless type.detached_entity?

  type
end

#domain_by_name(name) ⇒ Object



88
89
90
# File 'projects/manifest/src/root_manifest.rb', line 88

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

#domainsObject



18
19
20
21
22
# File 'projects/manifest/src/root_manifest.rb', line 18

def domains
  @domains ||= DataPath.value_at(:domain, root_manifest).keys.map do |reference|
    Domain.new(root_manifest, [:domain, reference])
  end
end

#entitiesObject



42
43
44
# File 'projects/manifest/src/root_manifest.rb', line 42

def entities
  organizations.map(&:entities).flatten
end

#entity_by_name(name) ⇒ Object



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

def entity_by_name(name)
  type = type_by_name(name)

  raise "#{name} is not an entity" unless type.entity?

  type
end

#errorsObject



50
51
52
53
54
# File 'projects/manifest/src/root_manifest.rb', line 50

def errors
  @errors ||= DataPath.value_at(:error, root_manifest).keys.map do |reference|
    Error.new(root_manifest, [:error, reference])
  end
end

#lookup(reference) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'projects/manifest/src/root_manifest.rb', line 113

def lookup(reference)
  prioritized_categories = [:command, :type, :error, :domain, :organization, :processor, :processor_class]

  prioritized_categories.each do |category|
    path = [category, reference]
    raw_manifest = DataPath.value_at(path, root_manifest)

    if raw_manifest
      return self.class.category_to_manifest_class(category).new(root_manifest, path)
    end
  end

  nil
end

#lookup_path(category, reference) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'projects/manifest/src/root_manifest.rb', line 102

def lookup_path(category, reference)
  path = [category, reference]
  raw_manifest = DataPath.value_at(path, root_manifest)

  if raw_manifest
    return self.class.category_to_manifest_class(category).new(root_manifest, path)
  end

  nil
end

#model_by_name(name) ⇒ Object



72
73
74
75
76
77
78
# File 'projects/manifest/src/root_manifest.rb', line 72

def model_by_name(name)
  type = type_by_name(name)

  raise "#{name} is not a model" unless type.model?

  type
end

#modelsObject



46
47
48
# File 'projects/manifest/src/root_manifest.rb', line 46

def models
  organizations.map(&:models).flatten
end

#organization_by_name(name) ⇒ Object



92
93
94
# File 'projects/manifest/src/root_manifest.rb', line 92

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

#organizationsObject



12
13
14
15
16
# File 'projects/manifest/src/root_manifest.rb', line 12

def organizations
  @organizations ||= DataPath.value_at(:organization, root_manifest).keys.map do |reference|
    Organization.new(root_manifest, [:organization, reference])
  end
end

#queriesObject



28
29
30
# File 'projects/manifest/src/root_manifest.rb', line 28

def queries
  commands.select(&:query?)
end

#type_by_name(name) ⇒ Object



80
81
82
# File 'projects/manifest/src/root_manifest.rb', line 80

def type_by_name(name)
  Type.new(root_manifest, [:type, name])
end

#typesObject



32
33
34
35
36
# File 'projects/manifest/src/root_manifest.rb', line 32

def types
  @types ||= DataPath.value_at(:type, root_manifest).keys.map do |reference|
    Type.new(root_manifest, [:type, reference])
  end
end