synchronisable 0.0.2 → 0.0.3

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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.rspec +0 -1
  4. data/.travis.yml +5 -0
  5. data/Gemfile +8 -1
  6. data/README.md +11 -4
  7. data/Rakefile +22 -3
  8. data/TODO.md +1 -1
  9. data/lib/generators/{synchronizable → synchronisable}/USAGE +0 -0
  10. data/lib/generators/{synchronizable → synchronisable}/install_generator.rb +2 -2
  11. data/lib/generators/{synchronizable → synchronisable}/templates/create_imports_migration.rb +4 -4
  12. data/lib/generators/{synchronizable → synchronisable}/templates/initializer.rb +2 -2
  13. data/lib/{synchronizable.rb → synchronisable.rb} +13 -13
  14. data/lib/{synchronizable → synchronisable}/context.rb +1 -1
  15. data/lib/{synchronizable → synchronisable}/dsl/associations.rb +4 -4
  16. data/lib/{synchronizable → synchronisable}/dsl/associations/association.rb +3 -3
  17. data/lib/{synchronizable → synchronisable}/dsl/associations/has_many.rb +2 -2
  18. data/lib/{synchronizable → synchronisable}/dsl/associations/has_one.rb +2 -2
  19. data/lib/{synchronizable → synchronisable}/dsl/macro.rb +8 -8
  20. data/lib/{synchronizable → synchronisable}/dsl/macro/attribute.rb +4 -4
  21. data/lib/{synchronizable → synchronisable}/dsl/macro/expression.rb +4 -4
  22. data/lib/{synchronizable → synchronisable}/dsl/macro/method.rb +4 -4
  23. data/lib/{synchronizable → synchronisable}/error_handler.rb +4 -4
  24. data/lib/{synchronizable → synchronisable}/exceptions.rb +1 -1
  25. data/lib/{synchronizable → synchronisable}/locale/en.yml +0 -0
  26. data/lib/{synchronizable → synchronisable}/locale/ru.yml +0 -0
  27. data/lib/{synchronizable → synchronisable}/model.rb +15 -15
  28. data/lib/{synchronizable → synchronisable}/model/methods.rb +6 -6
  29. data/lib/{synchronizable → synchronisable}/models/import.rb +6 -6
  30. data/lib/{synchronizable → synchronisable}/source.rb +3 -3
  31. data/lib/{synchronizable → synchronisable}/synchronizer.rb +18 -18
  32. data/lib/{synchronizable → synchronisable}/synchronizers/synchronizer_default.rb +2 -2
  33. data/lib/{synchronizable → synchronisable}/version.rb +2 -2
  34. data/lib/{synchronizable → synchronisable}/worker.rb +14 -14
  35. data/spec/dummy/app/models/match.rb +1 -1
  36. data/spec/dummy/app/models/match_player.rb +1 -1
  37. data/spec/dummy/app/models/player.rb +1 -1
  38. data/spec/dummy/app/models/stadium.rb +1 -1
  39. data/spec/dummy/app/models/stage.rb +1 -1
  40. data/spec/dummy/app/models/team.rb +1 -1
  41. data/spec/dummy/app/models/tournament.rb +1 -1
  42. data/spec/dummy/app/synchronizers/break_convention_team_synchronizer.rb +1 -1
  43. data/spec/dummy/app/synchronizers/match_synchronizer.rb +6 -6
  44. data/spec/dummy/app/synchronizers/player_synchronizer.rb +1 -1
  45. data/spec/dummy/app/synchronizers/stage_synchronizer.rb +1 -1
  46. data/spec/dummy/app/synchronizers/tournament_synchronizer.rb +1 -1
  47. data/spec/dummy/config/application.rb +1 -1
  48. data/spec/dummy/config/initializers/synchronizable.rb +1 -1
  49. data/spec/dummy/db/migrate/20140422135244_create_imports.rb +4 -4
  50. data/spec/dummy/db/schema.rb +3 -3
  51. data/spec/factories/import.rb +1 -1
  52. data/spec/models/match_spec.rb +10 -10
  53. data/spec/models/team_spec.rb +14 -18
  54. data/spec/spec_helper.rb +15 -5
  55. data/spec/{synchronizable → synchronisable}/dsl/macro_spec.rb +1 -1
  56. data/spec/synchronisable/models/import_spec.rb +10 -0
  57. data/spec/{synchronizable → synchronisable}/support/has_macro.rb +1 -1
  58. data/spec/{synchronizable → synchronisable}/support/has_macro_subclass.rb +0 -0
  59. data/spec/{synchronizable/synchronizable_spec.rb → synchronisable/synchronisable_spec.rb} +9 -9
  60. data/{synchronizable.gemspec → synchronisable.gemspec} +6 -4
  61. metadata +94 -79
  62. data/spec/synchronizable/models/import_spec.rb +0 -10
