replication 0.3.2 → 0.4.0
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 +4 -4
- data/Gemfile +1 -1
- data/README.md +2 -0
- data/db/migrate/714417722_replication_migration.rb +1 -1
- data/lib/replication/active_record/polymorphic_strand.rb +7 -0
- data/lib/replication/active_record/strand.rb +1 -1
- data/lib/replication/modules/association.rb +1 -1
- data/lib/replication/modules/polymorphic.rb +12 -0
- data/lib/replication/modules/semi_conservative.rb +4 -2
- data/lib/replication/process.rb +30 -27
- data/lib/replication/version.rb +1 -1
- data/lib/replication.rb +20 -2
- data/test/orm/active_record.rb +0 -5
- data/test/rails_app/app/models/animal.rb +2 -0
- data/test/rails_app/config/environments/test.rb +4 -1
- data/test/rails_app/db/migrate/830335961_organism_migration.rb +1 -1
- data/test/replication/modules/semi_conservative_test.rb +0 -1
- data/test/replication/process_test.rb +9 -1
- data/test/test_helper.rb +2 -2
- metadata +14 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 279a019bb4a36a642ec8ff94bf06df30534116b8
|
4
|
+
data.tar.gz: 185300af2787edbd13d48d7f6b34cc9ada06a47c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53c8cd4c11f0ce238c6d42bed9a1c89315001e9adcfa9d5ecda71cda5b12a277ba4eb3b558719073ed70cc841b45f1808769df2b48785c87a88686aaa7073959
|
7
|
+
data.tar.gz: dbfbc2ae4cfdf7de60b97cbf1cbe84e5fcecbb4d1280433636a95f966de4f327b59a7cac6ca943b399ebe2119107a4e0c133caaedc79c2423365551542a73fff
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,8 @@ module Replication
|
|
9
9
|
strand_class.new({
|
10
10
|
name: options[:name],
|
11
11
|
pairs: strand_attributes,
|
12
|
-
|
12
|
+
origin_id: self.id,
|
13
|
+
origin_type: self.class.to_s
|
13
14
|
})
|
14
15
|
end
|
15
16
|
|
@@ -17,7 +18,8 @@ module Replication
|
|
17
18
|
strand_class.to_adapter.create!({
|
18
19
|
name: options[:name],
|
19
20
|
pairs: strand_attributes,
|
20
|
-
|
21
|
+
origin_id: self.id,
|
22
|
+
origin_type: self.class.to_s
|
21
23
|
})
|
22
24
|
end
|
23
25
|
|
data/lib/replication/process.rb
CHANGED
@@ -1,26 +1,20 @@
|
|
1
1
|
module Replication
|
2
2
|
module Process
|
3
3
|
|
4
|
-
def
|
5
|
-
|
6
|
-
include Model
|
7
|
-
end
|
8
|
-
end
|
4
|
+
def can_replicate(pairs_method = :attributes, **options)
|
5
|
+
reset_config if self.respond_to?(:unwound)
|
9
6
|
|
10
|
-
|
11
|
-
def self.included(model_class)
|
12
|
-
model_class.extend self
|
13
|
-
end
|
7
|
+
puts replication_config.inspect
|
14
8
|
|
15
|
-
def can_replicate(pairs_method = :attributes, **options)
|
16
|
-
@@replication_config = Class.new(Config).new(self)
|
17
9
|
default_options = Replication.defaults
|
18
10
|
modules = [:semi_conservative] # required module
|
19
11
|
modules.concat([].push(options.delete(:with)).flatten).compact!
|
20
12
|
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
replication_config.pairs_method = pairs_method
|
14
|
+
replication_config.set default_options.merge(options)
|
15
|
+
replication_config.with modules
|
16
|
+
|
17
|
+
include Model
|
24
18
|
end
|
25
19
|
|
26
20
|
def new_from_strand(id=nil, **options)
|
@@ -33,25 +27,34 @@ module Replication
|
|
33
27
|
new(strand.pairs) if strand
|
34
28
|
end
|
35
29
|
|
36
|
-
def
|
37
|
-
|
30
|
+
def reset_config
|
31
|
+
@replication_config = nil
|
38
32
|
end
|
39
33
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
replication_config.strand_class
|
34
|
+
def replication_config
|
35
|
+
@replication_config ||= base_class.replication_config.dup.tap do |config|
|
36
|
+
config.model_class = self
|
44
37
|
end
|
38
|
+
end
|
39
|
+
end
|
45
40
|
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
module Model
|
42
|
+
def self.included(model_class)
|
43
|
+
return if model_class.respond_to?(:can_replicate)
|
44
|
+
end
|
49
45
|
|
50
|
-
|
46
|
+
def strand_class
|
47
|
+
replication_config.strand_class
|
48
|
+
end
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
end
|
50
|
+
def replication_config
|
51
|
+
self.class.replication_config
|
55
52
|
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def _strand_attributes
|
57
|
+
send(replication_config.pairs_method).deep_symbolize_keys
|
58
|
+
end
|
56
59
|
end
|
57
60
|
end
|
data/lib/replication/version.rb
CHANGED
data/lib/replication.rb
CHANGED
@@ -8,6 +8,7 @@ module Replication
|
|
8
8
|
|
9
9
|
module ActiveRecord
|
10
10
|
autoload :Strand, 'replication/active_record/strand'
|
11
|
+
autoload :PolymorphicStrand, 'replication/active_record/polymorphic_strand'
|
11
12
|
end
|
12
13
|
|
13
14
|
module Modules
|
@@ -15,17 +16,34 @@ module Replication
|
|
15
16
|
autoload :Proofreading, 'replication/modules/proofreading'
|
16
17
|
|
17
18
|
autoload :Association, 'replication/modules/association'
|
19
|
+
autoload :Polymorphic, 'replication/modules/polymorphic'
|
18
20
|
end
|
19
21
|
|
20
22
|
def self.defaults
|
21
23
|
defaults = {
|
22
|
-
only: [],
|
24
|
+
only: [],
|
23
25
|
except: []
|
24
26
|
}
|
25
27
|
defaults.merge!({
|
26
|
-
strand_class: ::Replication::ActiveRecord::
|
28
|
+
strand_class: ::Replication::ActiveRecord::PolymorphicStrand,
|
27
29
|
except: [:id, :created_at, :updated_at]
|
28
30
|
}) if defined?(ActiveRecord)
|
31
|
+
|
32
|
+
defaults
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.extended(model_class)
|
36
|
+
return if model_class.respond_to?(:can_replicate)
|
37
|
+
model_class.class_eval do
|
38
|
+
extend Process
|
39
|
+
@replication_config = Class.new(Config).new(self)
|
40
|
+
include Model
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Include or extend it. We work with both.
|
45
|
+
def self.included(model_class)
|
46
|
+
model_class.extend self
|
29
47
|
end
|
30
48
|
|
31
49
|
class UnwoundError < StandardError; end;
|
data/test/orm/active_record.rb
CHANGED
@@ -3,8 +3,3 @@ ActiveRecord::Base.logger = Logger.new(nil)
|
|
3
3
|
ActiveRecord::Base.include_root_in_json = true
|
4
4
|
|
5
5
|
ActiveRecord::Migrator.migrate([File.expand_path("../../../db/migrate/", __FILE__), File.expand_path("../../rails_app/db/migrate/", __FILE__)])
|
6
|
-
|
7
|
-
class ActiveSupport::TestCase
|
8
|
-
self.use_transactional_fixtures = true
|
9
|
-
self.use_instantiated_fixtures = false
|
10
|
-
end
|
@@ -1,4 +1,7 @@
|
|
1
1
|
RailsApp::Application.configure do
|
2
|
+
|
3
|
+
config.active_support.test_order = :random
|
4
|
+
|
2
5
|
# Settings specified here will take precedence over those in config/application.rb.
|
3
6
|
|
4
7
|
# The test environment is used exclusively to run your application's
|
@@ -13,7 +16,7 @@ RailsApp::Application.configure do
|
|
13
16
|
config.eager_load = false
|
14
17
|
|
15
18
|
# Configure static asset server for tests with Cache-Control for performance.
|
16
|
-
config.
|
19
|
+
config.serve_static_files = true
|
17
20
|
config.static_cache_control = 'public, max-age=3600'
|
18
21
|
|
19
22
|
# Show full error reports and disable caching.
|
@@ -3,7 +3,7 @@ require "test_helper"
|
|
3
3
|
class Replication::ProcessTest < ActiveSupport::TestCase
|
4
4
|
|
5
5
|
def setup
|
6
|
-
Organism.extend Replication
|
6
|
+
Organism.extend Replication
|
7
7
|
end
|
8
8
|
|
9
9
|
test "extending provide can_replicate method" do
|
@@ -48,4 +48,12 @@ class Replication::ProcessTest < ActiveSupport::TestCase
|
|
48
48
|
|
49
49
|
assert_instance_of Organism, Organism.new_from_strand(name: 'Original Bacteria')
|
50
50
|
end
|
51
|
+
|
52
|
+
test "STI support" do
|
53
|
+
Animal.can_replicate
|
54
|
+
original = Animal.create(name: 'Bat', number_of_legs: 2, birth_date: Time.now)
|
55
|
+
strand = original.replicate(name: 'Original Bat')
|
56
|
+
|
57
|
+
assert_equal "Animal", strand.origin_type
|
58
|
+
end
|
51
59
|
end
|
data/test/test_helper.rb
CHANGED
@@ -4,14 +4,14 @@ REPLICATION_ORM = (ENV["REPLICATION_ORM"] || :active_record).to_sym
|
|
4
4
|
$:.unshift File.dirname(__FILE__)
|
5
5
|
|
6
6
|
require "rails_app/config/environment"
|
7
|
-
require "rails/test_help"
|
8
7
|
require "orm/#{REPLICATION_ORM}"
|
8
|
+
require "rails/test_help"
|
9
9
|
|
10
10
|
require "minitest/reporters"
|
11
11
|
Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: false)]
|
12
12
|
|
13
13
|
# Basic Setup
|
14
|
-
Organism.extend Replication
|
14
|
+
Organism.extend Replication
|
15
15
|
|
16
16
|
def organism_object
|
17
17
|
Organism.new(name: 'Bacteria', number_of_legs: 1, birth_date: Time.now)
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: replication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo DeAlmeida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Data replication as templates for Ruby ORMs
|
@@ -45,17 +45,19 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .gitignore
|
48
|
+
- ".gitignore"
|
49
49
|
- Gemfile
|
50
50
|
- LICENSE.txt
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- db/migrate/714417722_replication_migration.rb
|
54
54
|
- lib/replication.rb
|
55
|
+
- lib/replication/active_record/polymorphic_strand.rb
|
55
56
|
- lib/replication/active_record/strand.rb
|
56
57
|
- lib/replication/config.rb
|
57
58
|
- lib/replication/engine.rb
|
58
59
|
- lib/replication/modules/association.rb
|
60
|
+
- lib/replication/modules/polymorphic.rb
|
59
61
|
- lib/replication/modules/proofreading.rb
|
60
62
|
- lib/replication/modules/semi_conservative.rb
|
61
63
|
- lib/replication/process.rb
|
@@ -65,6 +67,7 @@ files:
|
|
65
67
|
- test/orm/active_record.rb
|
66
68
|
- test/rails_app/Rakefile
|
67
69
|
- test/rails_app/app/models/.keep
|
70
|
+
- test/rails_app/app/models/animal.rb
|
68
71
|
- test/rails_app/app/models/concerns/.keep
|
69
72
|
- test/rails_app/app/models/organism.rb
|
70
73
|
- test/rails_app/app/models/tool.rb
|
@@ -102,17 +105,17 @@ require_paths:
|
|
102
105
|
- lib
|
103
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
107
|
requirements:
|
105
|
-
- -
|
108
|
+
- - ">="
|
106
109
|
- !ruby/object:Gem::Version
|
107
110
|
version: '0'
|
108
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
112
|
requirements:
|
110
|
-
- -
|
113
|
+
- - ">="
|
111
114
|
- !ruby/object:Gem::Version
|
112
115
|
version: '0'
|
113
116
|
requirements: []
|
114
117
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
118
|
+
rubygems_version: 2.4.5
|
116
119
|
signing_key:
|
117
120
|
specification_version: 4
|
118
121
|
summary: Data replication as templates for Ruby ORMs
|
@@ -120,6 +123,7 @@ test_files:
|
|
120
123
|
- test/orm/active_record.rb
|
121
124
|
- test/rails_app/Rakefile
|
122
125
|
- test/rails_app/app/models/.keep
|
126
|
+
- test/rails_app/app/models/animal.rb
|
123
127
|
- test/rails_app/app/models/concerns/.keep
|
124
128
|
- test/rails_app/app/models/organism.rb
|
125
129
|
- test/rails_app/app/models/tool.rb
|