Module: ActiveApi::InstanceMethods

Included in:
ApiObject
Defined in:
lib/api_object.rb

Instance Method Summary collapse

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/api_object.rb', line 117

def empty?
    (self.instance_variables - [:@errors]).empty?
end

#has_errors?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/api_object.rb', line 121

def has_errors?
  self.instance_variables.include?(:@errors)
end

#initialize(*args) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/api_object.rb', line 98

def initialize(*args)
    url = args.first.delete(:url)
    errors = args.first.delete(:errors)
    tags = respond_to?('data_tags') ? self.data_tags : args.last[:tags]
    args.first.each do |k, v| 
       k = k.gsub(/@/, '')
       k = self.columns[k.to_sym] unless self.columns[k.to_sym].nil?
       if self.respond_to?(k)   # check if it's included as a class attribute
          klass = self.assoc[k.to_sym] || k
          result = v.instance_of?(Array) ? v.map {|v1| init_object(v1, klass, tags)} : init_object(v, klass, tags)
          instance_variable_set("@#{k.to_s}", result)
       end
    end if args.first.is_a?(Hash)
    if self.empty?
      puts "ERROR: data passed for #{self.class} initialization was invalid. #{self.class.error_invalid_url url}" 
      @errors = errors || self.class.invalid_data_msg
    end
end

#persisted?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/api_object.rb', line 126

def persisted?
    false
end