Class: MicrosoftGraph::ClassBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/microsoft_graph/class_builder.rb

Constant Summary collapse

@@loaded =
false

Class Method Summary collapse

Class Method Details

.load!(service) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/microsoft_graph/class_builder.rb', line 5

def self.load!(service)
  if !@@loaded
    @service_namespace = service.namespace
    service.entity_types.each do |entity_type|
      create_class! entity_type
    end

    service.complex_types.each do |complex_type|
      create_class! complex_type
    end

    service.entity_sets.each do |entity_set|
      add_graph_association! entity_set
    end

    service.actions.each do |action|
      add_action_method! action
    end

    service.functions.each do |function|
      add_function_method! function
    end

    service.singletons.each do |singleton|
      class_name = classify(singleton.type_name)
      MicrosoftGraph.instance_eval do
        resource_name = singleton.name
        define_method(OData.convert_to_snake_case(resource_name)) do
          MicrosoftGraph
            .const_get(class_name)
            .new(
              graph:         self,
              resource_name: resource_name,
              parent:        self
            ).tap(&:fetch)
        end
      end
    end

    MicrosoftGraph.instance_eval do
      define_method(:navigation_properties) do
        service.entity_sets
          .concat(service.singletons)
          .map { |navigation_property|
            [navigation_property.name.to_sym, navigation_property]
          }.to_h
      end
    end

    @@loaded = true
  end
end

.loaded?Boolean


58
59
60
# File 'lib/microsoft_graph/class_builder.rb', line 58

def self.loaded?
  @@loaded
end