controlled_versioning 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd795072f67c6ec02a2c3217abf58ac0b22f790f
4
- data.tar.gz: 778a4f6609c7ad684b166806bfcf8d5f359b957d
3
+ metadata.gz: 8839d624630b52a42a4956e23fd40aba03ea9498
4
+ data.tar.gz: 9e4b13aebd887b5566b15a7cb883fabf114685dc
5
5
  SHA512:
6
- metadata.gz: dd82eb94ea2ebb8fe81c2610ade2c980fabeca3c978aa628e41f304afbc53550ea51149bdedf135a4b267cf945f143f7518bc4f1bc631bb489c0d4837a81108b
7
- data.tar.gz: 72176d86e0287e0058a7c3a425dacd4a4589ad793870d2a4a43fd3d6a4ab84579a1c3e85a70f6bde117def3be6b04ed400939d9483097b466da8ef89b7117f18
6
+ metadata.gz: 5fb843057ee753a5ed1d0520766bd3d85db4f0e562dfa0d7140f55d2c4602f535f93c960425211ef0dfac2925a0f3aa5173c63919e9e864ac7bdfd355b4b223d
7
+ data.tar.gz: 4eb85655b003fc7fa64e716980140997eefcdf99d4a8c2725c7ba105119021c72cbe5eb375a576038ceeb0b9368cb77c59d0e749483f14555a3d9123e4578b55
data/Rakefile CHANGED
@@ -14,8 +14,15 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
+ Bundler::GemHelper.install_tasks
17
18
 
19
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
20
+ load 'rails/tasks/engine.rake'
21
+ require "rspec/core/rake_task"
18
22
 
23
+ task :default => :spec
19
24
 
20
- Bundler::GemHelper.install_tasks
21
-
25
+ RSpec::Core::RakeTask.new(:spec) do |spec|
26
+ spec.pattern = 'spec/**/*_spec.rb'
27
+ # spec.rspec_opts = ['-cfs --backtrace']
28
+ end
@@ -1,9 +1,13 @@
1
1
  # Core
2
+ require "controlled_versioning/version"
3
+
4
+ require "controlled_versioning/initial_version"
5
+ require "controlled_versioning/initial_version/factory"
6
+
2
7
  require "controlled_versioning/revision"
3
- require "controlled_versioning/revision_auditor"
4
- require "controlled_versioning/revision_builder"
5
- require "controlled_versioning/revision_accepter"
6
- require "controlled_versioning/initial_version_builder"
8
+ require "controlled_versioning/revision/auditor"
9
+ require "controlled_versioning/revision/factory"
10
+ require "controlled_versioning/revision/publisher"
7
11
 
8
12
  # Add utility classes
9
13
  require "support/array_converter"
@@ -36,7 +40,7 @@ module ControlledVersioning
36
40
  nested_associations.present?
37
41
  end
38
42
 
39
- attr_accessor :user
43
+ attr_accessor :user, :notes
40
44
 
41
45
  after_create :create_initial_version
42
46
 
@@ -88,12 +92,12 @@ module ControlledVersioning
88
92
  assign_attributes(suggested_attributes)
89
93
  if invalid?
90
94
  errors
91
- elsif !RevisionAuditor.new(self).changes_original?
95
+ elsif !Revision::Auditor.new(self).changes_original?
92
96
  errors[:base] << I18n.t("errors.messages.no_revisions_made")
93
97
  errors
94
98
  else
95
99
  version = versions.build
96
- RevisionBuilder.new(versionable: self, version: version).version
100
+ Revision::Factory.new(versionable: self, version: version).build
97
101
  version.save
98
102
  version
99
103
  end
@@ -101,7 +105,7 @@ module ControlledVersioning
101
105
 
102
106
  private
103
107
  def create_initial_version
104
- InitialVersionBuilder.new(self)
108
+ InitialVersion::Factory.new(self).build
105
109
  end
106
110
  end
107
111
  end
@@ -0,0 +1,11 @@
1
+ class InitialVersion < Version
2
+
3
+ private
4
+ def versionable_nested_within
5
+ versionable.nested_within
6
+ end
7
+
8
+ def versionable_parent
9
+ versionable.public_send(versionable_nested_within)
10
+ end
11
+ end
@@ -1,26 +1,27 @@
1
- class InitialVersionBuilder < Revision
1
+ class InitialVersion::Factory < InitialVersion
2
2
 
3
3
  attr_reader :versionable, :version
4
4
  def initialize(versionable)
5
5
  @versionable = versionable
6
6
  @version = build_version_type
7
- build_initial_version
7
+ end
8
+
9
+ def build
10
+ build_version_attributes
11
+ version.save
8
12
  end
9
13
 
