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.1.2 lib/couch_potato/persistence/attachments.rb
couch_potato-1.1.1 lib/couch_potato/persistence/attachments.rb
couch_potato-1.1.0 lib/couch_potato/persistence/attachments.rb
couch_potato-1.0.1 lib/couch_potato/persistence/attachments.rb
couch_potato-1.0.0 lib/couch_potato/persistence/attachments.rb
couch_potato-0.7.1 lib/couch_potato/persistence/attachments.rb
couch_potato-0.7.0 lib/couch_potato/persistence/attachments.rb
couch_potato-0.7.0.pre.1 lib/couch_potato/persistence/attachments.rb
couch_potato-0.6.0 lib/couch_potato/persistence/attachments.rb
couch_potato-0.5.7 lib/couch_potato/persistence/attachments.rb
couch_potato-rails2-0.5.10 lib/couch_potato/persistence/attachments.rb
couch_potato-rails2-0.5.9 lib/couch_potato/persistence/attachments.rb
couch_potato-rails2-0.5.8 lib/couch_potato/persistence/attachments.rb
couch_potato-rails2-0.5.7 lib/couch_potato/persistence/attachments.rb
couch_potato-rails2-0.5.6 lib/couch_potato/persistence/attachments.rb
couch_potato-0.5.6 lib/couch_potato/persistence/attachments.rb
couch_potato-0.5.5 lib/couch_potato/persistence/attachments.rb
couch_potato-0.5.4 lib/couch_potato/persistence/attachments.rb
couch_potato-0.5.3 lib/couch_potato/persistence/attachments.rb
couch_potato-0.5.2 lib/couch_potato/persistence/attachments.rb