capistrano-chewy 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc03aaa995d6e19dcf3628db3ee4ebe0ded4e093
4
- data.tar.gz: 6d4d0d9068d11e6c3b2443fdf8f3cdeec181ef75
3
+ metadata.gz: 7b6374523d9371bd4b852392ca60ee9cd55a4af6
4
+ data.tar.gz: d4823ef99f9c17c9ed9c3cc7037d4823b39914e7
5
5
  SHA512:
6
- metadata.gz: 66e508f1ee8d0c208bb70be8ab31bfadb579c01a7f4c1c8500beeb10e4d7ab8c073ce37afab9f453ca24555866ef6f360b4bedc2ff6e6197dc8cbc4742ec81b4
7
- data.tar.gz: dba7535113a333ad4b302cf41bd3e0e719976de73e4bcba9d63e49c94615afabfd0da9b2cbfca0094f0d47222fd72b05b515a0170b490ae02919f21c2a3d87ac
6
+ metadata.gz: b658bbbe5b8f28656bef50eddd9850fae492d82a82520b3071240ef9d369d736e016f9242272e3c9a0f781de4d56f000e18e4b3ffc32672919b86cd149d613d7
7
+ data.tar.gz: e39fda7430b47631c38f48880ad0caede6103ac825e718e48f457cece00f9fed7481c56a51d7a39b6e4ea42c4960993759ca730545ae7290f3468d52b10c6a36
data/README.md CHANGED
@@ -9,6 +9,7 @@ Moreover, it adds the possibility of manual index management with the base Chewy
9
9
 
10
10
  ## Requirements
11
11
 
12
+ * Ruby >= 1.9.3
12
13
  * Capistrano >= 3.0
13
14
  * Chewy >= 0.4
14
15
 
@@ -59,11 +60,11 @@ require 'capistrano/chewy'
59
60
  then you can use `cap -T` to list `Capistrano::Chewy` tasks:
60
61
 
61
62
  ```ruby
62
- cap deploy:chewy:rebuild # Reset only modified Chewy indexes
63
- cap deploy:chewy:reset # Destroy, recreate and import data to all the indexes
64
- cap deploy:chewy:reset[indexes] # Destroy, recreate and import data to the specified indexes
65
- cap deploy:chewy:update # Updates data to all the indexes
66
- cap deploy:chewy:update[indexes] # Updates data to the specified indexes
63
+ cap chewy:rebuild # Reset only modified Chewy indexes
64
+ cap chewy:reset # Destroy, recreate and import data to all the indexes
65
+ cap chewy:reset[indexes] # Destroy, recreate and import data to the specified indexes
66
+ cap chewy:update # Updates data to all the indexes
67
+ cap chewy:update[indexes] # Updates data to the specified indexes
67
68
  ```
68
69
 
69
70
  By default `Capistrano::Chewy` adds `deploy:chewy:rebuild` task after `deploy:updated` and `deploy:reverted`.
@@ -75,12 +76,12 @@ You can setup the following:
75
76
 
76
77
  ```ruby
77
78
  # deploy.rb
78
- set :chewy_conditionally_reset, false # Reset only modified Chewy indexes, true by default
79
- set :chewy_path, 'app/my_indexes' # Path to Chewy indexes, 'app/chewy' by default
80
- set :chewy_env, :chewy_production # Environment variable for Chewy, equal to RAILS_ENV by default
81
- set :chewy_role, :web # Chewy role, :app by default
82
- set :chewy_default_hooks, false # Add default capistrano-chewy hooks to your deploy flow, true by default
83
- set :chewy_delete_removed_indexes, false # Delete indexes which files have been deleted, true by default
79
+ set :chewy_conditionally_reset, false # Reset only modified Chewy indexes, true by default
80
+ set :chewy_path, 'app/my_indexes' # Path to Chewy indexes, 'app/chewy' by default
81
+ set :chewy_env, :chewy_production # Environment variable for Chewy, equal to RAILS_ENV by default
82
+ set :chewy_role, :web # Chewy role, :app by default
83
+ set :chewy_default_hooks, false # Add default capistrano-chewy hooks to your deploy flow, true by default
84
+ set :chewy_delete_removed_indexes, false # Delete indexes which files have been deleted, true by default
84
85
  ```
