Module: SalesforceRecord::Attributes

Defined in:
lib/salesforce_record/attributes.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/salesforce_record/attributes.rb', line 10

def self.included(base)
  base.send(:extend, ClassMethods)

  base.instance_eval do
    # Store the attributes and aliases at the class level
    @salesforce_fields = {} # name  => field instance

    # The base attributes
    sf_attribute :Id, :type => :id
  end
end

Instance Method Details

#attributesObject

The attributes hash : name => parsed value



145
146
147
# File 'lib/salesforce_record/attributes.rb', line 145

def attributes
  Hash[*self.class.salesforce_attributes.map{|attr|[attr, self.send(attr)]}.flatten]
end

#initialize(attributes = {}) ⇒ Object

Constructor



136
137
138
139
140
141
# File 'lib/salesforce_record/attributes.rb', line 136

def initialize(attributes = {})
  # Iterate over the salesforce attributes and sets them
  attributes.each do |name, value|
    instance_variable_set :"@#{name}", value
  end
end