Class: TheCity::ApiObject
- Inherits:
-
Object
- Object
- TheCity::ApiObject
- Defined in:
- lib/api/api_object.rb
Overview
This class is the base class for all TheCity objects and is meant to be inherited.
Direct Known Subclasses
Address, Barcode, Campus, Checkin, Church, Donation, DonationExport, Family, FamilyMember, Fund, Group, GroupAddress, GroupCheckin, GroupCheckinEvent, GroupEventAttendance, GroupExport, GroupInvitation, GroupRole, GroupTag, Invitation, Metric, MetricMeasurement, MetricMeasurementValues, Pledge, Role, Skill, Tag, Terminology, User, UserAddress, UserAdminPrivilege, UserBarcode, UserCount, UserFamilyMember, UserInvitation, UserNote, UserProcess, UserProcessAnswer, UserRole, UserSkill, WebHook
Instance Attribute Summary collapse
-
#error_messages ⇒ Object
readonly
Returns the value of attribute error_messages.
-
#marked_for_destruction ⇒ Object
readonly
Returns the value of attribute marked_for_destruction.
Class Method Summary collapse
-
.__tc_attributes ⇒ Object
A list of tc_attr_accessors that have been specified.
-
.tc_attr_accessor(*vars) ⇒ Object
Used to specify a list of getters and setters.
Instance Method Summary collapse
-
#delete ⇒ Object
Delete this object.
-
#initialize_from_json_object(object_attributes) ⇒ Object
Initializes the current object from the JSON data that was loaded into the Hash.
-
#is_deleted? ⇒ Boolean
Returns the status of the current object.
-
#save ⇒ Object
Save this object.
-
#set_attributes(attribute_data) ⇒ Object
Sets the current object’s attributes from a hash.
-
#to_attributes ⇒ Object
Gets the current object’s attributes in a Hash.
Instance Attribute Details
#error_messages ⇒ Object (readonly)
Returns the value of attribute error_messages.
6 7 8 |
# File 'lib/api/api_object.rb', line 6 def @error_messages end |
#marked_for_destruction ⇒ Object (readonly)
Returns the value of attribute marked_for_destruction.
6 7 8 |
# File 'lib/api/api_object.rb', line 6 def marked_for_destruction @marked_for_destruction end |
Class Method Details
.__tc_attributes ⇒ Object
A list of tc_attr_accessors that have been specified.
18 19 20 |
# File 'lib/api/api_object.rb', line 18 def self.__tc_attributes @__tc_attributes end |
.tc_attr_accessor(*vars) ⇒ Object
Used to specify a list of getters and setters.
10 11 12 13 14 |
# File 'lib/api/api_object.rb', line 10 def self.tc_attr_accessor(*vars) @__tc_attributes ||= [] @__tc_attributes.concat(vars) attr_accessor(*vars) end |
Instance Method Details
#delete ⇒ Object
Delete this object.
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/api/api_object.rb', line 85 def delete writer = @writer_object.new(self.to_attributes) result = writer.delete_object if result === false @error_messages = writer. else @_deleted = true end result === false ? false : true end |
#initialize_from_json_object(object_attributes) ⇒ Object
Initializes the current object from the JSON data that was loaded into the Hash
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/api/api_object.rb', line 25 def initialize_from_json_object(object_attributes) if object_attributes.is_a?( Hash ) object_attributes.each do |key, value| method_to_call = "#{key.to_s.downcase.gsub(' ', '_')}=" if respond_to?(method_to_call) self.send(method_to_call, value) else # puts method_to_call # Show the missing methods end end end end |
#is_deleted? ⇒ Boolean
Returns the status of the current object.
40 41 42 |
# File 'lib/api/api_object.rb', line 40 def is_deleted? @_deleted ||= false end |
#save ⇒ Object
Save this object.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/api/api_object.rb', line 70 def save writer = @writer_object.new(self.to_attributes) result = writer.save_object if result === false @error_messages = writer. else self.set_attributes(result) end result === false ? false : true end |
#set_attributes(attribute_data) ⇒ Object
Sets the current object’s attributes from a hash
62 63 64 |
# File 'lib/api/api_object.rb', line 62 def set_attributes(attribute_data) attribute_data.each { |key, value| self.send("#{key}=", value) if self.respond_to?("#{key}=") } end |
#to_attributes ⇒ Object
Gets the current object’s attributes in a Hash.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/api/api_object.rb', line 47 def to_attributes vals = {} vals = {:marked_for_destruction => self.is_deleted?} if self.is_deleted? self.class.__tc_attributes.each do |tca| rep = self.send(tca) if rep.class == Array rep.collect! { |r| r.respond_to?(:to_attributes) ? r.to_attributes : r } end vals[tca] = rep end vals end |