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
17
18
19
20
21
# File 'lib/controlled_versioning/revision/factory.rb', line 11

def build
  versionable.assign_attributes(suggested_attributes)
  if versionable.invalid?
    versionable.errors
  elsif !Revision::Auditor.new(versionable).changes_original?
    versionable.errors[:base] << I18n.t("errors.messages.no_revisions_made")
    versionable.errors
  else
    build_parent
  end
end

#build_associationsObject



23
24
25
26
27
# File 'lib/controlled_versioning/revision/factory.rb', line 23

def build_associations
  mark_for_removal
  build_attributes
  build_children
end