85
86
 
86
87
  ## Contributing
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # encoding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'capistrano-chewy/version'
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = 'capistrano-chewy'
8
8
  spec.version = CapistranoChewy.gem_version
9
9
  spec.authors = ['Nikita Bulai']
10
- spec.date = '2016-10-19'
10
+ spec.date = '2016-10-20'
11
11
  spec.email = ['bulajnikita@gmail.com']
12
12
  spec.summary = 'Manage and continuously rebuild your ElasticSearch indexes with Chewy and Capistrano'
13
13
  spec.description = 'Manage and continuously rebuild your ElasticSearch indexes with Chewy and Capistrano v3.'
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ['lib']
21
21
 
22
+ spec.required_ruby_version = '>= 1.9.3'
23
+
22
24
  spec.add_dependency 'capistrano', '~> 3.0'
23
25
  spec.add_dependency 'chewy', '~> 0.4'
24
26
 
@@ -6,7 +6,7 @@ module CapistranoChewy
6
6
  module VERSION
7
7
  MAJOR = 0
8
8
  MINOR = 2
9
- TINY = 0
9
+ TINY = 1
10
10
 
11
11
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
12
12
  end
@@ -11,130 +11,137 @@ end
11
11
 
12
12
  namespace :deploy do
13
13
  before :starting, :check_chewy_hooks do
14
- invoke :'deploy:chewy:add_default_hooks' if fetch(:chewy_default_hooks)
14
+ invoke :'chewy:add_default_hooks' if fetch(:chewy_default_hooks)
15
15
  end
16
+ end
17
+
18
+ namespace :chewy do
19
+ def delete_indexes(index_files)
20
+ index_classes = index_files.map { |file| File.basename(file, '.rb').camelize }.uniq
21
+ runner_code = "[#{index_classes.join(', ')}].each(&:delete)"
22
+
23
+ # Removed index files exists only in the old (current) release
24
+ within current_path do
25
+ with rails_env: fetch(:chewy_env) do
26
+ info "Removing indexes: #{index_classes.join(',')}"
27
+ execute :rails, "runner '#{runner_code}'"
28
+ end
29
+ end
30
+ end
31
+
32
+ def reset_modified_indexes(index_files)
33
+ index_names = index_files.map { |file| File.basename(file, '_index.rb') }.join(',')
16
34
 
17
- namespace :chewy do
18
- # Adds default Capistrano::Chewy hooks to the deploy flow
19
- task :add_default_hooks do
20
- after :'deploy:updated', 'deploy:chewy:rebuild'
21
- after :'deploy:reverted', 'deploy:chewy:rebuild'
35
+ within release_path do
36
+ with rails_env: fetch(:chewy_env) do
37
+ info "Modified or new indexes: #{index_names}"
38
+ execute :rake, "chewy:reset[#{index_names}]"
39
+ end
22
40
  end
41
+ end
42
+
43
+ # Adds default Capistrano::Chewy hooks to the deploy flow
44
+ task :add_default_hooks do
45
+ after :'deploy:updated', 'chewy:rebuild'
46
+ after :'deploy:reverted', 'chewy:rebuild'
47
+ end
23
48
 
24
- # Default Chewy rake tasks
25
- desc 'Destroy, recreate and import data to all or specified (pass with [one,two]) indexes'
26
- task :reset do |_task, args|
27
- indexes = args.extras
28
-
29
- on roles fetch(:chewy_role) do
30
- within release_path do
31
- with rails_env: fetch(:chewy_env) do
32
- if indexes.any?
33
- execute :rake, "chewy:reset[#{indexes.join(',')}]"
34
- else
35
- # Simply chewy:reset / chewy:update for Chewy > 0.8.4
36
- execute :rake, 'chewy:reset:all'
37
- end
49
+ # Default Chewy rake tasks
50
+ desc 'Destroy, recreate and import data to all or specified (pass with [one,two]) indexes'
51
+ task :reset do |_task, args|
52
+ indexes = args.extras
53
+
54
+ on roles fetch(:chewy_role) do
55
+ within release_path do
56
+ with rails_env: fetch(:chewy_env) do
57
+ if indexes.any?
58
+ execute :rake, "chewy:reset[#{indexes.join(',')}]"
59
+ else
60
+ # Simply chewy:reset / chewy:update for Chewy > 0.8.4
61
+ execute :rake, 'chewy:reset:all'
38
62
  end