@@ -1,9 +1,9 @@
1
- require 'synchronizable/worker'
2
- require 'synchronizable/models/import'
1
+ require 'synchronisable/worker'
2
+ require 'synchronisable/models/import'
3
3
 
4
- module Synchronizable
4
+ module Synchronisable
5
5
  module Model
6
- # Methods that will be attached to synchronizable model class.
6
+ # Methods that will be attached to synchronisable model class.
7
7
  module Methods
8
8
  # Creates a new worker, that initiates synchronization
9
9
  # for this particular model.
@@ -21,7 +21,7 @@ module Synchronizable
21
21
  #
22
22
  # @param data [Array<Hash>] array of hashes with remote attributes.
23
23
  #
24
- # @see Synchronizable::Worker
24
+ # @see Synchronisable::Worker
25
25
  #
26
26
  # @example Supplying array of hashes with remote attributes
27
27
  # FooModel.sync([
@@ -48,7 +48,7 @@ module Synchronizable
48
48
 
49
49
  # Count of import records for this model.
50
50
  def imports_count
51
- Import.where(synchronizable_type: self).count
51
+ Import.where(synchronisable_type: self).count
52
52
  end
53
53
  end
54
54
  end
@@ -1,11 +1,11 @@
1
- module Synchronizable
1
+ module Synchronisable
2
2
  class Import < ActiveRecord::Base
3
- belongs_to :synchronizable, polymorphic: true
3
+ belongs_to :synchronisable, polymorphic: true
4
4
 
5
5
  serialize :attrs, Hash
6
6
 
7
- scope :with_synchronizable_type, ->(type) { where(synchronizable_type: type) }
8
- scope :with_synchronizable_ids, ->(ids) { where(synchronizable_id: ids) }
7
+ scope :with_synchronisable_type, ->(type) { where(synchronisable_type: type) }
8
+ scope :with_synchronisable_ids, ->(ids) { where(synchronisable_id: ids) }
9
9
 
10
10
  scope :with_remote_id, ->(id) { where(remote_id: id.to_s) }
11
11
  scope :with_remote_ids, ->(ids) { where(remote_id: ids.map(&:to_s)) }
@@ -14,9 +14,9 @@ module Synchronizable
14
14
  with_remote_id(id).first
15
15
  end
16
16
 
17
- def destroy_with_synchronizable
17
+ def destroy_with_synchronisable
18
18
  ActiveRecord::Base.transaction do
19
- synchronizable.try :destroy
19
+ synchronisable.try :destroy
20
20
  destroy
21
21
  end
22
22
  end
@@ -1,4 +1,4 @@
1
- module Synchronizable
1
+ module Synchronisable
2
2
  # Synchronization source.
3
3
  class Source
4
4
  attr_accessor :import_record
@@ -26,7 +26,7 @@ module Synchronizable
26
26
 
27
27
  @import_record = Import.find_by(
28
28
  :remote_id => @remote_id,
29
- :synchronizable_type => @model
29
+ :synchronisable_type => @model
30
30
  )
