Class: ChurchCommunityBuilder::ApiObject

Inherits:
Object
  • Object
show all
Defined in:
lib/api/api_object.rb

Overview

This class is the base class for all ChurchCommunityBuilder objects and is meant to be inherited.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#error_messagesObject (readonly)

Returns the value of attribute error_messages.



6
7
8
# File 'lib/api/api_object.rb', line 6

def error_messages
  @error_messages
end

#marked_for_destructionObject (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

.__ccb_attributesObject

A list of ccb_attr_accessors that have been specified.



18
19
20
# File 'lib/api/api_object.rb', line 18

def self.__ccb_attributes
  @__ccb_attributes
end

.ccb_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.ccb_attr_accessor(*vars)
  @__ccb_attributes ||= []
  @__ccb_attributes.concat(vars)
  attr_accessor(*vars)
end

Instance Method Details

#initialize_from_json_object(object_attributes) ⇒ Object

Initializes the current object from the JSON data that was loaded into the Hash

Parameters:

  • object_attributes

    A Hash of values to load into the current object.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/api/api_object.rb', line 25

def initialize_from_json_object(object_attributes)
  # puts "CALLER"
  # puts caller[0]
  # puts "DONE PUTTING CALLER"
  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)
        # puts "Sending :=> ".green + method_to_call.to_s + value.to_s
        self.send(method_to_call, value) 
      else
        # puts "Missing :=> ".red + method_to_call.to_s  # Show the missing methods
      end
    end
  end     
end

#is_deleted?Boolean

Returns the status of the current object.

Returns:

  • (Boolean)


46
47
48
# File 'lib/api/api_object.rb', line 46

def is_deleted?
  @_deleted ||= false
end

#set_attributes(attribute_data) ⇒ Object

Sets the current object’s attributes from a hash



68
69
70
# File 'lib/api/api_object.rb', line 68

def set_attributes(attribute_data)
  attribute_data.each { |key, value| self.send("#{key}=", value) if self.respond_to?("#{key}=") }
end

#to_attributesObject

Gets the current object’s attributes in a Hash.

Returns:

  • A hash of all the attributes.



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/api/api_object.rb', line 53

def to_attributes 
  vals = {}
  vals = {:marked_for_destruction => self.is_deleted?} if self.is_deleted?
  self.class.__ccb_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