Skip to content

Commit

Permalink
Get saving working
Browse files Browse the repository at this point in the history
  • Loading branch information
scotchi committed Oct 10, 2012
1 parent 2f53f27 commit 29b0632
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
13 changes: 9 additions & 4 deletions Ruby/lib/directededge/containerproxy.rb
Expand Up @@ -30,11 +30,9 @@ class ContainerProxy
SUPPORTED_TYPES = [ Array, Hash, Set ]

def initialize(klass, &loader)
@cached = false
@cached_data = klass.new
@add_queue = klass.new
@remove_queue = klass.new
@klass = klass
@loader = loader
clear
end

def add(value)
Expand Down Expand Up @@ -96,6 +94,13 @@ def set(values)
values
end

def clear
@cached = false
@cached_data = @klass.new
@add_queue = @klass.new
@remove_queue = @klass.new
end

def cached?
@cached
end
Expand Down
7 changes: 4 additions & 3 deletions Ruby/lib/directededge/item.rb
Expand Up @@ -39,9 +39,10 @@ def load
end

def save
xml(:cached_data) if cached?
xml(:add_queue) if queued?(:add)
xml(:remove_queue) if queued?(:remove)
resource.put(xml(:cached_data)) if cached?
resource[:update_method => :add].post(xml(:add_queue)) if queued?(:add)
resource[:update_method => :subtract].post(xml(:remove_queue)) if queued?(:remove)
@data.values.each(&:clear)
end

private
Expand Down
15 changes: 15 additions & 0 deletions Ruby/lib/directededge/resource.rb
Expand Up @@ -35,5 +35,20 @@ def [](*args)
end
super('?' + params.join('&'))
end

def get(additional_headers = {}, &block)
additional_headers[:content_type] ||= 'text/xml'
super(additional_headers, &block)
end

def put(payload, additional_headers = {}, &block)
additional_headers[:content_type] ||= 'text/xml'
super(payload, additional_headers, &block)
end

def post(payload, additional_headers = {}, &block)
additional_headers[:content_type] ||= 'text/xml'
super(payload, additional_headers, &block)
end
end
end

0 comments on commit 29b0632

Please sign in to comment.