Class: MicrosoftGraph::Base
- Inherits:
-
Object
- Object
- MicrosoftGraph::Base
- Defined in:
- lib/microsoft_graph/base.rb
Direct Known Subclasses
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #dirty? ⇒ Boolean
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #mark_clean ⇒ Object
- #odata_type ⇒ Object
- #properties ⇒ Object
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of 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( = {}) @cached_navigation_property_values = {} @cached_property_values = {} if [:attributes] initialize_serialized_properties([:attributes], [:persisted]) end @dirty = ! [: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( = {}) (if [:only] @cached_property_values.select { |key,v| [:only].include? key } elsif [:except] @cached_property_values.reject { |key,v| [:except].include? key } else @cached_property_values end).inject({}) do |result, (k,v)| k = OData.convert_to_camel_case(k) if [:convert_to_camel_case] result[k.to_s] = v.respond_to?(:as_json) ? v.as_json() : 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_clean ⇒ Object
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_type ⇒ Object
25 26 27 |
# File 'lib/microsoft_graph/base.rb', line 25 def odata_type self.class.const_get("ODATA_TYPE").name end |
#properties ⇒ Object
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( = {}) as_json().to_json end |