10
14
  private
11
15
  def build_version_type
12
- if is_a_nested_association?
13
- parent.initial_version.version_children.build(versionable: versionable)
16
+ if versionable_is_a_nested_association?
17
+ versionable_parent.initial_version.version_children.
18
+ build(versionable: versionable)
14
19
  else
15
- versionable.versions.build(initial: true)
20
+ versionable.versions.build(initial: true, notes: versionable_notes, user:
21
+ versionable_user)
16
22
  end
17
23
  end
18
24
 
19
- def build_initial_version
20
- build_version_attributes
21
- version.save
22
- end
23
-
24
25
  def build_version_attributes
25
26
  versionable_attributes.each do |attr|
26
27
  attr = AttributeEncapsulator.new(attr)
@@ -34,16 +35,4 @@ class InitialVersionBuilder < Revision
34
35
  new_value: attr.value)
35
36
  end
36
37
 
37
- def is_a_nested_association?
38
- versionable.is_a_nested_association?
39
- end
40
-
41
- def nested_within
42
- versionable.nested_within
43
- end
44
-
45
- def parent
46
- versionable.public_send(nested_within)
47
- end
48
-
49
38
  end
@@ -1,22 +1,10 @@
1
- class Revision
1
+ class Revision < Version
2
2
 
3
3
  private
4
- def versionable_attributes
5
- versionable.versionable_attributes
6
- end
7
-
8
- def changed_attributes
4
+ def versionable_changed_attributes
9
5
  versionable.changed_attributes
10
6
  end
11
7
 
12
- def nested_associations
13
- versionable.class.nested_associations
14
- end
15
-
16
- def version_attributes
17
- version.version_attributes
18
- end
19
-
20
8
  def version_children
21
9
  version.version_children
22
10
  end
@@ -1,4 +1,4 @@
1
- class RevisionAuditor < Revision
1
+ class Revision::Auditor < Revision
2
2
 
3
3
  attr_reader :versionable
4
4
  def initialize(versionable)
@@ -16,13 +16,13 @@ class RevisionAuditor < Revision
16
16
  def changes_at_least_one_attribute?
17
17
  versionable_attributes.each do |attr|
18
18
  attr = AttributeEncapsulator.new(attr)
19
- return true if changed_attributes.include?(attr.key)
19
+ return true if versionable_changed_attributes.include?(attr.key)
20
20
  end
21
21
  return false
22
22
  end
23
23
 
24
24
  def changes_at_least_one_nested_association?
25
- nested_associations.each do |association|
25
+ versionable_nested_associations.each do |association|
26
26
  return true if association_changed?(association)
27
27
  end
28
28
  return false
@@ -37,6 +37,6 @@ class RevisionAuditor < Revision
37
37
 
38
38
  def child_changed?(child)
39
39
  child.new_record? || child.marked_for_destruction? ||
40
- RevisionAuditor.new(child).changes_original?
40
+ Revision::Auditor.new(child).changes_original?
41
41
  end
42
42
  end
@@ -1,27 +1,34 @@
1
- class RevisionBuilder < Revision
1
+ class Revision::Factory < Revision
2
2
 
3
3
  attr_reader :versionable, :version
4
4
  def initialize(args)
5
5
  @versionable = args[:versionable]
6
6
  @version = args[:version]
7
- build_revision
8
7
  end
9
8
 
10
- private
11
- def build_revision
9
+ def build
12
10
  mark_for_removal
11
+ add_notes
13
12
  build_attributes
14
13
  build_children
15
14
  end
16
15
 
16
+ private
17
17
  def mark_for_removal
18
18
  version.marked_for_removal = true if versionable.marked_for_destruction?
19
19
  end
20
20
 
21
+ def add_notes
22
+ unless versionable_is_a_nested_association?
23
+ version.notes = versionable_notes
24
+ version.user = versionable_user
25
+ end
26
+ end
27
+
21
28
  def build_attributes
22
29
  versionable_attributes.each do |attr|
23
30
  attr = AttributeEncapsulator.new(attr)
24
- if changed_attributes.include?(attr.key)
31
+ if versionable_changed_attributes.include?(attr.key)
25
32
  build_attribute(attr)
26
33
  end
27
34
  end
@@ -35,7 +42,7 @@ class RevisionBuilder < Revision
35
42
  end
36
43
 
37
44
  def build_children
38
- nested_associations.each do |association|
45
+ versionable_nested_associations.each do |association|
39
46
  versionable.public_send(association).each do |child|
40
47
  build_child(child)
41
48
  end
@@ -43,9 +50,9 @@ class RevisionBuilder < Revision
43
50
  end
44
51
 
45
52
  def build_child(child)
