Sha256: 27b249a6bf355096dfea36ce771f4c9d119f9397e93a01fbd4a3a1d4f782965f

Contents?: true

Size: 619 Bytes

Versions: 40

Compression:

Stored size: 619 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 && _attachments.any?
        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

40 entries across 40 versions & 2 rubygems

Version Path
couch_potato-1.17.0 lib/couch_potato/persistence/attachments.rb
couch_potato-1.16.0 lib/couch_potato/persistence/attachments.rb
couch_potato-1.15.0 lib/couch_potato/persistence/attachments.rb
couch_potato-1.14.0 lib/couch_potato/persistence/attachments.rb
couch_potato-1.13.0 lib/couch_potato/persistence/attachments.rb
couch_potato-1.12.1 lib/couch_potato/persistence/attachments.rb
couch_potato-1.12.0 lib/couch_potato/persistence/attachments.rb
couch_potato-1.11.0 lib/couch_potato/persistence/attachments.rb
couch_potato-1.10.1 lib/couch_potato/persistence/attachments.rb
couch_potato-1.10.0 lib/couch_potato/persistence/attachments.rb
couch_potato-1.9.0 lib/couch_potato/persistence/attachments.rb
couch_potato-1.7.1 lib/couch_potato/persistence/attachments.rb
couch_potato-1.7.0 lib/couch_potato/persistence/attachments.rb
couch_potato-1.6.5 lib/couch_potato/persistence/attachments.rb
couch_potato-1.6.4 lib/couch_potato/persistence/attachments.rb
couch_potato-1.6.3 lib/couch_potato/persistence/attachments.rb
couch_potato-1.4.0 lib/couch_potato/persistence/attachments.rb
couch_potato-1.3.0 lib/couch_potato/persistence/attachments.rb
couch_potato-1.2.0 lib/couch_potato/persistence/attachments.rb
couch_potato-1.1.4 lib/couch_potato/persistence/attachments.rb