31
31
 
32
32
  set_parent_attribute
@@ -37,7 +37,7 @@ module Synchronizable
37
37
  end
38
38
 
39
39
  def local_record
40
- @import_record.try(:synchronizable)
40
+ @import_record.try(:synchronisable)
41
41
  end
42
42
 
43
43
  def dump_message
@@ -1,16 +1,16 @@
1
- require 'synchronizable/dsl/macro'
2
- require 'synchronizable/dsl/associations'
3
- require 'synchronizable/exceptions'
1
+ require 'synchronisable/dsl/macro'
2
+ require 'synchronisable/dsl/associations'
3
+ require 'synchronisable/exceptions'
4
4
 
5
- module Synchronizable
5
+ module Synchronisable
6
6
  # @abstract Subclass to create your model specific synchronizer class to
7
7
  # setup synchronization attributes and behavior.
8
8
  #
9
- # @see Synchronizable::DSL::Macro
10
- # @see Synchronizable::SynchronizerDefault
9
+ # @see Synchronisable::DSL::Macro
10
+ # @see Synchronisable::SynchronizerDefault
11
11
  class Synchronizer
12
- include Synchronizable::DSL::Macro
13
- include Synchronizable::DSL::Associations
12
+ include Synchronisable::DSL::Macro
13
+ include Synchronisable::DSL::Associations
14
14
 
15
15
  SYMBOL_ARRAY_CONVERTER = ->(source) { (source || []).map(&:to_s) }
16
16
 
@@ -47,7 +47,7 @@ module Synchronizable
47
47
  # Lambda that returns a hash with remote attributes by id.
48
48
  #
49
49
  # @example Common use case
50
- # class FooSynchronizer < Synchronizable::Synchronizer
50
+ # class FooSynchronizer < Synchronisable::Synchronizer
51
51
  # find do |id|
52
52
  # remote_source.find { |h| h[:foo_id] == id } }
53
53
  # end
@@ -57,33 +57,33 @@ module Synchronizable
57
57
  # Lambda, that will be called before synchronization
58
58
  # of each record and its assocations.
59
59
  #
60
- # @param source [Synchronizable::Source] synchronization source
60
+ # @param source [Synchronisable::Source] synchronization source
61
61
  #
62
62
  # @return [Boolean] `true` to continue sync, `false` to cancel
63
63
  method :before_sync
64
64
  # Lambda, that will be called every time
65
65
  # after record and its associations is synchronized.
66
66
  #
67
- # @param source [Synchronizable::Source] synchronization source
67
+ # @param source [Synchronisable::Source] synchronization source
68
68
  method :after_sync
69
69
 
70
70
  # Lambda, that will be called before synchronization of each record.
71
71
  #
72
- # @param source [Synchronizable::Source] synchronization source
72
+ # @param source [Synchronisable::Source] synchronization source
73
73
  #
74
74
  # @return [Boolean] `true` to continue sync, `false` to cancel
75
75
  method :before_record_sync
76
76
 
77
77
  # Lambda, that will be called every time after record is synchronized.
78
78
  #
79
- # @param source [Synchronizable::Source] synchronization source
79
+ # @param source [Synchronisable::Source] synchronization source
80
80
  method :after_record_sync
81
81
 
82
82
  # Lambda, that will be called before each association sync.
83
83
  #
84
- # @param source [Synchronizable::Source] synchronization source
84
+ # @param source [Synchronisable::Source] synchronization source
85
85
  # @param id association remote id
86
- # @param association [Synchronizable::DSL::Associations::Association]
86
+ # @param association [Synchronisable::DSL::Associations::Association]
87
87
  # association builder
88
88
  #
89
89
  # @return [Boolean] `true` to continue sync, `false` to cancel
@@ -91,9 +91,9 @@ module Synchronizable
91
91
 