46
- if RevisionAuditor.new(child).changes_original?
53
+ if Revision::Auditor.new(child).changes_original?
47
54
  version_child = build_version_child(child)
48
- RevisionBuilder.new(versionable: child, version: version_child)
55
+ Revision::Factory.new(versionable: child, version: version_child).build
49
56
  end
50
57
  end
51
58
 
@@ -1,18 +1,17 @@
1
- class RevisionAccepter < Revision
1
+ class Revision::Publisher < Revision
2
2
 
3
3
  attr_reader :version, :versionable
4
4
  def initialize(version)
5
5
  @version = version
6
6
  @versionable = version.versionable
7
- accept_revision
8
7
  end
9
8
 
10
- private
11
9
  def accept_revision
12
10
  create_or_update_versionable
13
11
  update_version_children
14
12
  end
15
13
 
14
+ private
16
15
  def create_or_update_versionable
17
16
  versionable.present? ? update_versionable : create_versionable
18
17
  end
@@ -40,7 +39,7 @@ class RevisionAccepter < Revision
40
39
  if child.marked_for_removal?
41
40
  destroy_child(child)
42
41
  else
43
- RevisionAccepter.new(child)
42
+ Revision::Publisher.new(child).accept_revision
44
43
  end
45
44
  end
46
45
 
@@ -1,3 +1,27 @@
1
- module ControlledVersioning
2
- VERSION = "0.6.1"
3
- end
1
+ class Version
2
+
3
+ private
4
+ def versionable_attributes
5
+ versionable.versionable_attributes
6
+ end
7
+
8
+ def version_attributes
9
+ version.version_attributes
10
+ end
11
+
12
+ def versionable_is_a_nested_association?
13
+ versionable.is_a_nested_association?
14
+ end
15
+
16
+ def versionable_nested_associations
17
+ versionable.class.nested_associations
18
+ end
19
+
20
+ def versionable_notes
21
+ versionable.notes
22
+ end
23
+
24
+ def versionable_user
25
+ versionable.user
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module ControlledVersioning
2
+ VERSION_NUMBER = "0.6.2"
3
+ end
@@ -12,18 +12,24 @@ class CreateVersions < ActiveRecord::Migration
12
12
 
13
13
  t.boolean :marked_for_removal, null: false, default: false
14
14
 
15
- t.boolean :approved, null: false, default: false
15
+ t.boolean :accepted, null: false, default: false
16
16
  t.boolean :declined, null: false, default: false
17
17
  t.boolean :pending, null: false, default: true
18
18
 
19
19
  t.datetime :created_at
20
20
  end
21
21
  add_index :versions, :initial
22
+ add_index :versions, :accepted
23
+ add_index :versions, :declined
24
+ add_index :versions, :pending
22
25
  add_index :versions, [:versionable_type, :versionable_id]
23
26
  end
24
27
 
25
28
  def self.down
26
29
  remove_index :versions, :initial
30
+ remove_index :versions, :accepted
31
+ remove_index :versions, :declined
32
+ remove_index :versions, :pending
27
33
  remove_index :versions, [:verstionable_type, :versionable_id]
28
34
  drop_table :versions
29
35
  end
@@ -8,8 +8,8 @@ class ControlledVersioning::Version < ActiveRecord::Base
8
8
  validates :versionable, presence: true
9
9
 
10
10
  def accept
11
- RevisionAccepter.new(self)
12
- update_attributes(pending: false, approved: true)
11
+ Revision::Publisher.new(self).accept_revision unless initial?
12
+ update_attributes(pending: false, accepted: true)
13
13
  end
14
14
 
15
15
  def decline
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: controlled_versioning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - timothythehuman
@@ -128,11 +128,13 @@ files:
128
128
  - lib/generators/templates/version.rb
129
129
  - lib/generators/templates/create_version_attributes.rb
130
130
  - lib/generators/controlled_versioning/install_generator.rb
131
- - lib/controlled_versioning/revision_accepter.rb
132
- - lib/controlled_versioning/revision_builder.rb
131
+ - lib/controlled_versioning/initial_version.rb
132
+ - lib/controlled_versioning/version_number.rb
133
+ - lib/controlled_versioning/initial_version/factory.rb
133
134
  - lib/controlled_versioning/revision.rb
134
- - lib/controlled_versioning/revision_auditor.rb
135
- - lib/controlled_versioning/initial_version_builder.rb
135
+ - lib/controlled_versioning/revision/factory.rb
136
+ - lib/controlled_versioning/revision/auditor.rb
137
+ - lib/controlled_versioning/revision/publisher.rb
136
138
  - lib/controlled_versioning/version.rb
137
139
  - lib/controlled_versioning.rb
138
140
  - MIT-LICENSE