Class: Economic::EntityProxy

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/economic/proxies/entity_proxy.rb

Direct Known Subclasses

CurrentInvoiceLineProxy, CurrentInvoiceProxy, DebtorContactProxy, DebtorProxy

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (EntityProxy) initialize(owner)

Returns a new instance of EntityProxy



16
17
18
19
# File 'lib/economic/proxies/entity_proxy.rb', line 16

def initialize(owner)
  @owner = owner
  @items = []
end

Instance Attribute Details

- (Object) items (readonly)

Returns the value of attribute items



14
15
16
# File 'lib/economic/proxies/entity_proxy.rb', line 14

def items
  @items
end

- (Object) owner (readonly)

Returns the value of attribute owner



14
15
16
# File 'lib/economic/proxies/entity_proxy.rb', line 14

def owner
  @owner
end

Class Method Details

+ (Object) entity_class

Returns the class this Proxy is a proxy for



5
6
7
8
9
# File 'lib/economic/proxies/entity_proxy.rb', line 5

def entity_class
  proxy_class_name = name.split('::').last
  entity_class_name = proxy_class_name.sub(/Proxy$/, '')
  Economic.const_get(entity_class_name)
end

Instance Method Details

- (Object) <<(item)

Add item to proxy



61
62
63
# File 'lib/economic/proxies/entity_proxy.rb', line 61

def <<(item)
  items << item
end

- (Object) build(properties = {})

Returns a new, unpersisted Economic::Entity



26
27
28
29
30
31
32
33
# File 'lib/economic/proxies/entity_proxy.rb', line 26

def build(properties = {})
  entity = self.class.entity_class.new(:session => session)

  entity.update_properties(properties)
  entity.partial = false

  entity
end

- (Object) each



65
66
67
# File 'lib/economic/proxies/entity_proxy.rb', line 65

def each
  items.each { |i| yield i }
end

- (Boolean) empty?

Returns:

  • (Boolean)


69
70
71
# File 'lib/economic/proxies/entity_proxy.rb', line 69

def empty?
  items.empty?
end

- (Object) entity_class

Returns the class this proxy manages



36
37
38
# File 'lib/economic/proxies/entity_proxy.rb', line 36

def entity_class
  self.class.entity_class
end

- (Object) find(handle)

Fetches Entity data from API and returns an Entity initialized with that data



41
42
43
44
45
46
47
# File 'lib/economic/proxies/entity_proxy.rb', line 41

def find(handle)
  handle = Entity::Handle.new(:number => handle) unless handle.is_a?(Entity::Handle)
  entity_hash = get_data(handle)
  entity = build(entity_hash)
  entity.persisted = true
  entity
end

- (Object) get_data(handle)

Gets data for Entity from the API. Returns Hash with the response data



50
51
52
53
54
55
56
57
58
# File 'lib/economic/proxies/entity_proxy.rb', line 50

def get_data(handle)
  handle = Entity::Handle.new(:number => handle) unless handle.is_a?(Entity::Handle)
  entity_hash = session.request(entity_class.soap_action(:get_data)) do
    soap.body = {
      'entityHandle' => handle.to_hash
    }
  end
  entity_hash
end

- (Object) session



21
22
23
# File 'lib/economic/proxies/entity_proxy.rb', line 21

def session
  owner.session
end