replication 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f806ca18d9e7fba9d5e807ab8e6e116c9c9cbeb0
4
- data.tar.gz: 438097738f11ebb9cd1a17479567ed95bfaf005b
3
+ metadata.gz: af7f89d66290f3a6e85b44aa53a710af654de579
4
+ data.tar.gz: 1e4068b2e2debd7567d283e8c0a56c3606004239
5
5
  SHA512:
6
- metadata.gz: 6b55b5077da9447e8b36132215ecfaad70d3668942019c7eabac58ad8f3697134724d0f42d5169f20ed1a4c0fa541e437a291f25129db9d60e08bd52e62ebfb0
7
- data.tar.gz: 4bfb05a38b7713e250ec5dc83cd39502acac12144cb027c691a9edb7177594bdeaa3dffdef64ccdffcc3a83131408ec9aee89e0bf4e83dcb872dc5b0a2206feb
6
+ metadata.gz: 17a772115a1e9a9f53f4c8570fb1f6e78c72a940f159199333eb6d7f157f792c71d825066ca788de3b959b3174f4dad0005bf353ff314d9ecb6cab890eaad252
7
+ data.tar.gz: 46ec1398c27134b0db676e1d45a88449b39e0252659a191f88dd3286e6516333d6da949ac158a37f89bb853caec9a6b40aa04d429483dc183631a6887f2a7db9
data/.gitignore CHANGED
@@ -22,3 +22,6 @@ tmp
22
22
  mkmf.log
23
23
 
24
24
  *.log
25
+
26
+ .ruby-version
27
+ .ruby-gemset
data/README.md CHANGED
@@ -50,6 +50,11 @@ class Model
50
50
  end
51
51
  ```
52
52
 
53
+ You can whitelist an array of attributes. They'll be replicated in the new strand.
54
+ ```ruby
55
+ can_replicate only: [:some_column, :other_column]
56
+ ```
57
+
53
58
  You can blacklist an array of attributes. They'll not be replicated in the new strand.
54
59
  ```ruby
55
60
  can_replicate except: [:id, :name]
@@ -2,7 +2,7 @@ module Replication
2
2
 
3
3
  class Config
4
4
 
5
- attr_accessor :model_class, :pairs_method, :strand_class, :except
5
+ attr_accessor :model_class, :pairs_method, :strand_class, :except, :only
6
6
 
7
7
  def initialize(model_class)
8
8
  @model_class = model_class
@@ -1,3 +1,6 @@
1
+ require 'active_support/core_ext/hash/except'
2
+ require 'active_support/core_ext/hash/slice'
3
+
1
4
  module Replication
2
5
  module Modules
3
6
  module SemiConservative
@@ -19,7 +22,9 @@ module Replication
19
22
  end
20
23
 
21
24
  def strand_attributes
22
- _strand_attributes.except(*replication_config.except)
25
+ @strand_attributes = _strand_attributes
26
+ @strand_attributes = @strand_attributes.slice(*replication_config.only) unless replication_config.only.empty?
27
+ @strand_attributes = @strand_attributes.except(*replication_config.except) unless replication_config.except.empty?
23
28
  end
24
29
  end
25
30
  end
@@ -1,3 +1,3 @@
1
1
  module Replication
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/replication.rb CHANGED
@@ -16,8 +16,11 @@ module Replication
16
16
  end
17
17
 
18
18
  def self.defaults
19
- defaults = {}
20
- defaults.merge({
19
+ defaults = {
20
+ only: [],
21
+ except: []
22
+ }
23
+ defaults.merge!({
21
24
  strand_class: ::Replication::ActiveRecord::Strand,
22
25
  except: [:id, :created_at, :updated_at]
23
26
  }) if defined?(ActiveRecord)
@@ -6,9 +6,13 @@ class Replication::Modules::SemiConservativeTest < ActiveSupport::TestCase
6
6
  Organism.extend Replication::Process
7
7
  end
8
8
 
9
+ def organism_object
10
+ Organism.new(name: 'Bacteria', number_of_legs: 1, birth_date: Time.now)
11
+ end
12
+
9
13
  test "unwound with default options" do
10
14
  Organism.can_replicate
11
- organism = Organism.new(name: 'Bacteria', number_of_legs: 1, birth_date: Time.now)
15
+ organism = organism_object
12
16
  strand = organism.unwound(name: 'First bacteria')
13
17
 
14
18
  assert_equal organism.strand_attributes, strand.pairs
@@ -16,9 +20,26 @@ class Replication::Modules::SemiConservativeTest < ActiveSupport::TestCase
16
20
 
17
21
  test "replicate with default options" do
18
22
  Organism.can_replicate
19
- organism = Organism.new(name: 'Bacteria', number_of_legs: 1, birth_date: Time.now)
23
+ organism = organism_object
20
24
  strand = organism.replicate(name: 'First bacteria')
21
25
 
22
26
  assert_equal organism.strand_attributes, strand.pairs
23
27
  end
28
+
29
+ test "unwound with whitelist" do
30
+ Organism.can_replicate only: [:name]
31
+ organism = organism_object
32
+ strand = organism.replicate(name: 'First bacteria')
33
+
34
+ assert_equal ({ name: 'Bacteria' }), strand.pairs
35
+ end
36
+
37
+ test "unwound with blacklist" do
38
+ Organism.can_replicate except: [:id, :number_of_legs, :birth_date, :created_at, :updated_at]
39
+ organism = organism_object
40
+ strand = organism.replicate(name: 'First bacteria')
41
+
42
+ assert_equal ({ name: 'Bacteria' }), strand.pairs
43
+ end
44
+
24
45
  end
data/test/test_helper.rb CHANGED
@@ -8,4 +8,4 @@ require "rails/test_help"
8
8
  require "orm/#{REPLICATION_ORM}"
9
9
 
10
10
  require "minitest/reporters"
11
- Minitest::Reporters.use!
11
+ Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: false)]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: replication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.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: 2014-06-24 00:00:00.000000000 Z
11
+ date: 2014-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler