Module: Ripple::Serialization
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Serializers::JSON
- Defined in:
- lib/ripple/serialization.rb
Overview
Provides methods for serializing Ripple documents to external formats (e.g. JSON). By default, embedded documents will be included in the resulting format.
Instance Method Summary collapse
-
#serializable_hash(options = nil) ⇒ Hash
Creates a Hash suitable for conversion to an external format.
Instance Method Details
#serializable_hash(options = nil) ⇒ Hash
Creates a Hash suitable for conversion to an external format.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ripple/serialization.rb', line 35 def serializable_hash(=nil) = .try(:clone) || {} unless .has_key?(:include) [:include] = self.class..map(&:name) end hash = super() hash['key'] = key if respond_to?(:key) && key.present? && (![:except] || ![:except].map(&:to_s).include?("key")) serializable_add_includes() do |association, records, opts| hash[association.to_s] = records.is_a?(Enumerable) ? records.map {|r| r.serializable_hash(opts) } : records.serializable_hash(opts) end hash end |