Sha256: 59cae89add67c25214ed29ed5867d5c43ce3bd04e018edee7ec409a234eb6c3d

Contents?: true

Size: 840 Bytes

Versions: 3

Compression:

Stored size: 840 Bytes

Contents

class InitialVersion::Factory < InitialVersion

  attr_reader :versionable, :version
  def initialize(versionable)
    @versionable = versionable
    @version = build_version_type
  end

  def build
    build_version_attributes
    version.save
  end

  private
  def build_version_type
    if versionable_is_a_nested_association?
      versionable_parent.initial_version.version_children.
        build(versionable: versionable)
    else
      versionable.versions.build(initial: true, notes: versionable_notes, user:
        versionable_user)
    end
  end

  def build_version_attributes
    versionable_attributes.each do |attr|
      attr = AttributeEncapsulator.new(attr)
      build_attribute(attr)
    end
  end

  def build_attribute(attr)
    version_attributes.build(
      name: attr.key,
      new_value: attr.value)
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
controlled_versioning-0.7.2 lib/controlled_versioning/initial_version/factory.rb
controlled_versioning-0.6.3 lib/controlled_versioning/initial_version/factory.rb
controlled_versioning-0.6.2 lib/controlled_versioning/initial_version/factory.rb