Class: Foobara::Manifest::RootManifest

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

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary collapse

Attributes inherited from BaseManifest

#path

Instance Method Summary collapse

Methods included from TruncatedInspect

#inspect, truncating

Methods inherited from BaseManifest

#==, #[], category_to_manifest_class, #domain, #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, #relevant_manifest, #respond_to_missing?, #scoped_category

Constructor Details

#initialize(root_manifest) ⇒ RootManifest

Returns a new instance of RootManifest.



8
9
10
# File 'foobara-0.1.7/projects/manifest/src/foobara/manifest/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 'foobara-0.1.7/projects/manifest/src/foobara/manifest/root_manifest.rb', line 6

def root_manifest
  @root_manifest
end

Instance Method Details

#command_by_name(name) ⇒ Object



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

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

#commandsObject



24
25
26
# File 'foobara-0.1.7/projects/manifest/src/foobara/manifest/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.

Returns:

  • (Boolean)


93
94
95
# File 'foobara-0.1.7/projects/manifest/src/foobara/manifest/root_manifest.rb', line 93

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

#detached_entitiesObject



34
35
36
# File 'foobara-0.1.7/projects/manifest/src/foobara/manifest/root_manifest.rb', line 34

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

#detached_entity_by_name(name) ⇒ Object



52
53
54
55
56
57
58
# File 'foobara-0.1.7/projects/manifest/src/foobara/manifest/root_manifest.rb', line 52

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



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

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

#domainsObject



18
19
20
21
22
# File 'foobara-0.1.7/projects/manifest/src/foobara/manifest/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



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

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

#entity_by_name(name) ⇒ Object



60
61
62
63
64
65
66
# File 'foobara-0.1.7/projects/manifest/src/foobara/manifest/root_manifest.rb', line 60

def entity_by_name(name)
  type = type_by_name(name)

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

  type
end

#errorsObject



46
47
48
49
50
# File 'foobara-0.1.7/projects/manifest/src/foobara/manifest/root_manifest.rb', line 46

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

#lookup(reference) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'foobara-0.1.7/projects/manifest/src/foobara/manifest/root_manifest.rb', line 108

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



97
98
99
100
101
102
103
104
105
106
# File 'foobara-0.1.7/projects/manifest/src/foobara/manifest/root_manifest.rb', line 97

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



68
69
70
71
72
73
74
# File 'foobara-0.1.7/projects/manifest/src/foobara/manifest/root_manifest.rb', line 68

def model_by_name(name)
  type = type_by_name(name)

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

  type
end

#modelsObject



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

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

#organization_by_name(name) ⇒ Object



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

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

#organizationsObject



12
13
14
15
16
# File 'foobara-0.1.7/projects/manifest/src/foobara/manifest/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

#type_by_name(name) ⇒ Object



76
77
78
# File 'foobara-0.1.7/projects/manifest/src/foobara/manifest/root_manifest.rb', line 76

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

#typesObject



28
29
30
31
32
# File 'foobara-0.1.7/projects/manifest/src/foobara/manifest/root_manifest.rb', line 28

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