Class: MicrosoftGraph::Base

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

Direct Known Subclasses

BaseEntity

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/microsoft_graph/base.rb', line 4

def initialize(options = {})
  @cached_navigation_property_values = {}
  @cached_property_values            = {}
  if options[:attributes]
    initialize_serialized_properties(options[:attributes], options[:persisted])
  end
  @dirty = ! options[:persisted]
  @dirty_properties = if @dirty
    @cached_property_values.keys.inject({}) do |result, key|
      result[key] = true
      result
    end
  else
    {}
  end
end

Instance Method Details

#as_json(options = {}) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/microsoft_graph/base.rb', line 29

def as_json(options = {})
  (if options[:only]
    @cached_property_values.select { |key,v| options[:only].include? key }
  elsif options[:except]
    @cached_property_values.reject { |key,v| options[:except].include? key }
  else
    @cached_property_values
  end).inject({}) do |result, (k,v)|
    k = OData.convert_to_camel_case(k) if options[:convert_to_camel_case]
    result[k.to_s] = v.respond_to?(:as_json) ? v.as_json(options) : v
    result
  end
end

#dirty?Boolean


47
48
49
50
51
# File 'lib/microsoft_graph/base.rb', line 47

def dirty?
  @dirty || @cached_property_values.any? { |key, value|
    value.respond_to?(:dirty?) && value.dirty?
  }
end

#mark_cleanObject


53
54
55
56
57
58
59
# File 'lib/microsoft_graph/base.rb', line 53

def mark_clean
  @dirty = false
  @dirty_properties = {}
  @cached_property_values.each { |key, value|
    value.respond_to?(:mark_clean) && value.mark_clean
  }
end

#odata_typeObject


25
26
27
# File 'lib/microsoft_graph/base.rb', line 25

def odata_type
  self.class.const_get("ODATA_TYPE").name
end

#propertiesObject


21
22
23
# File 'lib/microsoft_graph/base.rb', line 21

def properties
  {}
end

#to_json(options = {}) ⇒ Object


43
44
45
# File 'lib/microsoft_graph/base.rb', line 43

def to_json(options = {})
  as_json(options).to_json
end