synchronisable 1.1.6 → 1.1.7

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: 70388e8c1eef4b5cb5e12223a4201d02073248ad
4
- data.tar.gz: 829ab2f2ebf18374eaaab7e34b97ca084c494224
3
+ metadata.gz: 02c09a1ef8d6a3cfb421f127643ad5b79655756f
4
+ data.tar.gz: 7f5e474b07df81f291239fbd71a7a700007cfbaa
5
5
  SHA512:
6
- metadata.gz: 3c4b925a4fb1a39e8c7d440fea7803c2303f89b7fad7b951564aa800b18b21d48934691f686e9e112102e005df959792f67d08ba4529687b7e4a84977905e74e
7
- data.tar.gz: 7f69d985173f10d17fb3e84474c7b1dc4c0d0d8e8f85eadf9d7cf42a6364aa3072606a0a275a09060a8ec28268998640664019ba2de87f9bae199a239cc58e14
6
+ metadata.gz: 453ce50073eb8f24ee073738c08f2a96d2692a0e5ce193e5652fc1800887f61347172ca1ccb83f17f4b0ad7c941b84d9746e519e7ba83db6910c8d9c61d9d648
7
+ data.tar.gz: a13eff1a136a0b5d001c6a9268dd53e66aeab994ccebb3960f99ca7ac761f72d9d4b439ed0805880d3742fa0924c6f188381b2ff8838129918b443d49f7bdb4d
data/README.md CHANGED
@@ -32,10 +32,6 @@ And then execute:
32
32
 
33
33
  $ bundle
34
34
 
35
- Or install it yourself as:
36
-
37
- $ gem install synchronisable
38
-
39
35
  Optionally, if you are using rails to run an initializer generator:
40
36
 
41
37
  $ rails g synchronisable:install
@@ -15,4 +15,8 @@ Synchronisable.configure do |config|
15
15
  # a `synchronisable` dsl instruction.
16
16
  #
17
17
  # config.models = %w(Foo Bar)
18
+
19
+ # What to do with an associated import record
20
+ # when its synchronisable is destroyed. Default is `:destroy`.
21
+ # config.dependent_import = :destroy
18
22
  end
@@ -2,9 +2,14 @@ module Synchronisable
2
2
  class Configuration
3
3
  include ActiveSupport::Configurable
4
4
 
5
+ config_accessor :dependent_import do
6
+ :destroy
7
+ end
8
+
5
9
  config_accessor :models do
6
- {}
10
+ []
7
11
  end
12
+
8
13
  config_accessor :logging do
9
14
  default_logger = -> { Logger.new(STDOUT) }
10
15
  rails_logger = -> { Rails.logger || default_logger.() }
@@ -0,0 +1,22 @@
1
+ require 'synchronisable/models/import'
2
+
3
+ module Synchronisable
4
+ module Model
5
+ module Scopes
6
+ def not_imported
7
+ includes(:import)
8
+ .where(imports: { synchronisable_id: nil })
9
+ .references(:imports)
10
+ end
11
+
12
+ def imported
13
+ includes(:import)
14
+ .where.not(imports: { synchronisable_id: nil })
15
+ .refences(:imports)
16
+ end
17
+
18
+ alias_method :without_import, :not_imported
19
+ alias_method :with_import, :imported
20
+ end
21
+ end
22
+ end
@@ -1,4 +1,5 @@
1
1
  require 'synchronisable/model/methods'
2
+ require 'synchronisable/model/scopes'
2
3
  require 'synchronisable/synchronizers/synchronizer_default'
3
4
 
4
5
  module Synchronisable
@@ -29,24 +30,28 @@ module Synchronisable
29
30
  # end
30
31
  def synchronisable(*args)
31
32
  extend Synchronisable::Model::Methods
33
+ extend Synchronisable::Model::Scopes
32
34
 
33
35
  class_attribute :synchronizer
34
- has_one :import, as: :synchronisable, class_name: 'Synchronisable::Import'
35
36
 
36
- scope :without_import, -> {
37
- includes(:import)
38
- .where(imports: { synchronisable_id: nil })
39
- .references(:imports)
40
- }
37
+ options = args.extract_options!
38
+
39
+ set_defaults(options)
40
+ set_synchronizer(args, options)
41
41
 
42
- set_defaults(args)
42
+ has_one :import,
43
+ as: :synchronisable,
44
+ class_name: 'Synchronisable::Import',
45
+ dependent: options[:dependent]
43
46
  end
44
47
 
45
48
  private
46
49
 
47
- def set_defaults(args)
48
- options = args.extract_options!
50
+ def set_defaults(options)
51
+ options[:dependent] ||= Synchronisable.config.dependent_import
52
+ end
49
53
 
54
+ def set_synchronizer(args, options)
50
55
  self.synchronizer = args.first || options[:synchronizer] ||
51
56
  find_synchronizer || SynchronizerDefault
52
57
  end
@@ -2,7 +2,7 @@ module Synchronisable
2
2
  module VERSION
3
3
  MAJOR = 1
4
4
  MINOR = 1
5
- PATCH = 6
5
+ PATCH = 7
6
6
  SUFFIX = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, SUFFIX].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synchronisable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasiliy Yorkin
@@ -310,6 +310,7 @@ files:
310
310
  - lib/synchronisable/locale/ru.yml
311
311
  - lib/synchronisable/model.rb
312
312
  - lib/synchronisable/model/methods.rb
313
+ - lib/synchronisable/model/scopes.rb
313
314
  - lib/synchronisable/models/import.rb
314
315
  - lib/synchronisable/source.rb
315
316
  - lib/synchronisable/synchronizer.rb