Sha256: d90cc237c72e56967f24cd8ca1b72a2c7039ec4b01d9442c12509103f71211db

Contents?: true

Size: 953 Bytes

Versions: 4

Compression:

Stored size: 953 Bytes

Contents

require './record/abstract_record'

class EmbeddedRecord < AbstractRecord
  attr_reader :embedded_field, :parent_record
  
  def initialize(embedded_field, parent_record, values={}, new_record=true)
    @embedded_field = embedded_field
    @parent_record = parent_record
    super(values, new_record)
  end
  
  def site
    parent_record.site
  end
  
  def set(name, value)
    super
    parent_record.changed!(embedded_field.name)
  end
  
  def set_raw(name, value)
    super
    parent_record.changed!(embedded_field.name)
  end
      
  def changed!(name)
    super
    parent_record.changed!(embedded_field.name)
  end
  
  def fields
    embedded_field.fields
  end
  
  def perform_save
    embedded_field.save(self, parent_record)
  end

  def perform_destroy
    embedded_field.destroy(self, parent_record)
  end
  
  def perform_reload(id)
    # TODO: determine whether reloading the parent record will cause any problems
    self
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yodel-0.0.4 lib/yodel/models/core/record/embedded_record.rb
yodel-0.0.3 lib/yodel/models/core/record/embedded_record.rb
yodel-0.0.2 lib/yodel/models/core/record/embedded_record.rb
yodel-0.0.1 lib/yodel/models/core/record/embedded_record.rb