Class: Revision::Factory

Inherits:
Revision show all
Defined in:
lib/controlled_versioning/revision/factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Factory

Returns a new instance of Factory.



5
6
7
8
9
# File 'lib/controlled_versioning/revision/factory.rb', line 5

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

Instance Attribute Details

#suggested_attributesObject (readonly)

Returns the value of attribute suggested_attributes.



3
4
5
# File 'lib/controlled_versioning/revision/factory.rb', line 3

def suggested_attributes
  @suggested_attributes
end

#versionObject

Returns the value of attribute version.



4
5
6
# File 'lib/controlled_versioning/revision/factory.rb', line 4

def version
  @version
end

#versionableObject (readonly)

Returns the value of attribute versionable.



3
4
5
# File 'lib/controlled_versioning/revision/factory.rb', line 3

def versionable
  @versionable
end

Instance Method Details

#buildObject



11
12
13
14
15
16
# File 'lib/controlled_versioning/revision/factory.rb', line 11

def build
  versionable.assign_attributes(suggested_attributes)
  versionable.valid?
  validate_presence_of_changes
  versionable.errors.present? ? versionable : build_parent
end

#build_associationsObject



18
19
20
21
22
# File 'lib/controlled_versioning/revision/factory.rb', line 18

def build_associations
  mark_for_removal
  build_attributes
  build_children
end