class PivotalTracker::Proxy

Public Class Methods

new(owner, target) click to toggle source
# File lib/pivotal-tracker/proxy.rb, line 8
def initialize(owner, target)
  @owner = owner
  @target = target
  @opts = {}
end

Public Instance Methods

<<(*objects) click to toggle source
# File lib/pivotal-tracker/proxy.rb, line 24
def <<(*objects)
  objects.flatten.each do |object|
    if obj = object.create
      return obj
    else
      return object
    end
  end
end
all(options={}) click to toggle source
# File lib/pivotal-tracker/proxy.rb, line 14
def all(options={})
  proxy_found(options)
end
create(args = {}) click to toggle source
# File lib/pivotal-tracker/proxy.rb, line 34
def create(args = {})
  object = @target.new(args.merge({:owner => @owner}))
  if obj = object.create
    return obj
  else
    return object
  end
end
find(param, options={}) click to toggle source
# File lib/pivotal-tracker/proxy.rb, line 18
def find(param, options={})
  return all(options) if param == :all
  return @target.find(param, @owner.id) if @target.respond_to?("find")
  return proxy_found(options).detect { |document| document.id == param }
end

Protected Instance Methods

proxy_found(options) click to toggle source
# File lib/pivotal-tracker/proxy.rb, line 45
def proxy_found(options)
  if @found.nil? or @opts != options
    @opts = options
    @found = load_found()
  end
  @found
end

Private Instance Methods

load_found() click to toggle source
# File lib/pivotal-tracker/proxy.rb, line 59
def load_found()
  @target.all(@owner, @opts)
end
method_missing(method, *args, &block) click to toggle source
# File lib/pivotal-tracker/proxy.rb, line 55
def method_missing(method, *args, &block)
  @target.send(method, *args, &block)
end