Class: MicrosoftGraph::Collection
- Inherits:
-
Object
- Object
- MicrosoftGraph::Collection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/microsoft_graph/collection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#graph ⇒ Object
Returns the value of attribute graph.
Instance Method Summary collapse
- #<<(value) ⇒ Object
- #[]=(index, value) ⇒ Object
- #as_json(options = {}) ⇒ Object
- #dirty? ⇒ Boolean
- #each ⇒ Object
-
#initialize(type, initial_values = []) ⇒ Collection
constructor
A new instance of Collection.
- #mark_clean ⇒ Object
- #new(attributes = {}) ⇒ Object
- #parental_chain ⇒ Object
Constructor Details
#initialize(type, initial_values = []) ⇒ Collection
Returns a new instance of Collection.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/microsoft_graph/collection.rb', line 12 def initialize(type, initial_values = []) @type = type @dirty = false @internal_values = if klass = MicrosoftGraph::ClassBuilder.get_namespaced_class(type.member_type.name) initial_values.map { |v| klass.new(attributes: v) } else initial_values end end |
Instance Attribute Details
#graph ⇒ Object
Returns the value of attribute graph.
8 9 10 |
# File 'lib/microsoft_graph/collection.rb', line 8 def graph @graph end |
Instance Method Details
#<<(value) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/microsoft_graph/collection.rb', line 29 def <<(value) unless @type.valid_value?(value) raise MicrosoftGraph::TypeError.new( "Value \"#{value}\" does not match type #{@type.member_type.name}" ) end @dirty = true @internal_values << value self end |
#[]=(index, value) ⇒ Object
40 41 42 43 44 |
# File 'lib/microsoft_graph/collection.rb', line 40 def []=(index, value) raise MicrosoftGraph::TypeError unless @type.valid_value?(value) @dirty = true values[index] = value end |
#as_json(options = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/microsoft_graph/collection.rb', line 59 def as_json( = {}) values.map do |value| if value.respond_to? :as_json value.as_json() else value end end end |
#dirty? ⇒ Boolean
46 47 48 49 50 |
# File 'lib/microsoft_graph/collection.rb', line 46 def dirty? @dirty || @internal_values.any? { |value| value.respond_to?(:dirty?) && value.dirty? } end |
#each ⇒ Object
23 24 25 26 27 |
# File 'lib/microsoft_graph/collection.rb', line 23 def each values.each do |value| yield value end end |
#mark_clean ⇒ Object
52 53 54 55 56 57 |
# File 'lib/microsoft_graph/collection.rb', line 52 def mark_clean @dirty = false @internal_values.each { |value| value.respond_to?(:mark_clean) && value.mark_clean } end |
#new(attributes = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/microsoft_graph/collection.rb', line 69 def new(attributes = {}) klass = MicrosoftGraph::ClassBuilder.get_namespaced_class(@type.member_type.name) if klass new_instance = klass.new(graph: graph, attributes: attributes) self << new_instance new_instance else raise NoMethodError.new("undefined method `new' for #{as_json}:#{self.class}") end end |
#parental_chain ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/microsoft_graph/collection.rb', line 80 def parental_chain if parent && parent.respond_to?(:parental_chain) parent.parental_chain.concat([parent]) else [parent] end end |