Sha256: 40540b133f3bd7825e130fbeac69b2ce79c2974420c3cf98e372e68364d4a738

Contents?: true

Size: 1.05 KB

Versions: 9

Compression:

Stored size: 1.05 KB

Contents

class InitialVersion::Factory < InitialVersion

  attr_reader :versionable, :version
  def initialize(args)
    @versionable = args[:versionable]
    @version = args[:version]
  end

  def build
    build_version_attributes
    build_children
    version
  end

  private
  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

  def build_children
    versionable_nested_associations.each do |association|
      versionable.public_send(association).each do |child|
        build_child(child, association)
      end
    end
  end

  def build_child(child, association)
    version_child = build_version_child(child, association)
    InitialVersion::Factory.new(versionable: child,
      version: version_child).build
  end

  def build_version_child(child, association)
    version_children.build(association_name: association, versionable: child)
  end

end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
rubber_stamp-0.15.1 lib/rubber_stamp/initial_version/factory.rb
rubber_stamp-0.13.0 lib/rubber_stamp/initial_version/factory.rb
controlled_versioning-0.12.0 lib/controlled_versioning/initial_version/factory.rb
controlled_versioning-0.11.0 lib/controlled_versioning/initial_version/factory.rb
controlled_versioning-0.10.0 lib/controlled_versioning/initial_version/factory.rb
controlled_versioning-0.9.2 lib/controlled_versioning/initial_version/factory.rb
controlled_versioning-0.9.1 lib/controlled_versioning/initial_version/factory.rb
controlled_versioning-0.9.0 lib/controlled_versioning/initial_version/factory.rb
controlled_versioning-0.8.0 lib/controlled_versioning/initial_version/factory.rb