92
92
  # Lambda, that will be called every time after association if synchronized.
93
93
  #
94
- # @param source [Synchronizable::Source] synchronization source
94
+ # @param source [Synchronisable::Source] synchronization source
95
95
  # @param id association remote id
96
- # @param association [Synchronizable::DSL::Associations::Association]
96
+ # @param association [Synchronisable::DSL::Associations::Association]
97
97
  # association builder
98
98
  method :after_association_sync
99
99
 
@@ -159,7 +159,7 @@ module Synchronizable
159
159
  after.(*args) if after
160
160
  end
161
161
 
162
- # Throws the {Synchronizable::MissedRemoteIdError} if given id isn't present.
162
+ # Throws the {Synchronisable::MissedRemoteIdError} if given id isn't present.
163
163
  #
164
164
  # @param id id to check
165
165
  #
@@ -1,6 +1,6 @@
1
- require 'synchronizable/synchronizer'
1
+ require 'synchronisable/synchronizer'
2
2
 
3
- module Synchronizable
3
+ module Synchronisable
4
4
  # Default synchronizer to be used when
5
5
  # model specific synchronizer is not defined.
6
6
  #
@@ -1,8 +1,8 @@
1
- module Synchronizable
1
+ module Synchronisable
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 2
5
+ PATCH = 3
6
6
  SUFFIX = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, SUFFIX].compact.join('.')
@@ -1,9 +1,9 @@
1
- require 'synchronizable/error_handler'
2
- require 'synchronizable/context'
3
- require 'synchronizable/source'
4
- require 'synchronizable/models/import'
1
+ require 'synchronisable/error_handler'
2
+ require 'synchronisable/context'
3
+ require 'synchronisable/source'
4
+ require 'synchronisable/models/import'
5
5
 
6
- module Synchronizable
6
+ module Synchronisable
7
7
  # Responsible for model synchronization.
8
8
  #
9
9
  # @api private
@@ -20,7 +20,7 @@ module Synchronizable
20
20
  # @overload run(model, data)
21
21
  # @overload run(model)
22
22
  #
23
- # @return [Synchronizable::Context] synchronization context
23
+ # @return [Synchronisable::Context] synchronization context
24
24
  def run(model, *args)
25
25
  options = args.extract_options!
26
26
  data = args.first
@@ -35,7 +35,7 @@ module Synchronizable
35
35
  # If not specified worker will try to get the data
36
36
  # using `fetch` lambda/proc defined in corresponding synchronizer
37
37
  #
38
- # @return [Synchronizable::Context] synchronization context
38
+ # @return [Synchronisable::Context] synchronization context
39
39
  def run(data)
40
40
  sync do |context|
41
41
  error_handler = ErrorHandler.new(@logger, context)
@@ -87,7 +87,7 @@ module Synchronizable
87
87
 
88
88
  # Method called by {#run} for each remote model attribute hash
89
89
  #
90
- # @param source [Synchronizable::Source] synchronization source
90
+ # @param source [Synchronisable::Source] synchronization source
91
91
  #
92
92
  # @return [Boolean] `true` if synchronization was completed
93
93
  # without errors, `false` otherwise
@@ -117,8 +117,8 @@ module Synchronizable
117
117
  def create_record_pair(source)
118
118
  local_record = @model.create!(source.local_attrs)
119
119
  import_record = Import.create!(
120
- :synchronizable_id => local_record.id,
121
- :synchronizable_type => @model.to_s,
120
+ :synchronisable_id => local_record.id,
121
+ :synchronisable_type => @model.to_s,
122
122
  :remote_id => source.remote_id,
123
123
  :attrs => source.local_attrs
124
124
  )
@@ -143,10 +143,10 @@ module Synchronizable
143
143
 
144
144
  # Synchronizes associations.
145
145
  #
146
- # @param source [Synchronizable::Source] synchronization source
146
+ # @param source [Synchronisable::Source] synchronization source
147
147
  #
