Class: Msgraph::Api::Resource::Base
- Inherits:
-
Object
- Object
- Msgraph::Api::Resource::Base
show all
- Defined in:
- lib/msgraph/api/resource/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(parent = nil, resource_name: nil, **attributes) ⇒ Base
Returns a new instance of Base.
23
24
25
26
27
|
# File 'lib/msgraph/api/resource/base.rb', line 23
def initialize(parent=nil, resource_name: nil, **attributes)
self.parent = parent
self.resource_name = resource_name || self.class.resource_name
self.attributes = attributes
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **options) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/msgraph/api/resource/base.rb', line 29
def method_missing(name, *args, **options)
attr_name = name.to_s.to_graph_attribute
if !self.attributes.has_key?(attr_name) && @loading != true
@loading = true
self.attributes = get
@loading = false
end
if self.attributes.has_key?(attr_name)
self.attributes[attr_name]
else
super(name, *args, **options)
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
6
7
8
|
# File 'lib/msgraph/api/resource/base.rb', line 6
def attributes
@attributes
end
|
#parent ⇒ Object
Returns the value of attribute parent.
6
7
8
|
# File 'lib/msgraph/api/resource/base.rb', line 6
def parent
@parent
end
|
#resource_name ⇒ Object
Returns the value of attribute resource_name.
6
7
8
|
# File 'lib/msgraph/api/resource/base.rb', line 6
def resource_name
@resource_name
end
|
Class Method Details
.lists(name, as: nil, resource_name: nil) ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/msgraph/api/resource/base.rb', line 13
def self.lists(name, as: nil, resource_name: nil)
class_name = "Msgraph::Api::Resource::#{name.to_s.classify}"
as ||= class_name.constantize
resource_name ||= name.to_s.to_graph_resource
define_method(name) do
List.new(self, as, resource_name)
end
end
|
.resource_name(relative_path = nil) ⇒ Object
8
9
10
11
|
# File 'lib/msgraph/api/resource/base.rb', line 8
def self.resource_name(relative_path=nil)
@resource_name = relative_path unless relative_path.nil?
@resource_name ||= self.name.demodulize.to_graph_resource
end
|
Instance Method Details
#client ⇒ Object
50
51
52
|
# File 'lib/msgraph/api/resource/base.rb', line 50
def client
parent.client
end
|
#resource_path ⇒ Object
46
47
48
|
# File 'lib/msgraph/api/resource/base.rb', line 46
def resource_path
parent.resource_path.join_path(self.resource_name, self.attributes[:id] || self.attributes["id"])
end
|
#user ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/msgraph/api/resource/base.rb', line 54
def user
if self.is_a?(User)
return self
else
return parent.user
end
end
|