Class: Blastramp::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/blastramp/entity.rb

Direct Known Subclasses

Address, Order, OrderItem

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values = {}) ⇒ Entity

Returns a new instance of Entity.



27
28
29
30
# File 'lib/blastramp/entity.rb', line 27

def initialize(values = {})
  initialize_defaults
  update_properties(values)
end

Instance Attribute Details

#sessionObject

Internal accessors



4
5
6
# File 'lib/blastramp/entity.rb', line 4

def session
  @session
end

Class Method Details

.has_properties(*properties) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/blastramp/entity.rb', line 7

def has_properties(*properties)
  @properties = properties
  properties.each do |property|
    unless instance_methods.collect(&:to_s).include?(property.to_s)
      # Create property accessors that loads the full Entity from the API if necessary
      define_method "#{property}" do
        instance_variable_get("@#{property}")
      end
    end

    # Just use regular writers
    attr_writer property
  end
end

.propertiesObject



22
23
24
# File 'lib/blastramp/entity.rb', line 22

def properties
  @properties || []
end

Instance Method Details

#initialize_defaultsObject



32
33
34
# File 'lib/blastramp/entity.rb', line 32

def initialize_defaults
  nil
end

#inspectObject



36
37
38
39
# File 'lib/blastramp/entity.rb', line 36

def inspect
  props = self.class.properties.collect { |p| "#{p}=#{self.send(p).inspect}" }
  "#<#{self.class}:#{self.object_id}, #{props.join(', ')}>"
end

#soap_dataObject

Returns OrderedHash with the data structure to send to the API



49
50
# File 'lib/blastramp/entity.rb', line 49

def soap_data
end

#update_properties(hash) ⇒ Object

Updates properties of Entity with the values from hash



42
43
44
45
46
# File 'lib/blastramp/entity.rb', line 42

def update_properties(hash)
  hash.each do |key, value|
    self.send("#{key}=", value)
  end
end