Sha256: 6ccec6540ae15d1f1d7e2989f219a831485806b79ebce1bed663c4c74dcd00e7

Contents?: true

Size: 589 Bytes

Versions: 6

Compression:

Stored size: 589 Bytes

Contents

module CouchPotato
  module Attachments
    def self.included(base)
      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

6 entries across 6 versions & 1 rubygems

Version Path
couch_potato-0.2.20 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.19 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.18 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.17 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.16 lib/couch_potato/persistence/attachments.rb
couch_potato-0.2.15 lib/couch_potato/persistence/attachments.rb