39
63
  end
40
64
  end
41
65
  end
66
+ end
42
67
 
43
- desc 'Updates data to all or specified (passed with [one,two]) indexes'
44
- task :update do |_task, args|
45
- indexes = args.extras
46
-
47
- on roles fetch(:chewy_role) do
48
- within release_path do
49
- with rails_env: fetch(:chewy_env) do
50
- if indexes.any?
51
- execute :rake, "chewy:update[#{indexes.join(',')}]"
52
- else
53
- execute :rake, 'chewy:update:all'
54
- end
68
+ desc 'Updates data to all or specified (passed with [one,two]) indexes'
69
+ task :update do |_task, args|
70
+ indexes = args.extras
71
+
72
+ on roles fetch(:chewy_role) do
73
+ within release_path do
74
+ with rails_env: fetch(:chewy_env) do
75
+ if indexes.any?
76
+ execute :rake, "chewy:update[#{indexes.join(',')}]"
77
+ else
78
+ execute :rake, 'chewy:update:all'
55
79
  end
56
80
  end
57
81
  end
58
82
  end
83
+ end
59
84
 
60
- # Smart rebuild of modified Chewy indexes
61
- desc 'Reset Chewy indexes if they have been added, changed or removed'
62
- task :rebuild do
63
- on roles fetch(:chewy_role) do
64
- info "Checking Chewy directory (#{fetch(:chewy_path)})"
85
+ # Smart rebuild of modified Chewy indexes
86
+ desc 'Reset Chewy indexes if they have been added, changed or removed'
87
+ task :rebuild do
88
+ on roles fetch(:chewy_role) do
89
+ info "Checking Chewy directory (#{fetch(:chewy_path)})"
65
90
 
66
- chewy_path = File.join(release_path, fetch(:chewy_path))
67
- unless test("[ -d #{chewy_path} ]")
68
- error "Directory #{chewy_path} doesn't exist!"
69
- exit 1
70
- end
91
+ chewy_path = File.join(release_path, fetch(:chewy_path))
92
+ unless test("[ -d #{chewy_path} ]")
93
+ error "Directory #{chewy_path} doesn't exist!"
94
+ exit 1
95
+ end
71
96
 
72
- if fetch(:chewy_conditionally_reset)
73
- if test('diff -v')
74
- info 'Running smart indexes reset...'
75
- invoke :'deploy:chewy:rebuilding'
76
- else
77
- error "Can't check the difference between Chewy indexes - install 'diff' tool first!"
78
- exit 1
79
- end
97
+ if fetch(:chewy_conditionally_reset)
98
+ if test('diff -v')
99
+ info 'Running smart indexes reset...'
100
+ invoke :'chewy:rebuilding'
80
101
  else
81
- info 'Running chewy:reset:all'
82
- invoke :'deploy:chewy:reset:all'
102
+ error "Can't check the difference between Chewy indexes - install 'diff' tool first!"
103
+ exit 1
83
104
  end
105
+ else
106
+ info 'Running chewy:reset:all'
107
+ invoke :'chewy:reset:all'
84
108
  end
85
109
  end
110
+ end
86
111
 