148
- # @see Synchronizable::DSL::Associations
149
- # @see Synchronizable::DSL::Associations::Association
148
+ # @see Synchronisable::DSL::Associations
149
+ # @see Synchronisable::DSL::Associations::Association
150
150
  def sync_associations(source)
151
151
  if verbose_logging? && source.associations.present?
152
152
  @logger.info "starting associations sync"
@@ -185,7 +185,7 @@ module Synchronizable
185
185
  end
186
186
 
187
187
  def verbose_logging?
188
- Synchronizable.logging[:verbose]
188
+ Synchronisable.logging[:verbose]
189
189
  end
190
190
  end
191
191
  end
@@ -6,5 +6,5 @@ class Match < ActiveRecord::Base
6
6
 
7
7
  has_many :match_players, dependent: :destroy
8
8
 
9
- synchronizable
9
+ synchronisable
10
10
  end
@@ -11,5 +11,5 @@ class MatchPlayer < ActiveRecord::Base
11
11
 
12
12
  validates :match, :player, presence: true
13
13
 
14
- synchronizable
14
+ synchronisable
15
15
  end
@@ -1,5 +1,5 @@
1
1
  class Player < ActiveRecord::Base
2
2
  belongs_to :team
3
3
 
4
- synchronizable
4
+ synchronisable
5
5
  end
@@ -3,5 +3,5 @@ class Stadium < ActiveRecord::Base
3
3
  # so synchronization worker is gonna try
4
4
  # to use remote attributes as is to create a record
5
5
 
6
- synchronizable
6
+ synchronisable
7
7
  end
@@ -2,5 +2,5 @@ class Stage < ActiveRecord::Base
2
2
  belongs_to :tournament
3
3
  has_many :matches
4
4
 
5
- synchronizable
5
+ synchronisable
6
6
  end
@@ -1,5 +1,5 @@
1
1
  class Team < ActiveRecord::Base
2
2
  has_many :players
3
3
 
4
- synchronizable BreakConventionTeamSynchronizer
4
+ synchronisable BreakConventionTeamSynchronizer
5
5
  end
@@ -3,5 +3,5 @@ class Tournament < ActiveRecord::Base
3
3
 
4
4
  validates :name, :beginning, :ending, :presence => true
5
5
 
6
- synchronizable
6
+ synchronisable
7
7
  end
@@ -1,4 +1,4 @@
1
- class BreakConventionTeamSynchronizer < Synchronizable::Synchronizer
1
+ class BreakConventionTeamSynchronizer < Synchronisable::Synchronizer
2
2
  @gateway = TeamGateway.new
3
3
 
4
4
  remote_id :maet_id
@@ -1,4 +1,4 @@
1
- class MatchSynchronizer < Synchronizable::Synchronizer
1
+ class MatchSynchronizer < Synchronisable::Synchronizer
2
2
  @gateway = MatchGateway.new
3
3
 
4
4
  has_one :team, key: 'home_team_id'
@@ -39,12 +39,12 @@ class MatchSynchronizer < Synchronizable::Synchronizer
39
39
  match = source.local_record
40
40
  remote_player_ids = source.remote_attrs[ref_type.to_sym] || {}
41
41
 
42
- player_imports = Synchronizable::Import
43
- .with_synchronizable_type(Player)
42
+ player_imports = Synchronisable::Import
43
+ .with_synchronisable_type(Player)
44
44
  .with_remote_ids(remote_player_ids)
45
45
 
46
46
  local_player_ids = player_imports.map do |import|
47
- import.synchronizable.id
47
+ import.synchronisable.id
48
48
  end
49
49
 
50
50
  local_player_ids.each do |player_id|
@@ -60,8 +60,8 @@ class MatchSynchronizer < Synchronizable::Synchronizer
60
60
  match_player = MatchPlayer.find_by(attrs)
61
61
  unless match_player
