Sha256: fef7814234ccb8c1248d6456287ab84f029ebf99a911c445fcf810b0abceba02

Contents?: true

Size: 598 Bytes

Versions: 20

Compression:

Stored size: 598 Bytes

Contents

module CouchPotato
  module Attachments
    def self.included(base) #:nodoc:
      base.class_eval do
        attr_writer :_attachments
        
        def _attachments
          @_attachments ||= {}
        end
        
        base.extend ClassMethods
      end
    end
    
    def to_hash
      if _attachments
        super.merge('_attachments' => _attachments)
      else
        super
      end
    end
    
    module ClassMethods
      def json_create(json)
        instance = super
        instance._attachments = json['_attachments'] if json
        instance
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
couch_potato-0.5.1 lib/couch_potato/persistence/attachments.rb
couch_potato-0.5.0 lib/couch_potato/persistence/attachments.rb
davber_couch_potato-0.4.0 lib/couch_potato/persistence/attachments.rb
couch_potato-0.4.0 lib/couch_potato/persistence/attachments.rb
couch_potato-0.3.2 lib/couch_potato/persistence/attachments.rb
couch_potato-0.3.1 lib/couch_potato/persistence/attachments.rb
davber_couch_potato-0.3.0 lib/couch_potato/persistence/attachments.rb
couch_potato-0.3.0 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.32 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.31 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.30 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.29 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.28 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.27 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.26 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.25 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.24 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.23 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.22 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.21 lib/couch_potato/persistence/attachments.rb