Sha256: d37fb3eb44835c8411fdcd4fe2d9f3f8b115194af3c40379fc4bb0be863391fa

Contents?: true

Size: 618 Bytes

Versions: 2

Compression:

Stored size: 618 Bytes

Contents

module ActiveData
  module Model
    module Associations
      class EmbedsOne < Association

        def collection?
          false
        end

        def define_reader target
          target.class_eval <<-EOS
            def #{name}
              @#{name}
            end
          EOS
        end

        def define_writer target
          target.class_eval <<-EOS
            def #{name}= value
              association = self.class.reflect_on_association('#{name}')
              @#{name} = association.klass.instantiate(value) if value
            end
          EOS
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_data-0.3.0 lib/active_data/model/associations/embeds_one.rb
active_data-0.2.0 lib/active_data/model/associations/embeds_one.rb