synchronisable 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.rspec +0 -1
- data/.travis.yml +5 -0
- data/Gemfile +8 -1
- data/README.md +11 -4
- data/Rakefile +22 -3
- data/TODO.md +1 -1
- data/lib/generators/{synchronizable → synchronisable}/USAGE +0 -0
- data/lib/generators/{synchronizable → synchronisable}/install_generator.rb +2 -2
- data/lib/generators/{synchronizable → synchronisable}/templates/create_imports_migration.rb +4 -4
- data/lib/generators/{synchronizable → synchronisable}/templates/initializer.rb +2 -2
- data/lib/{synchronizable.rb → synchronisable.rb} +13 -13
- data/lib/{synchronizable → synchronisable}/context.rb +1 -1
- data/lib/{synchronizable → synchronisable}/dsl/associations.rb +4 -4
- data/lib/{synchronizable → synchronisable}/dsl/associations/association.rb +3 -3
- data/lib/{synchronizable → synchronisable}/dsl/associations/has_many.rb +2 -2
- data/lib/{synchronizable → synchronisable}/dsl/associations/has_one.rb +2 -2
- data/lib/{synchronizable → synchronisable}/dsl/macro.rb +8 -8
- data/lib/{synchronizable → synchronisable}/dsl/macro/attribute.rb +4 -4
- data/lib/{synchronizable → synchronisable}/dsl/macro/expression.rb +4 -4
- data/lib/{synchronizable → synchronisable}/dsl/macro/method.rb +4 -4
- data/lib/{synchronizable → synchronisable}/error_handler.rb +4 -4
- data/lib/{synchronizable → synchronisable}/exceptions.rb +1 -1
- data/lib/{synchronizable → synchronisable}/locale/en.yml +0 -0
- data/lib/{synchronizable → synchronisable}/locale/ru.yml +0 -0
- data/lib/{synchronizable → synchronisable}/model.rb +15 -15
- data/lib/{synchronizable → synchronisable}/model/methods.rb +6 -6
- data/lib/{synchronizable → synchronisable}/models/import.rb +6 -6
- data/lib/{synchronizable → synchronisable}/source.rb +3 -3
- data/lib/{synchronizable → synchronisable}/synchronizer.rb +18 -18
- data/lib/{synchronizable → synchronisable}/synchronizers/synchronizer_default.rb +2 -2
- data/lib/{synchronizable → synchronisable}/version.rb +2 -2
- data/lib/{synchronizable → synchronisable}/worker.rb +14 -14
- data/spec/dummy/app/models/match.rb +1 -1
- data/spec/dummy/app/models/match_player.rb +1 -1
- data/spec/dummy/app/models/player.rb +1 -1
- data/spec/dummy/app/models/stadium.rb +1 -1
- data/spec/dummy/app/models/stage.rb +1 -1
- data/spec/dummy/app/models/team.rb +1 -1
- data/spec/dummy/app/models/tournament.rb +1 -1
- data/spec/dummy/app/synchronizers/break_convention_team_synchronizer.rb +1 -1
- data/spec/dummy/app/synchronizers/match_synchronizer.rb +6 -6
- data/spec/dummy/app/synchronizers/player_synchronizer.rb +1 -1
- data/spec/dummy/app/synchronizers/stage_synchronizer.rb +1 -1
- data/spec/dummy/app/synchronizers/tournament_synchronizer.rb +1 -1
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/initializers/synchronizable.rb +1 -1
- data/spec/dummy/db/migrate/20140422135244_create_imports.rb +4 -4
- data/spec/dummy/db/schema.rb +3 -3
- data/spec/factories/import.rb +1 -1
- data/spec/models/match_spec.rb +10 -10
- data/spec/models/team_spec.rb +14 -18
- data/spec/spec_helper.rb +15 -5
- data/spec/{synchronizable → synchronisable}/dsl/macro_spec.rb +1 -1
- data/spec/synchronisable/models/import_spec.rb +10 -0
- data/spec/{synchronizable → synchronisable}/support/has_macro.rb +1 -1
- data/spec/{synchronizable → synchronisable}/support/has_macro_subclass.rb +0 -0
- data/spec/{synchronizable/synchronizable_spec.rb → synchronisable/synchronisable_spec.rb} +9 -9
- data/{synchronizable.gemspec → synchronisable.gemspec} +6 -4
- metadata +94 -79
- data/spec/synchronizable/models/import_spec.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1816035987d8bab6ea54e58aab1a9ee8a8477766
|
4
|
+
data.tar.gz: 1c2e17f3e3ed31c29e87283a0065ac25861a210e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1903884dcb5008df7cc0703bfa294397faaa2b2cf806e3597f0f670529df88a62613464aeb230c40564a46cb6968b5bd03e4a1222a4cfa46d23948db15172ba5
|
7
|
+
data.tar.gz: face867f4e7d462e427904b3e195aa16a6a40fa7d9b89bc28673bd6f0fc1d52b6dc359ee388acf33a24ee8e4bfd24f5e0e5ba839fad28e98d90cc1ad492a9ee3
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: VgctGe2yW3LCxsIUQthEwU3jSpqzYYlxu
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -6,4 +6,11 @@ gem 'pry'
|
|
6
6
|
gem 'byebug'
|
7
7
|
gem 'pry-byebug'
|
8
8
|
|
9
|
-
|
9
|
+
group :test, :development do
|
10
|
+
gem 'pre-commit'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem 'coveralls', require: false
|
15
|
+
gem 'codeclimate-test-reporter', require: false
|
16
|
+
end
|
data/README.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/vyorkin/
|
1
|
+
[![Build Status](https://travis-ci.org/vyorkin/synchronisable.png?branch=master)](https://travis-ci.org/vyorkin/synchronisable)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/vyorkin/synchronisable.png)](https://codeclimate.com/github/vyorkin/synchronisable)
|
3
|
+
[![Coverage Status](https://coveralls.io/repos/vyorkin/synchronisable/badge.png)](https://coveralls.io/r/vyorkin/synchronisable)
|
4
|
+
[![Inch Pages](http://inch-pages.github.io/github/vyorkin/synchronisable)](http://inch-pages.github.io/github/vyorkin/synchronisable)
|
5
|
+
[![Gem Version](http://stillmaintained.com/vyorkin/synchronisable.png)](http://stillmaintained.com/vyorkin/synchronisable)
|
6
|
+
[![Dependency Status](https://gemnasium.com/vyorkin/synchronisable.svg)](https://gemnasium.com/vyorkin/synchronisable)
|
2
7
|
|
3
|
-
|
8
|
+
|
9
|
+
|
10
|
+
# Synchronisable
|
4
11
|
|
5
12
|
Provides base fuctionality (models, DSL) for AR synchronization with external resources (apis, services etc)
|
6
13
|
|
@@ -8,7 +15,7 @@ Provides base fuctionality (models, DSL) for AR synchronization with external re
|
|
8
15
|
|
9
16
|
Add this line to your application's Gemfile:
|
10
17
|
|
11
|
-
gem '
|
18
|
+
gem 'synchronisable'
|
12
19
|
|
13
20
|
And then execute:
|
14
21
|
|
@@ -16,7 +23,7 @@ And then execute:
|
|
16
23
|
|
17
24
|
Or install it yourself as:
|
18
25
|
|
19
|
-
$ gem install
|
26
|
+
$ gem install synchronisable
|
20
27
|
|
21
28
|
## Usage
|
22
29
|
|
data/Rakefile
CHANGED
@@ -1,7 +1,26 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'rake'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rspec/core/rake_task'
|
3
4
|
|
4
5
|
RSpec::Core::RakeTask.new(:spec)
|
5
6
|
|
6
|
-
|
7
|
+
def run_in_dummy_app(command)
|
8
|
+
success = system("cd spec/dummy && #{command}")
|
9
|
+
raise "#{command} failed" unless success
|
10
|
+
end
|
11
|
+
|
12
|
+
task default: :ci
|
7
13
|
task test: :spec
|
14
|
+
|
15
|
+
desc 'Run all tests for CI'
|
16
|
+
task ci: %w(db:setup spec)
|
17
|
+
|
18
|
+
namespace :db do
|
19
|
+
desc 'Set up databases for integration testing'
|
20
|
+
task :setup do
|
21
|
+
puts 'Setting up databases'
|
22
|
+
run_in_dummy_app 'rm -f db/*.sqlite3'
|
23
|
+
run_in_dummy_app 'rake db:create db:migrate db:seed'
|
24
|
+
run_in_dummy_app 'RAILS_ENV=test rake db:create db:migrate db:seed'
|
25
|
+
end
|
26
|
+
end
|
data/TODO.md
CHANGED
@@ -4,7 +4,7 @@ Primary objectives
|
|
4
4
|
* except/only (DONE)
|
5
5
|
* sync method (DONE)
|
6
6
|
* dependent syncronization & mapping (DONE)
|
7
|
-
* tests for
|
7
|
+
* tests for Synchronisable.sync (DONE)
|
8
8
|
* destroy_missed
|
9
9
|
* worker.rb refactoring
|
10
10
|
* integrate with travis, stillmaintained, gemnasium
|
File without changes
|
@@ -2,7 +2,7 @@ require 'rails/generators'
|
|
2
2
|
require 'rails/generators/migration'
|
3
3
|
require 'rails/generators/active_record'
|
4
4
|
|
5
|
-
module
|
5
|
+
module Synchronisable
|
6
6
|
class InstallGenerator < Rails::Generators::Base
|
7
7
|
include Rails::Generators::Migration
|
8
8
|
|
@@ -14,7 +14,7 @@ module Synchronizable
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def create_initializer_file
|
17
|
-
copy_file 'initializer.rb', 'config/initializers/
|
17
|
+
copy_file 'initializer.rb', 'config/initializers/synchronisable.rb'
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.next_migration_number(dirname)
|
@@ -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 :
|
5
|
-
t.integer :
|
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, [:
|
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, [:
|
18
|
+
remove_index :imports, [:synchronisable_type, :synchronisable_id]
|
19
19
|
drop_table :imports
|
20
20
|
end
|
21
21
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
Synchronisable.configure do |config|
|
2
2
|
# Logging configuration
|
3
3
|
#
|
4
4
|
# config.logging = {
|
@@ -8,7 +8,7 @@ Synchronizable.configure do |config|
|
|
8
8
|
|
9
9
|
# If you want to restrict synchronized models.
|
10
10
|
# By default it will try to sync all models that have
|
11
|
-
# a `
|
11
|
+
# a `synchronisable` dsl instruction.
|
12
12
|
#
|
13
13
|
# config.models = %w(Foo Bar)
|
14
14
|
end
|
@@ -10,13 +10,13 @@ require 'active_support/concern'
|
|
10
10
|
|
11
11
|
require 'i18n'
|
12
12
|
|
13
|
-
require '
|
14
|
-
require '
|
15
|
-
require '
|
16
|
-
require '
|
13
|
+
require 'synchronisable/version'
|
14
|
+
require 'synchronisable/models/import'
|
15
|
+
require 'synchronisable/synchronizer'
|
16
|
+
require 'synchronisable/model'
|
17
17
|
|
18
18
|
locale_paths = File.join(File.dirname(__FILE__),
|
19
|
-
'
|
19
|
+
'synchronisable', 'locale', '*.yml')
|
20
20
|
|
21
21
|
Dir[locale_paths].each { |path| I18n.load_path << path }
|
22
22
|
I18n.backend.load_translations unless defined?(Rails)
|
@@ -41,7 +41,7 @@ I18n.available_locales = [:en, :ru]
|
|
41
41
|
# :match_players => :player
|
42
42
|
# })
|
43
43
|
|
44
|
-
module
|
44
|
+
module Synchronisable
|
45
45
|
include ActiveSupport::Configurable
|
46
46
|
|
47
47
|
config_accessor :models do
|
@@ -54,16 +54,16 @@ module Synchronizable
|
|
54
54
|
}
|
55
55
|
end
|
56
56
|
|
57
|
-
# Syncs models that is defined in {
|
57
|
+
# Syncs models that is defined in {Synchronisable#models}
|
58
58
|
#
|
59
59
|
# @param models [Array] array of models that should be synchronized.
|
60
|
-
# This take a precedence over models defined in {
|
61
|
-
# If this parameter is not specified and {
|
60
|
+
# This take a precedence over models defined in {Synchronisable#models}.
|
61
|
+
# If this parameter is not specified and {Synchronisable#models} is empty,
|
62
62
|
# than it will try to sync only those models which have a corresponding synchronizers.
|
63
63
|
#
|
64
|
-
# @return [Array<[
|
64
|
+
# @return [Array<[Synchronisable::Context]>] array of synchronization contexts
|
65
65
|
#
|
66
|
-
# @see
|
66
|
+
# @see Synchronisable::Context
|
67
67
|
def self.sync(*models)
|
68
68
|
source = source_models(models)
|
69
69
|
source.map(&:sync)
|
@@ -82,11 +82,11 @@ module Synchronizable
|
|
82
82
|
|
83
83
|
def self.find_models
|
84
84
|
ActiveRecord::Base.descendants.select do |model|
|
85
|
-
model.included_modules.include?(
|
85
|
+
model.included_modules.include?(Synchronisable::Model)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
ActiveSupport.on_load(:active_record) do
|
91
|
-
include
|
91
|
+
include Synchronisable::Model
|
92
92
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'synchronisable/dsl/associations/has_one'
|
2
|
+
require 'synchronisable/dsl/associations/has_many'
|
3
3
|
|
4
|
-
module
|
4
|
+
module Synchronisable
|
5
5
|
module DSL
|
6
6
|
module Associations
|
7
7
|
extend ActiveSupport::Concern
|
@@ -23,7 +23,7 @@ module Synchronizable
|
|
23
23
|
#
|
24
24
|
# @param attrs [Hash] local record attributes
|
25
25
|
#
|
26
|
-
# @return [Hash<
|
26
|
+
# @return [Hash<Synchronisable::Association, Array>] associations hash
|
27
27
|
#
|
28
28
|
# @raise [MissedAssocationsError] raised when the given
|
29
29
|
# attributes hash doesn't required associations
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'synchronisable/dsl/macro'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Synchronisable
|
4
4
|
module DSL
|
5
5
|
module Associations
|
6
6
|
# Association builder.
|
7
7
|
class Association
|
8
|
-
include
|
8
|
+
include Synchronisable::DSL::Macro
|
9
9
|
|
10
10
|
attribute :key_suffix, default: -> { raise NotImplementedError }
|
11
11
|
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'synchronisable/dsl/macro/method'
|
2
|
+
require 'synchronisable/dsl/macro/attribute'
|
3
3
|
|
4
|
-
module
|
4
|
+
module Synchronisable
|
5
5
|
module DSL
|
6
6
|
# Allows to define DSL-like attributes and methods.
|
7
7
|
# to be used in target class/module.
|
8
8
|
#
|
9
9
|
# @example Common use cases
|
10
10
|
# class Foo
|
11
|
-
# include
|
11
|
+
# include Synchronisable::DSL::Macro
|
12
12
|
#
|
13
13
|
# attribute :bar, default: 1
|
14
14
|
# attribute :blah, default: -> { bar * 2 }
|
@@ -32,10 +32,10 @@ module Synchronizable
|
|
32
32
|
#
|
33
33
|
# @api private
|
34
34
|
#
|
35
|
-
# @see
|
36
|
-
# @see
|
37
|
-
# @see
|
38
|
-
# @see
|
35
|
+
# @see Synchronisable::Synchronizer
|
36
|
+
# @see Synchronisable::DSL::Macro::Expression
|
37
|
+
# @see Synchronisable::DSL::Macro::Attribute
|
38
|
+
# @see Synchronisable::DSL::Macro::Method
|
39
39
|
module Macro
|
40
40
|
extend ActiveSupport::Concern
|
41
41
|
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require '
|
1
|
+
require 'synchronisable/dsl/macro/expression'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Synchronisable
|
4
4
|
module DSL
|
5
5
|
module Macro
|
6
6
|
# Expression for an attribute definition.
|
7
7
|
#
|
8
8
|
# @api private
|
9
9
|
#
|
10
|
-
# @see
|
11
|
-
# @see
|
10
|
+
# @see Synchronisable::DSL::Macro
|
11
|
+
# @see Synchronisable::DSL::Expression
|
12
12
|
class Attribute < Expression
|
13
13
|
def initialize(options)
|
14
14
|
@converter = options[:converter]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Synchronisable
|
2
2
|
module DSL
|
3
3
|
module Macro
|
4
4
|
# Serves as storage and provides lazy evaluation for expression.
|
@@ -7,9 +7,9 @@ module Synchronizable
|
|
7
7
|
#
|
8
8
|
# @api private
|
9
9
|
#
|
10
|
-
# @see
|
11
|
-
# @see
|
12
|
-
# @see
|
10
|
+
# @see Synchronisable::DSL::Macro
|
11
|
+
# @see Synchronisable::DSL::Attribute
|
12
|
+
# @see Synchronisable::DSL::Method
|
13
13
|
class Expression
|
14
14
|
attr_reader :source, :default
|
15
15
|
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require '
|
1
|
+
require 'synchronisable/dsl/macro/expression'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Synchronisable
|
4
4
|
module DSL
|
5
5
|
module Macro
|
6
6
|
# Expression for a method definition.
|
7
7
|
#
|
8
8
|
# @api private
|
9
9
|
#
|
10
|
-
# @see
|
11
|
-
# @see
|
10
|
+
# @see Synchronisable::DSL::Macro
|
11
|
+
# @see Synchronisable::DSL::Expression
|
12
12
|
class Method < Expression; end
|
13
13
|
end
|
14
14
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
module
|
1
|
+
module Synchronisable
|
2
2
|
# Helper class for synchronization errors handling.
|
3
3
|
#
|
4
|
-
# @see
|
4
|
+
# @see Synchronisable::Context
|
5
5
|
#
|
6
6
|
# @api private
|
7
7
|
class ErrorHandler
|
8
8
|
# @param logger [Logger] logger to used to log errors
|
9
|
-
# @param context [
|
9
|
+
# @param context [Synchronisable::Context] synchronization context
|
10
10
|
def initialize(logger, context)
|
11
11
|
@logger, @context = logger, context
|
12
12
|
end
|
@@ -14,7 +14,7 @@ module Synchronizable
|
|
14
14
|
# Wraps the given block in transaction.
|
15
15
|
# Rescued exceptions are written to log and saved to errors array.
|
16
16
|
#
|
17
|
-
# @param source [
|
17
|
+
# @param source [Synchronisable::Source] synchronization source
|
18
18
|
#
|
19
19
|
# @return [Boolean] `true` if syncronization was completed
|
20
20
|
# without errors, `false` otherwise
|
File without changes
|
File without changes
|
@@ -1,37 +1,37 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'synchronisable/model/methods'
|
2
|
+
require 'synchronisable/synchronizers/synchronizer_default'
|
3
3
|
|
4
|
-
module
|
4
|
+
module Synchronisable
|
5
5
|
module Model
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
module ClassMethods
|
9
9
|
SYNCHRONIZER_SUFFIX = 'Synchronizer'
|
10
10
|
|
11
|
-
# Declare this on your model class to make it
|
12
|
-
# After that you can call {
|
11
|
+
# Declare this on your model class to make it synchronisable.
|
12
|
+
# After that you can call {Synchronisable::Model::Methods#sync} to
|
13
13
|
# start model synchronization.
|
14
14
|
#
|
15
|
-
# @overload
|
15
|
+
# @overload synchronisable(klass, options)
|
16
16
|
# @param klass [Class] synchronizer class to be used
|
17
|
-
# @param options [Hash] describes behavior of
|
17
|
+
# @param options [Hash] describes behavior of synchronisable model
|
18
18
|
# @option options [Class] :synchronizer class that provides
|
19
19
|
# synchronization configuration
|
20
|
-
# @overload
|
21
|
-
# @overload
|
20
|
+
# @overload synchronisable(options)
|
21
|
+
# @overload synchronisable
|
22
22
|
#
|
23
|
-
# @see
|
24
|
-
# @see
|
23
|
+
# @see Synchronisable::Synchronizer
|
24
|
+
# @see Synchronisable::Model::Methods
|
25
25
|
#
|
26
26
|
# @example Common usage
|
27
27
|
# class FooModel < ActiveRecord::Base
|
28
|
-
#
|
28
|
+
# synchronisable BarSynchronizer
|
29
29
|
# end
|
30
|
-
def
|
31
|
-
extend
|
30
|
+
def synchronisable(*args)
|
31
|
+
extend Synchronisable::Model::Methods
|
32
32
|
|
33
33
|
class_attribute :synchronizer
|
34
|
-
has_one :import, as: :
|
34
|
+
has_one :import, as: :synchronisable
|
35
35
|
|
36
36
|
set_defaults(args)
|
37
37
|
end
|