87
- desc 'Runs smart Chewy indexes rebuilding (only for changed files)'
88
- task :rebuilding do
89
- on roles fetch(:chewy_role) do
90
- chewy_path = fetch(:chewy_path)
91
- info "Checking changes in #{chewy_path}"
92
-
93
- chewy_release_path = File.join(release_path, chewy_path)
94
- chewy_current_path = File.join(current_path, chewy_path)
95
-
96
- # -q, --brief report only when files differ
97
- # -E, --ignore-tab-expansion ignore changes due to tab expansion
98
- # -Z, --ignore-trailing-space ignore white space at line end
99
- # -B, --ignore-blank-lines ignore changes where lines are all blank
100
- #
101
- diff_args = "-qZEB #{chewy_release_path} #{chewy_current_path}"
102
- indexes_diff = capture :diff, diff_args, raise_on_non_zero_exit: false
103
- changes = ::CapistranoChewy::DiffParser.parse(indexes_diff, chewy_current_path, chewy_release_path)
104
-
105
- # If diff is empty then indices have not changed
106
- if changes.empty?
107
- info 'Skipping `deploy:chewy:rebuilding` (nothing changed in the Chewy path)'
108
- exit 0
109
- else
110
- indexes_to_reset = changes.changed.concat(changes.added)
111
- indexes_to_delete = changes.removed
112
-
113
- # Reset indexes which have been modified or added
114
- if indexes_to_reset.any?
115
- indexes = indexes_to_reset.map { |file| File.basename(file, '_index.rb') }.join(',')
116
-
117
- within release_path do
118
- with rails_env: fetch(:chewy_env) do
119
- info "Modified or new indexes: #{indexes}"
120
- execute :rake, "chewy:reset[#{indexes}]"
121
- end
122
- end
123
- end
112
+ desc 'Runs smart Chewy indexes rebuilding (only for changed files)'
113
+ task :rebuilding do
114
+ on roles fetch(:chewy_role) do
115
+ chewy_path = fetch(:chewy_path)
116
+ info "Checking changes in #{chewy_path}"
117
+
118
+ chewy_release_path = File.join(release_path, chewy_path)
119
+ chewy_current_path = File.join(current_path, chewy_path)
120
+
121
+ # -q, --brief report only when files differ
122
+ # -E, --ignore-tab-expansion ignore changes due to tab expansion
123
+ # -Z, --ignore-trailing-space ignore white space at line end
124
+ # -B, --ignore-blank-lines ignore changes where lines are all blank
125
+ #
126
+ diff_args = "-qZEB #{chewy_release_path} #{chewy_current_path}"
127
+ indexes_diff = capture :diff, diff_args, raise_on_non_zero_exit: false
128
+ changes = ::CapistranoChewy::DiffParser.parse(indexes_diff, chewy_current_path, chewy_release_path)
129
+
130
+ # If diff is empty then indices have not changed
131
+ if changes.empty?
132
+ info 'Skipping `chewy:rebuilding` (nothing changed in the Chewy path)'
133
+ else
134
+ indexes_to_reset = changes.changed.concat(changes.added)
135
+ indexes_to_delete = changes.removed
136
+
137
+ # Reset indexes which have been modified or added
138
+ if indexes_to_reset.any?
139
+ reset_modified_indexes(indexes_to_reset)
140
+ end
124
141
 
125
- # Delete indexes which have been removed
126
- if indexes_to_delete.any? && fetch(:chewy_delete_removed_indexes)
127
- indexes = indexes_to_delete.map { |file| File.basename(file, '.rb').camelize }.uniq
128
- runner_code = "[#{indexes.join(', ')}].each(&:delete)"
129
-
130
- # Removed index files exists only in the old (current) release
131
- within current_path do
132
- with rails_env: fetch(:chewy_env) do
133
- info "Removing indexes: #{indexes.join(',')}"
134
- execute :rails, "runner '#{runner_code}'"
135
- end
136
- end
137
- end
142
+ # Delete indexes which have been removed
143
+ if indexes_to_delete.any? && fetch(:chewy_delete_removed_indexes)
144
+ delete_indexes(indexes_to_delete)
138
145
  end
139
146
  end
140
147
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-chewy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Bulai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-19 00:00:00.000000000 Z
11
+ date: 2016-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -88,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - ">="
90
90
  - !ruby/object:Gem::Version
91
- version: '0'
91
+ version: 1.9.3
92
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="