Class: ActiveSP::Base
- Inherits:
-
Object
- Object
- ActiveSP::Base
- Extended by:
- Associations, Caching
- Defined in:
- lib/activesp/base.rb
Overview
The base class for all objects stored in SharePoint
Instance Method Summary collapse
-
#attribute(name) ⇒ Integer, ...
Returns the value of the attribute of the given name, or nil if this object does not have an attribute by the given name.
-
#attribute_type(name) ⇒ Field
Returns the type of the attribute by the given name, or nil if this object does not have an attribute by the given name.
-
#attribute_types ⇒ Hash{String => Field}
Returns the types of the attributes of this object as a Hash.
-
#attributes ⇒ Hash{String => Integer, Float, String, Time, Boolean, Base}
Returns the attributes of this object as a Hash.
-
#has_attribute?(name) ⇒ Boolean
Returns whether or not this object has an attribute with the given name.
-
#has_writable_attribute?(name) ⇒ Boolean
Returns whether or not this object has an attribute with the given name that can be assigned to.
-
#key ⇒ String
Returns a key that can be used to retrieve this object later on using Connection#find_by_key.
-
#method_missing(m, *a, &b) ⇒ Object
Provides convenient getters and setters for attributes.
-
#reload ⇒ void
Reloads the object from the server.
-
#save ⇒ void
Saves the object to the server.
-
#set_attribute(name, value) ⇒ Integer, ...
Sets the attribute with the given name to the given value.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a, &b) ⇒ Object
Provides convenient getters and setters for attributes. Note that no name mangling is done, so an attribute such as Title is accessed as obj.Title. The main rationale behind this is that name mangling is usually not lossless (e.g., both Title
and title
could map to the more Rubyish title
) and imperfect.
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/activesp/base.rb', line 97 def method_missing(m, *a, &b) ms = m.to_s if a.length == 0 && has_attribute?(ms) attribute(ms) elsif a.length == 1 && ms[-1] == ?= && has_writable_attribute?(ms[0..-2]) set_attribute(ms[0..-2], *a) else super end end |
Instance Method Details
#attribute(name) ⇒ Integer, ...
Returns the value of the attribute of the given name, or nil if this object does not have an attribute by the given name
71 72 73 |
# File 'lib/activesp/base.rb', line 71 def attribute(name) current_attributes[name] end |
#attribute_type(name) ⇒ Field
Returns the type of the attribute by the given name, or nil if this object does not have an attribute by the given name
78 79 80 |
# File 'lib/activesp/base.rb', line 78 def attribute_type(name) internal_attribute_types[name] end |
#attribute_types ⇒ Hash{String => Field}
Returns the types of the attributes of this object as a Hash
49 50 51 |
# File 'lib/activesp/base.rb', line 49 def attribute_types internal_attribute_types end |
#attributes ⇒ Hash{String => Integer, Float, String, Time, Boolean, Base}
Returns the attributes of this object as a Hash
42 43 44 |
# File 'lib/activesp/base.rb', line 42 def attributes current_attributes end |
#has_attribute?(name) ⇒ Boolean
Returns whether or not this object has an attribute with the given name
57 58 59 |
# File 'lib/activesp/base.rb', line 57 def has_attribute?(name) current_attributes.has_key?(name) end |
#has_writable_attribute?(name) ⇒ Boolean
Returns whether or not this object has an attribute with the given name that can be assigned to
64 65 66 |
# File 'lib/activesp/base.rb', line 64 def has_writable_attribute?(name) has_attribute?(name) and attr = internal_attribute_types[name] and !attr.ReadOnly end |
#key ⇒ String
Returns a key that can be used to retrieve this object later on using Connection#find_by_key
36 37 38 |
# File 'lib/activesp/base.rb', line 36 def key raise "This is here for documentation purposes only" end |
#reload ⇒ void
This method returns an undefined value.
Reloads the object from the server
110 111 |
# File 'lib/activesp/base.rb', line 110 def reload end |
#save ⇒ void
This method returns an undefined value.
Saves the object to the server. Raises an exception when the save fails
115 116 |
# File 'lib/activesp/base.rb', line 115 def save end |
#set_attribute(name, value) ⇒ Integer, ...
Sets the attribute with the given name to the given value
87 88 89 90 91 |
# File 'lib/activesp/base.rb', line 87 def set_attribute(name, value) has_attribute?(name) and field = attribute_type(name) and internal_attribute_types[name] or raise ArgumentError, "#{self} has no field by the name #{name}" !field.ReadOnly or raise ArgumentError, "field #{name} of #{self} is read-only" current_attributes[name] = type_check_attribute(field, value) end |