62
62
  remote_id = "#{attrs[:match_id]}_#{attrs[:player_id]}"
63
- Synchronizable::Import.create!(
64
- :synchronizable => MatchPlayer.create!(attrs),
63
+ Synchronisable::Import.create!(
64
+ :synchronisable => MatchPlayer.create!(attrs),
65
65
  :remote_id => remote_id,
66
66
  :attrs => attrs
67
67
  )
@@ -1,4 +1,4 @@
1
- class PlayerSynchronizer < Synchronizable::Synchronizer
1
+ class PlayerSynchronizer < Synchronisable::Synchronizer
2
2
  @gateway = PlayerGateway.new
3
3
 
4
4
  remote_id :player_id
@@ -1,4 +1,4 @@
1
- class StageSynchronizer < Synchronizable::Synchronizer
1
+ class StageSynchronizer < Synchronisable::Synchronizer
2
2
  @gateway = StageGateway.new
3
3
 
4
4
  has_many :matches
@@ -1,4 +1,4 @@
1
- class TournamentSynchronizer < Synchronizable::Synchronizer
1
+ class TournamentSynchronizer < Synchronisable::Synchronizer
2
2
  @gateway = TournamentGateway.new
3
3
 
4
4
  has_many :stages
@@ -7,7 +7,7 @@ require 'action_view/railtie'
7
7
  require 'sprockets/railtie'
8
8
 
9
9
  Bundler.require(*Rails.groups)
10
- require 'synchronizable'
10
+ require 'synchronisable'
11
11
 
12
12
  module Dummy
13
13
  class Application < Rails::Application
@@ -1,2 +1,2 @@
1
- Synchronizable.configure do |config|
1
+ Synchronisable.configure do |config|
2
2
  end
@@ -1,8 +1,8 @@
1
1
  class CreateImports < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :imports do |t|
4
- t.string :synchronizable_type, null: false
5
- t.integer :synchronizable_id, null: false
4
+ t.string :synchronisable_type, null: false
5
+ t.integer :synchronisable_id, null: false
6
6
  t.text :attrs
7
7
  t.string :remote_id, null: false
8
8
 
@@ -10,12 +10,12 @@ class CreateImports < ActiveRecord::Migration
10
10
  end
11
11
 
12
12
  add_index :imports, :remote_id
13
- add_index :imports, [:synchronizable_type, :synchronizable_id]
13
+ add_index :imports, [:synchronisable_type, :synchronisable_id]
14
14
  end
15
15
 
16
16
  def self.down
17
17
  remove_index :imports, :remote_id
18
- remove_index :imports, [:synchronizable_type, :synchronizable_id]
18
+ remove_index :imports, [:synchronisable_type, :synchronisable_id]
19
19
  drop_table :imports
20
20
  end
21
21
  end
@@ -14,8 +14,8 @@
14
14
  ActiveRecord::Schema.define(version: 20140507140039) do
15
15
 
16
16
  create_table "imports", force: true do |t|
17
- t.string "synchronizable_type", null: false
18
- t.integer "synchronizable_id", null: false
17
+ t.string "synchronisable_type", null: false
18
+ t.integer "synchronisable_id", null: false
19
19
  t.text "attrs"
20
20
  t.string "remote_id", null: false
21
21
  t.datetime "created_at"
@@ -23,7 +23,7 @@ ActiveRecord::Schema.define(version: 20140507140039) do
23
23
  end
24
24
 
25
25
  add_index "imports", ["remote_id"], name: "index_imports_on_remote_id"
26
- add_index "imports", ["synchronizable_type", "synchronizable_id"], name: "index_imports_on_synchronizable_type_and_synchronizable_id"
26
+ add_index "imports", ["synchronisable_type", "synchronisable_id"], name: "index_imports_on_synchronisable_type_and_synchronisable_id"
27
27
 
28
28
  create_table "match_players", force: true do |t|
29
29
  t.integer "match_id"