Sha256: 05424b4e6da5f7738df092ce80ab8545fd6f77b7f5defb7ddf7e31016cdaf0b7

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

module EmbeddedAssociation
  include AbstractModel
  
  def fields_field
    @fields_field ||= FieldsField.new(name)
  end
  
  def fields
    @fields ||= fields_field.typecast(@options['fields'], nil)
  end
  
  def options
    @options.merge({'fields' => fields_field.untypecast(fields, nil)})
  end
  
  def validate(record, errors)
    EmbeddedRecordsValidation.validate(self, record.get(name), record, errors)
    super(record, errors)
  end
  
  def default_input_type
    :embedded
  end
  
  private
    def process_json_item(embedded_record, store, record)
      return unless embedded_record.respond_to?(:to_hash)
      EmbeddedRecord.new(self, record, {}).tap {|new_record| new_record.from_json(embedded_record)}
    end
    
    def clear(store, record)
      if store.is_a?(Array)
        store.clear
      else
        record.set_raw(name, {})
        return {}
      end
    end
  
    def all(store, record)
      return [] if store.blank?
      store = [store] unless store.respond_to?(:collect)
      store.collect do |values|
        EmbeddedRecord.new(self, record, values, false)
      end
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yodel-0.0.7 lib/yodel/models/core/associations/embedded/embedded_association.rb
yodel-0.0.4 lib/yodel/models/core/associations/embedded/embedded_association.rb
yodel-0.0.3 lib/yodel/models/core/associations/embedded/embedded_association.rb
yodel-0.0.2 lib/yodel/models/core/associations/embedded/embedded_association.rb
yodel-0.0.1 lib/yodel/models/core/associations/embedded/embedded_association.rb