Sha256: a365c1642b976affe000db13f21f50fabbed3f2b541e9ba1384bbfb71459b0d3

Contents?: true

Size: 492 Bytes

Versions: 3

Compression:

Stored size: 492 Bytes

Contents

module Postly
  # Quick and Dirty has_many proxy class.
  # #create is the only methods currently needed in the API.
  # Otherwise this would be a bit more robust.
  class ManyProxy
  
    def initialize proxied, klass
      @klass    = klass
      @proxied  = proxied
    end
    
    def create attrs={}
      @klass.create( attrs.merge( foreign_key => @proxied.id ) )
    end
  
    def foreign_key
      (@proxied.class.to_s.split("::").last.downcase << '_id').to_sym
    end
  
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
progressions-postly-0.2.2 lib/postly/many_proxy.rb
postly-0.2.2 lib/postly/many_proxy.rb
postly-0.2.1 lib/postly/many_proxy.rb