synchronisable 0.0.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 +7 -0
- data/.gitignore +20 -0
- data/.rspec +3 -0
- data/.ruby-version +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +9 -0
- data/Guardfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +22 -0
- data/Rakefile +7 -0
- data/TODO.md +20 -0
- data/bin/autospec +16 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/lib/generators/synchronizable/USAGE +2 -0
- data/lib/generators/synchronizable/install_generator.rb +24 -0
- data/lib/generators/synchronizable/templates/create_imports_migration.rb +21 -0
- data/lib/generators/synchronizable/templates/initializer.rb +14 -0
- data/lib/synchronizable.rb +92 -0
- data/lib/synchronizable/context.rb +25 -0
- data/lib/synchronizable/dsl/associations.rb +57 -0
- data/lib/synchronizable/dsl/associations/association.rb +59 -0
- data/lib/synchronizable/dsl/associations/has_many.rb +12 -0
- data/lib/synchronizable/dsl/associations/has_one.rb +13 -0
- data/lib/synchronizable/dsl/macro.rb +100 -0
- data/lib/synchronizable/dsl/macro/attribute.rb +41 -0
- data/lib/synchronizable/dsl/macro/expression.rb +51 -0
- data/lib/synchronizable/dsl/macro/method.rb +15 -0
- data/lib/synchronizable/error_handler.rb +50 -0
- data/lib/synchronizable/exceptions.rb +8 -0
- data/lib/synchronizable/locale/en.yml +17 -0
- data/lib/synchronizable/locale/ru.yml +17 -0
- data/lib/synchronizable/model.rb +54 -0
- data/lib/synchronizable/model/methods.rb +55 -0
- data/lib/synchronizable/models/import.rb +24 -0
- data/lib/synchronizable/source.rb +72 -0
- data/lib/synchronizable/synchronizer.rb +177 -0
- data/lib/synchronizable/synchronizers/synchronizer_default.rb +10 -0
- data/lib/synchronizable/version.rb +10 -0
- data/lib/synchronizable/worker.rb +191 -0
- data/spec/dummy/.gitignore +16 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +16 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/gateways/gateway_base.rb +19 -0
- data/spec/dummy/app/gateways/match_gateway.rb +15 -0
- data/spec/dummy/app/gateways/player_gateway.rb +26 -0
- data/spec/dummy/app/gateways/stage_gateway.rb +18 -0
- data/spec/dummy/app/gateways/team_gateway.rb +18 -0
- data/spec/dummy/app/gateways/tournament_gateway.rb +15 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/match.rb +10 -0
- data/spec/dummy/app/models/match_player.rb +15 -0
- data/spec/dummy/app/models/player.rb +5 -0
- data/spec/dummy/app/models/stadium.rb +7 -0
- data/spec/dummy/app/models/stage.rb +6 -0
- data/spec/dummy/app/models/team.rb +5 -0
- data/spec/dummy/app/models/tournament.rb +7 -0
- data/spec/dummy/app/synchronizers/break_convention_team_synchronizer.rb +14 -0
- data/spec/dummy/app/synchronizers/match_synchronizer.rb +71 -0
- data/spec/dummy/app/synchronizers/player_synchronizer.rb +19 -0
- data/spec/dummy/app/synchronizers/stage_synchronizer.rb +20 -0
- data/spec/dummy/app/synchronizers/tournament_synchronizer.rb +20 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +26 -0
- data/spec/dummy/config/boot.rb +6 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +33 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +20 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/synchronizable.rb +2 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/db/migrate/20140422132431_create_teams.rb +11 -0
- data/spec/dummy/db/migrate/20140422132544_create_matches.rb +12 -0
- data/spec/dummy/db/migrate/20140422132708_create_players.rb +15 -0
- data/spec/dummy/db/migrate/20140422133122_create_match_players.rb +12 -0
- data/spec/dummy/db/migrate/20140422135244_create_imports.rb +21 -0
- data/spec/dummy/db/migrate/20140422140817_create_stadiums.rb +10 -0
- data/spec/dummy/db/migrate/20140507135800_create_tournaments.rb +13 -0
- data/spec/dummy/db/migrate/20140507135837_create_stages.rb +13 -0
- data/spec/dummy/db/migrate/20140507140039_add_stage_id_to_matches.rb +6 -0
- data/spec/dummy/db/schema.rb +103 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/vendor/assets/javascripts/.keep +0 -0
- data/spec/dummy/vendor/assets/stylesheets/.keep +0 -0
- data/spec/factories/import.rb +5 -0
- data/spec/factories/match.rb +9 -0
- data/spec/factories/match_player.rb +9 -0
- data/spec/factories/player.rb +10 -0
- data/spec/factories/remote/match.rb +21 -0
- data/spec/factories/remote/player.rb +18 -0
- data/spec/factories/remote/stage.rb +26 -0
- data/spec/factories/remote/team.rb +21 -0
- data/spec/factories/remote/tournament.rb +18 -0
- data/spec/factories/stadium.rb +7 -0
- data/spec/factories/team.rb +16 -0
- data/spec/models/match_spec.rb +41 -0
- data/spec/models/team_spec.rb +85 -0
- data/spec/spec_helper.rb +64 -0
- data/spec/synchronizable/dsl/macro_spec.rb +59 -0
- data/spec/synchronizable/models/import_spec.rb +10 -0
- data/spec/synchronizable/support/has_macro.rb +12 -0
- data/spec/synchronizable/support/has_macro_subclass.rb +9 -0
- data/spec/synchronizable/synchronizable_spec.rb +60 -0
- data/synchronizable.gemspec +39 -0
- metadata +506 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
|
2
|
+
#
|
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
|
6
|
+
|
|
7
|
+
# Ignore bundler config.
|
|
8
|
+
/.bundle
|
|
9
|
+
|
|
10
|
+
# Ignore the default SQLite database.
|
|
11
|
+
/db/*.sqlite3
|
|
12
|
+
/db/*.sqlite3-journal
|
|
13
|
+
|
|
14
|
+
# Ignore all logfiles and tempfiles.
|
|
15
|
+
/log/*.log
|
|
16
|
+
/tmp
|
data/spec/dummy/Rakefile
ADDED
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require jquery
|
|
14
|
+
//= require jquery_ujs
|
|
15
|
+
//= require turbolinks
|
|
16
|
+
//= require_tree .
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
|
10
|
+
*
|
|
11
|
+
*= require_self
|
|
12
|
+
*= require_tree .
|
|
13
|
+
*/
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class GatewayBase
|
|
2
|
+
def id_key
|
|
3
|
+
raise NotImplementedError,
|
|
4
|
+
I18n.t('errors.gateway_method_missing', method: 'id_key')
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def source
|
|
8
|
+
raise NotImplementedError,
|
|
9
|
+
I18n.t('errors.gateway_method_missing', method: 'source')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def fetch
|
|
13
|
+
source
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def find(id)
|
|
17
|
+
source.find { |h| h[id_key] == id }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class PlayerGateway < GatewayBase
|
|
2
|
+
def id_key
|
|
3
|
+
:player_id
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def source
|
|
7
|
+
@source ||= [
|
|
8
|
+
FactoryGirl.build(:remote_player,
|
|
9
|
+
:team => 'team_0',
|
|
10
|
+
:player_id => 'player_0'
|
|
11
|
+
),
|
|
12
|
+
FactoryGirl.build(:remote_player,
|
|
13
|
+
:team => 'team_0',
|
|
14
|
+
:player_id => 'player_2'
|
|
15
|
+
),
|
|
16
|
+
FactoryGirl.build(:remote_player,
|
|
17
|
+
:team => 'team_1',
|
|
18
|
+
:player_id => 'player_1'
|
|
19
|
+
),
|
|
20
|
+
FactoryGirl.build(:remote_player,
|
|
21
|
+
:team => 'team_1',
|
|
22
|
+
:player_id => 'player_3'
|
|
23
|
+
)
|
|
24
|
+
]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class StageGateway < GatewayBase
|
|
2
|
+
def id_key
|
|
3
|
+
:stage_id
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def source
|
|
7
|
+
@source ||= [
|
|
8
|
+
FactoryGirl.build(:remote_stage,
|
|
9
|
+
:stage_id => 'stage_0',
|
|
10
|
+
:matches_ids => %w(match_0)
|
|
11
|
+
),
|
|
12
|
+
FactoryGirl.build( :remote_stage,
|
|
13
|
+
:stage_id => 'stage_1',
|
|
14
|
+
:matches_ids => %w(match_0)
|
|
15
|
+
)
|
|
16
|
+
]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class TeamGateway < GatewayBase
|
|
2
|
+
def id_key
|
|
3
|
+
:maet_id
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def source
|
|
7
|
+
@source ||= [
|
|
8
|
+
FactoryGirl.build(:remote_team,
|
|
9
|
+
:maet_id => 'team_0',
|
|
10
|
+
:players_ids => %w(player_0 player_2)
|
|
11
|
+
),
|
|
12
|
+
FactoryGirl.build(:remote_team,
|
|
13
|
+
:maet_id => 'team_1',
|
|
14
|
+
:players_ids => %w(player_1 player_3)
|
|
15
|
+
)
|
|
16
|
+
]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class TournamentGateway < GatewayBase
|
|
2
|
+
def id_key
|
|
3
|
+
:tour_id
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def source
|
|
7
|
+
@source ||= [
|
|
8
|
+
FactoryGirl.build(:remote_tournament,
|
|
9
|
+
:tour_id => 'tournament_0',
|
|
10
|
+
:is_current => true,
|
|
11
|
+
:stages_ids => %w(stage_0 stage_1)
|
|
12
|
+
)
|
|
13
|
+
]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class MatchPlayer < ActiveRecord::Base
|
|
2
|
+
REF_TYPES = [
|
|
3
|
+
REF_TYPE_LINE_UP_HOME = 'line_up_home',
|
|
4
|
+
REF_TYPE_LINE_UP_AWAY = 'line_up_away',
|
|
5
|
+
REF_TYPE_SUBSTITUTES_HOME = 'substitutes_home',
|
|
6
|
+
REF_TYPE_SUBSTITUTES_AWAY = 'substitutes_away'
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
belongs_to :match
|
|
10
|
+
belongs_to :player
|
|
11
|
+
|
|
12
|
+
validates :match, :player, presence: true
|
|
13
|
+
|
|
14
|
+
synchronizable
|
|
15
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class BreakConventionTeamSynchronizer < Synchronizable::Synchronizer
|
|
2
|
+
@gateway = TeamGateway.new
|
|
3
|
+
|
|
4
|
+
remote_id :maet_id
|
|
5
|
+
mappings(
|
|
6
|
+
:eman => :name,
|
|
7
|
+
:yrtnuoc => :country,
|
|
8
|
+
:ytic => :city
|
|
9
|
+
)
|
|
10
|
+
except :ignored_1, :ignored_2
|
|
11
|
+
|
|
12
|
+
find { |id| @gateway.find(id) }
|
|
13
|
+
fetch { @gateway.fetch }
|
|
14
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
class MatchSynchronizer < Synchronizable::Synchronizer
|
|
2
|
+
@gateway = MatchGateway.new
|
|
3
|
+
|
|
4
|
+
has_one :team, key: 'home_team_id'
|
|
5
|
+
has_one :team, key: 'away_team_id'
|
|
6
|
+
|
|
7
|
+
has_many :players
|
|
8
|
+
|
|
9
|
+
remote_id :match_id
|
|
10
|
+
|
|
11
|
+
mappings(
|
|
12
|
+
:gninnigeb => :beginning,
|
|
13
|
+
:home_team => :home_team_id,
|
|
14
|
+
:away_team => :away_team_id,
|
|
15
|
+
:rehtaew => :weather,
|
|
16
|
+
:ln_home => :line_up_home,
|
|
17
|
+
:ln_away => :line_up_away,
|
|
18
|
+
:sub_home => :substitutes_home,
|
|
19
|
+
:sub_away => :substitutes_away
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
except :ignored_1, :ignored_2,
|
|
23
|
+
:line_up_home, :line_up_away,
|
|
24
|
+
:substitutes_home, :substitutes_away
|
|
25
|
+
|
|
26
|
+
destroy_missed true
|
|
27
|
+
|
|
28
|
+
find { |id| @gateway.find(id) }
|
|
29
|
+
fetch { @gateway.fetch }
|
|
30
|
+
|
|
31
|
+
after_sync do |source|
|
|
32
|
+
MatchPlayer::REF_TYPES.each do |ref_type|
|
|
33
|
+
sync_match_players(source, ref_type)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class << self
|
|
38
|
+
def sync_match_players(source, ref_type)
|
|
39
|
+
match = source.local_record
|
|
40
|
+
remote_player_ids = source.remote_attrs[ref_type.to_sym] || {}
|
|
41
|
+
|
|
42
|
+
player_imports = Synchronizable::Import
|
|
43
|
+
.with_synchronizable_type(Player)
|
|
44
|
+
.with_remote_ids(remote_player_ids)
|
|
45
|
+
|
|
46
|
+
local_player_ids = player_imports.map do |import|
|
|
47
|
+
import.synchronizable.id
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
local_player_ids.each do |player_id|
|
|
51
|
+
sync_match_player({
|
|
52
|
+
:match_id => match.id,
|
|
53
|
+
:player_id => player_id,
|
|
54
|
+
:ref_type => ref_type
|
|
55
|
+
})
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def sync_match_player(attrs)
|
|
60
|
+
match_player = MatchPlayer.find_by(attrs)
|
|
61
|
+
unless match_player
|
|
62
|
+
remote_id = "#{attrs[:match_id]}_#{attrs[:player_id]}"
|
|
63
|
+
Synchronizable::Import.create!(
|
|
64
|
+
:synchronizable => MatchPlayer.create!(attrs),
|
|
65
|
+
:remote_id => remote_id,
|
|
66
|
+
:attrs => attrs
|
|
67
|
+
)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class PlayerSynchronizer < Synchronizable::Synchronizer
|
|
2
|
+
@gateway = PlayerGateway.new
|
|
3
|
+
|
|
4
|
+
remote_id :player_id
|
|
5
|
+
|
|
6
|
+
mappings(
|
|
7
|
+
:eman_tsrif => :first_name,
|
|
8
|
+
:eman_tsal => :last_name,
|
|
9
|
+
:yadhtrib => :birthday,
|
|
10
|
+
:pihsnezitic => :citizenship,
|
|
11
|
+
:thgieh => :height,
|
|
12
|
+
:thgiew => :weight,
|
|
13
|
+
:team => :team_id
|
|
14
|
+
)
|
|
15
|
+
only :team_id, :first_name, :last_name
|
|
16
|
+
|
|
17
|
+
find { |id| @gateway.find(id) }
|
|
18
|
+
fetch { @gateway.fetch }
|
|
19
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class StageSynchronizer < Synchronizable::Synchronizer
|
|
2
|
+
@gateway = StageGateway.new
|
|
3
|
+
|
|
4
|
+
has_many :matches
|
|
5
|
+
|
|
6
|
+
remote_id :stage_id
|
|
7
|
+
|
|
8
|
+
mappings(
|
|
9
|
+
:tour_id => :tournament_id,
|
|
10
|
+
:gninnigeb => :beginning,
|
|
11
|
+
:gnidge => :ending,
|
|
12
|
+
:eman => :name,
|
|
13
|
+
:rebmun => :number
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
except :ignored_1, :ignored_2
|
|
17
|
+
|
|
18
|
+
find { |id| @gateway.find(id) }
|
|
19
|
+
fetch { @gateway.fetch }
|
|
20
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class TournamentSynchronizer < Synchronizable::Synchronizer
|
|
2
|
+
@gateway = TournamentGateway.new
|
|
3
|
+
|
|
4
|
+
has_many :stages
|
|
5
|
+
|
|
6
|
+
remote_id :tour_id
|
|
7
|
+
|
|
8
|
+
mappings(
|
|
9
|
+
:eman => :name,
|
|
10
|
+
:eman_trohs => :short_name,
|
|
11
|
+
:gninnigeb => :beginning,
|
|
12
|
+
:gnidge => :ending,
|
|
13
|
+
:tnerruc_si => :is_current
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
only :name, :beginning, :ending
|
|
17
|
+
|
|
18
|
+
find { |id| @gateway.find(id) }
|
|
19
|
+
fetch { @gateway.fetch }
|
|
20
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Dummy</title>
|
|
5
|
+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
|
6
|
+
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
|
|
7
|
+
<%= csrf_meta_tags %>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
|
|
11
|
+
<%= yield %>
|
|
12
|
+
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|