chewy 0.8.4 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +34 -0
- data/.rubocop_todo.yml +44 -0
- data/.travis.yml +20 -60
- data/Appraisals +15 -40
- data/CHANGELOG.md +42 -0
- data/Gemfile +1 -0
- data/Guardfile +5 -5
- data/README.md +155 -6
- data/Rakefile +11 -1
- data/chewy.gemspec +5 -7
- data/gemfiles/rails.3.2.activerecord.gemfile +1 -0
- data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +1 -0
- data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +1 -0
- data/gemfiles/{rails.4.2.mongoid.4.0.0.gemfile → rails.4.2.mongoid.4.0.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.4.0.0.kaminari.gemfile → rails.4.2.mongoid.4.0.kaminari.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.4.0.0.will_paginate.gemfile → rails.4.2.mongoid.4.0.will_paginate.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.gemfile → rails.4.2.mongoid.5.1.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.kaminari.gemfile → rails.4.2.mongoid.5.1.kaminari.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.will_paginate.gemfile → rails.4.2.mongoid.5.1.will_paginate.gemfile} +2 -1
- data/gemfiles/{rails.4.0.activerecord.gemfile → rails.5.0.activerecord.gemfile} +4 -2
- data/gemfiles/{rails.4.0.mongoid.4.0.0.kaminari.gemfile → rails.5.0.activerecord.kaminari.gemfile} +4 -2
- data/gemfiles/{rails.4.0.mongoid.4.0.0.will_paginate.gemfile → rails.5.0.activerecord.will_paginate.gemfile} +4 -2
- data/gemfiles/{sequel.4.31.gemfile → sequel.4.38.gemfile} +3 -2
- data/lib/chewy.rb +24 -16
- data/lib/chewy/backports/deep_dup.rb +1 -1
- data/lib/chewy/backports/duplicable.rb +1 -0
- data/lib/chewy/config.rb +13 -7
- data/lib/chewy/errors.rb +4 -4
- data/lib/chewy/fields/base.rb +19 -14
- data/lib/chewy/fields/root.rb +11 -9
- data/lib/chewy/index.rb +38 -25
- data/lib/chewy/index/actions.rb +17 -17
- data/lib/chewy/index/settings.rb +3 -4
- data/lib/chewy/journal.rb +107 -0
- data/lib/chewy/journal/apply.rb +31 -0
- data/lib/chewy/journal/clean.rb +24 -0
- data/lib/chewy/journal/entry.rb +83 -0
- data/lib/chewy/journal/query.rb +87 -0
- data/lib/chewy/log_subscriber.rb +8 -8
- data/lib/chewy/minitest.rb +1 -0
- data/lib/chewy/minitest/helpers.rb +77 -0
- data/lib/chewy/minitest/search_index_receiver.rb +80 -0
- data/lib/chewy/query.rb +116 -60
- data/lib/chewy/query/compose.rb +5 -6
- data/lib/chewy/query/criteria.rb +26 -16
- data/lib/chewy/query/filters.rb +9 -9
- data/lib/chewy/query/loading.rb +2 -2
- data/lib/chewy/query/nodes/and.rb +3 -3
- data/lib/chewy/query/nodes/base.rb +1 -1
- data/lib/chewy/query/nodes/bool.rb +6 -4
- data/lib/chewy/query/nodes/equal.rb +6 -6
- data/lib/chewy/query/nodes/exists.rb +2 -2
- data/lib/chewy/query/nodes/expr.rb +2 -2
- data/lib/chewy/query/nodes/field.rb +35 -31
- data/lib/chewy/query/nodes/has_child.rb +1 -0
- data/lib/chewy/query/nodes/has_parent.rb +1 -0
- data/lib/chewy/query/nodes/has_relation.rb +11 -13
- data/lib/chewy/query/nodes/match_all.rb +1 -1
- data/lib/chewy/query/nodes/missing.rb +2 -2
- data/lib/chewy/query/nodes/not.rb +3 -3
- data/lib/chewy/query/nodes/or.rb +3 -3
- data/lib/chewy/query/nodes/prefix.rb +4 -3
- data/lib/chewy/query/nodes/query.rb +3 -3
- data/lib/chewy/query/nodes/range.rb +11 -11
- data/lib/chewy/query/nodes/raw.rb +1 -1
- data/lib/chewy/query/nodes/regexp.rb +15 -11
- data/lib/chewy/query/nodes/script.rb +6 -6
- data/lib/chewy/query/pagination/will_paginate.rb +2 -2
- data/lib/chewy/railtie.rb +3 -3
- data/lib/chewy/rake_helper.rb +51 -30
- data/lib/chewy/repository.rb +2 -2
- data/lib/chewy/rspec.rb +1 -1
- data/lib/chewy/rspec/update_index.rb +46 -47
- data/lib/chewy/runtime/version.rb +4 -4
- data/lib/chewy/search.rb +7 -5
- data/lib/chewy/strategy.rb +10 -8
- data/lib/chewy/strategy/atomic.rb +2 -2
- data/lib/chewy/strategy/base.rb +4 -4
- data/lib/chewy/strategy/bypass.rb +1 -2
- data/lib/chewy/strategy/sidekiq.rb +2 -0
- data/lib/chewy/strategy/urgent.rb +1 -1
- data/lib/chewy/type.rb +51 -45
- data/lib/chewy/type/adapter/active_record.rb +23 -12
- data/lib/chewy/type/adapter/base.rb +4 -4
- data/lib/chewy/type/adapter/mongoid.rb +6 -6
- data/lib/chewy/type/adapter/object.rb +15 -12
- data/lib/chewy/type/adapter/orm.rb +24 -15
- data/lib/chewy/type/adapter/sequel.rb +11 -7
- data/lib/chewy/type/crutch.rb +4 -3
- data/lib/chewy/type/import.rb +51 -32
- data/lib/chewy/type/mapping.rb +17 -17
- data/lib/chewy/type/observe.rb +9 -7
- data/lib/chewy/type/witchcraft.rb +62 -23
- data/lib/chewy/type/wrapper.rb +20 -14
- data/lib/chewy/version.rb +1 -1
- data/lib/generators/chewy/install_generator.rb +3 -3
- data/lib/tasks/chewy.rake +28 -23
- data/spec/chewy/config_spec.rb +33 -12
- data/spec/chewy/fields/base_spec.rb +143 -154
- data/spec/chewy/fields/root_spec.rb +22 -20
- data/spec/chewy/fields/time_fields_spec.rb +11 -9
- data/spec/chewy/index/actions_spec.rb +27 -4
- data/spec/chewy/index/aliases_spec.rb +2 -2
- data/spec/chewy/index/settings_spec.rb +72 -50
- data/spec/chewy/index_spec.rb +95 -43
- data/spec/chewy/journal/apply_spec.rb +120 -0
- data/spec/chewy/journal/entry_spec.rb +237 -0
- data/spec/chewy/journal_spec.rb +173 -0
- data/spec/chewy/minitest/helpers_spec.rb +90 -0
- data/spec/chewy/minitest/search_index_receiver_spec.rb +120 -0
- data/spec/chewy/query/criteria_spec.rb +504 -237
- data/spec/chewy/query/filters_spec.rb +94 -66
- data/spec/chewy/query/loading_spec.rb +76 -40
- data/spec/chewy/query/nodes/and_spec.rb +3 -7
- data/spec/chewy/query/nodes/bool_spec.rb +5 -13
- data/spec/chewy/query/nodes/equal_spec.rb +20 -20
- data/spec/chewy/query/nodes/exists_spec.rb +7 -7
- data/spec/chewy/query/nodes/has_child_spec.rb +42 -23
- data/spec/chewy/query/nodes/has_parent_spec.rb +42 -23
- data/spec/chewy/query/nodes/match_all_spec.rb +2 -2
- data/spec/chewy/query/nodes/missing_spec.rb +6 -5
- data/spec/chewy/query/nodes/not_spec.rb +3 -7
- data/spec/chewy/query/nodes/or_spec.rb +3 -7
- data/spec/chewy/query/nodes/prefix_spec.rb +6 -6
- data/spec/chewy/query/nodes/query_spec.rb +3 -3
- data/spec/chewy/query/nodes/range_spec.rb +19 -19
- data/spec/chewy/query/nodes/raw_spec.rb +2 -2
- data/spec/chewy/query/nodes/regexp_spec.rb +31 -19
- data/spec/chewy/query/nodes/script_spec.rb +5 -5
- data/spec/chewy/query/pagination/kaminari_spec.rb +2 -2
- data/spec/chewy/query/pagination/will_paginage_spec.rb +6 -7
- data/spec/chewy/query/pagination_spec.rb +2 -3
- data/spec/chewy/query_spec.rb +208 -145
- data/spec/chewy/repository_spec.rb +8 -8
- data/spec/chewy/rspec/update_index_spec.rb +180 -111
- data/spec/chewy/search_spec.rb +8 -8
- data/spec/chewy/strategy/active_job_spec.rb +2 -2
- data/spec/chewy/strategy/atomic_spec.rb +4 -1
- data/spec/chewy/strategy/resque_spec.rb +2 -2
- data/spec/chewy/strategy/sidekiq_spec.rb +2 -2
- data/spec/chewy/type/actions_spec.rb +1 -1
- data/spec/chewy/type/adapter/active_record_spec.rb +255 -149
- data/spec/chewy/type/adapter/mongoid_spec.rb +169 -108
- data/spec/chewy/type/adapter/object_spec.rb +56 -40
- data/spec/chewy/type/adapter/sequel_spec.rb +248 -163
- data/spec/chewy/type/import_spec.rb +78 -47
- data/spec/chewy/type/mapping_spec.rb +6 -6
- data/spec/chewy/type/observe_spec.rb +20 -14
- data/spec/chewy/type/witchcraft_spec.rb +89 -43
- data/spec/chewy/type_spec.rb +4 -3
- data/spec/chewy_spec.rb +10 -8
- data/spec/spec_helper.rb +3 -0
- data/spec/support/active_record.rb +1 -1
- data/spec/support/class_helpers.rb +10 -11
- data/spec/support/mongoid.rb +2 -2
- data/spec/support/sequel.rb +1 -1
- metadata +65 -35
- data/gemfiles/rails.4.0.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.0.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.0.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.1.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.1.mongoid.4.0.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.4.0.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.1.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.5.0.0.beta3.activerecord.gemfile +0 -16
- data/gemfiles/rails.5.0.0.beta3.activerecord.kaminari.gemfile +0 -16
- data/gemfiles/rails.5.0.0.beta3.activerecord.will_paginate.gemfile +0 -15
data/lib/chewy/type/mapping.rb
CHANGED
@@ -31,8 +31,8 @@ module Chewy
|
|
31
31
|
# end
|
32
32
|
# end
|
33
33
|
#
|
34
|
-
def root
|
35
|
-
raise
|
34
|
+
def root(options = {}, &block)
|
35
|
+
raise 'Root is already defined' if root_object
|
36
36
|
build_root(options, &block)
|
37
37
|
end
|
38
38
|
|
@@ -96,7 +96,7 @@ module Chewy
|
|
96
96
|
# field :en, value: ->(name) { name['en'] }
|
97
97
|
# end
|
98
98
|
#
|
99
|
-
#
|
99
|
+
# Of course it is possible to define object fields contents dynamically
|
100
100
|
# but make sure evaluation proc returns hash:
|
101
101
|
#
|
102
102
|
# field :name, type: 'object', value: -> { name_translations }
|
@@ -109,7 +109,7 @@ module Chewy
|
|
109
109
|
# field :sorted, analyzer: 'sorted'
|
110
110
|
# end
|
111
111
|
#
|
112
|
-
def field
|
112
|
+
def field(*args, &block)
|
113
113
|
options = args.extract_options!
|
114
114
|
build_root
|
115
115
|
|
@@ -136,10 +136,9 @@ module Chewy
|
|
136
136
|
# end
|
137
137
|
# end
|
138
138
|
# end
|
139
|
-
def agg
|
140
|
-
options = args.extract_options!
|
139
|
+
def agg(name, &block)
|
141
140
|
build_root
|
142
|
-
self._agg_defs = _agg_defs.merge(
|
141
|
+
self._agg_defs = _agg_defs.merge(name => block)
|
143
142
|
end
|
144
143
|
alias_method :aggregation, :agg
|
145
144
|
|
@@ -148,7 +147,7 @@ module Chewy
|
|
148
147
|
# class CarsIndex < Chewy::Index
|
149
148
|
# define_type Car do
|
150
149
|
# template 'model.*', type: 'string', analyzer: 'special'
|
151
|
-
# field 'model', type: 'object' # here we can put {
|
150
|
+
# field 'model', type: 'object' # here we can put { de: 'Der Mercedes', en: 'Mercedes' }
|
152
151
|
# # and template will be applyed to this field
|
153
152
|
# end
|
154
153
|
# end
|
@@ -163,8 +162,8 @@ module Chewy
|
|
163
162
|
# template /tit.+/, 'string', mapping_hash # "match_mapping_type" as the optionsl second argument
|
164
163
|
# template template42: {match: 'hello*', mapping: {type: 'object'}} # or even pass a template as is
|
165
164
|
#
|
166
|
-
def template
|
167
|
-
build_root.dynamic_template
|
165
|
+
def template(*args)
|
166
|
+
build_root.dynamic_template(*args)
|
168
167
|
end
|
169
168
|
alias_method :dynamic_template, :template
|
170
169
|
|
@@ -176,20 +175,21 @@ module Chewy
|
|
176
175
|
|
177
176
|
private
|
178
177
|
|
179
|
-
def expand_nested
|
178
|
+
def expand_nested(field, &block)
|
180
179
|
if @_current_field
|
181
180
|
field.parent = @_current_field
|
182
181
|
@_current_field.children.push(field)
|
183
182
|
end
|
184
183
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
184
|
+
return unless block
|
185
|
+
|
186
|
+
previous_field = @_current_field
|
187
|
+
@_current_field = field
|
188
|
+
yield
|
189
|
+
@_current_field = previous_field
|
190
190
|
end
|
191
191
|
|
192
|
-
def build_root
|
192
|
+
def build_root(options = {}, &block)
|
193
193
|
return root_object if root_object
|
194
194
|
self.root_object = Chewy::Fields::Root.new(type_name, options)
|
195
195
|
expand_nested(root_object, &block)
|
data/lib/chewy/type/observe.rb
CHANGED
@@ -8,7 +8,7 @@ module Chewy
|
|
8
8
|
options = args.extract_options!
|
9
9
|
method = args.first
|
10
10
|
|
11
|
-
|
11
|
+
proc do
|
12
12
|
backreference = if method && method.to_s == 'self'
|
13
13
|
self
|
14
14
|
elsif method
|
@@ -18,9 +18,11 @@ module Chewy
|
|
18
18
|
end
|
19
19
|
|
20
20
|
reference = if type_name.is_a?(Proc)
|
21
|
-
type_name.arity
|
22
|
-
instance_exec(&type_name)
|
21
|
+
if type_name.arity.zero?
|
22
|
+
instance_exec(&type_name)
|
23
|
+
else
|
23
24
|
type_name.call(self)
|
25
|
+
end
|
24
26
|
else
|
25
27
|
type_name
|
26
28
|
end
|
@@ -31,11 +33,11 @@ module Chewy
|
|
31
33
|
|
32
34
|
def extract_callback_options!(args)
|
33
35
|
options = args.extract_options!
|
34
|
-
options.each_key.with_object({})
|
36
|
+
result = options.each_key.with_object({}) do |key, hash|
|
35
37
|
hash[key] = options.delete(key) if [:if, :unless].include?(key)
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
end
|
39
|
+
args.push(options) unless options.empty?
|
40
|
+
result
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
@@ -1,10 +1,11 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
begin
|
2
|
+
require 'method_source'
|
3
|
+
require 'parser/current'
|
4
|
+
require 'unparser'
|
3
5
|
rescue LoadError
|
6
|
+
nil
|
4
7
|
end
|
5
8
|
|
6
|
-
%w[method_source parser/current unparser].each { |lib| try_require lib }
|
7
|
-
|
8
9
|
module Chewy
|
9
10
|
class Type
|
10
11
|
module Witchcraft
|
@@ -22,9 +23,9 @@ module Chewy
|
|
22
23
|
|
23
24
|
def check_requirements!
|
24
25
|
messages = []
|
25
|
-
messages << "MethodSource gem is required for the Witchcraft
|
26
|
-
messages << "Parser gem is required for the Witchcraft
|
27
|
-
messages << "Unparser gem is required for the Witchcraft
|
26
|
+
messages << "MethodSource gem is required for the Witchcraft, please add `gem 'method_source'` to your Gemfile" unless Proc.method_defined?(:source)
|
27
|
+
messages << "Parser gem is required for the Witchcraft, please add `gem 'parser'` to your Gemfile" unless '::Parser'.safe_constantize
|
28
|
+
messages << "Unparser gem is required for the Witchcraft, please add `gem 'unparser'` to your Gemfile" unless '::Unparser'.safe_constantize
|
28
29
|
messages = messages.join("\n")
|
29
30
|
|
30
31
|
raise messages if messages.present?
|
@@ -40,19 +41,22 @@ module Chewy
|
|
40
41
|
end
|
41
42
|
|
42
43
|
class Cauldron
|
44
|
+
attr_reader :locals
|
45
|
+
|
43
46
|
def initialize(type)
|
44
47
|
@type = type
|
48
|
+
@locals = []
|
45
49
|
end
|
46
50
|
|
47
51
|
def brew(object, crutches = nil)
|
48
|
-
alicorn.call(object, crutches).as_json
|
52
|
+
alicorn.call(locals, object, crutches).as_json
|
49
53
|
end
|
50
54
|
|
51
55
|
private
|
52
56
|
|
53
57
|
def alicorn
|
54
58
|
@alicorn ||= class_eval <<-RUBY
|
55
|
-
-> (object0, crutches) do
|
59
|
+
-> (locals, object0, crutches) do
|
56
60
|
#{composed_values(@type.root_object, 0)}
|
57
61
|
end
|
58
62
|
RUBY
|
@@ -94,21 +98,21 @@ module Chewy
|
|
94
98
|
<<-RUBY
|
95
99
|
(if #{object}.is_a?(Hash)
|
96
100
|
{
|
97
|
-
#{non_proc_fields.map do |
|
98
|
-
fetcher = "#{object}.has_key?(:#{
|
99
|
-
"#{
|
101
|
+
#{non_proc_fields.map do |f|
|
102
|
+
fetcher = "#{object}.has_key?(:#{f.name}) ? #{object}[:#{f.name}] : #{object}['#{f.name}']"
|
103
|
+
"#{f.name}: #{composed_value(f, fetcher, nesting)}"
|
100
104
|
end.join(', ')}
|
101
105
|
}
|
102
106
|
else
|
103
107
|
{
|
104
|
-
#{non_proc_fields.map do |
|
105
|
-
"#{
|
108
|
+
#{non_proc_fields.map do |f|
|
109
|
+
"#{f.name}: #{composed_value(f, "#{object}.#{f.name}", nesting)}"
|
106
110
|
end.join(', ')}
|
107
111
|
}
|
108
112
|
end)
|
109
113
|
RUBY
|
110
114
|
else
|
111
|
-
|
115
|
+
'{}'
|
112
116
|
end
|
113
117
|
end
|
114
118
|
|
@@ -118,13 +122,13 @@ module Chewy
|
|
118
122
|
if proc_fields.present?
|
119
123
|
<<-RUBY
|
120
124
|
{
|
121
|
-
#{proc_fields.map do |
|
122
|
-
"#{
|
125
|
+
#{proc_fields.map do |f|
|
126
|
+
"#{f.name}: (#{composed_value(f, source_for(f.value, nesting), nesting)})"
|
123
127
|
end.join(', ')}
|
124
128
|
}
|
125
129
|
RUBY
|
126
130
|
else
|
127
|
-
|
131
|
+
'{}'
|
128
132
|
end
|
129
133
|
end
|
130
134
|
|
@@ -145,26 +149,36 @@ module Chewy
|
|
145
149
|
raise "No lambdas found, try to reformat your code:\n`#{proc.source}`" unless lambdas
|
146
150
|
|
147
151
|
source = lambdas.first
|
148
|
-
|
152
|
+
proc_params = proc.parameters.map(&:second)
|
153
|
+
|
154
|
+
if proc.arity.zero?
|
149
155
|
source = replace_self(source, :"object#{nesting}")
|
150
156
|
source = replace_send(source, :"object#{nesting}")
|
151
157
|
elsif proc.arity < 0
|
152
158
|
raise "Splat arguments are unsupported by witchcraft:\n`#{proc.source}"
|
153
159
|
else
|
154
160
|
(nesting + 1).times do |n|
|
155
|
-
source = replace_lvar(source,
|
161
|
+
source = replace_lvar(source, proc_params[n], :"object#{n}") if proc_params[n]
|
162
|
+
end
|
163
|
+
source = replace_lvar(source, proc_params[nesting + 1], :crutches) if proc_params[nesting + 1]
|
164
|
+
|
165
|
+
binding_variable_list(source).each do |variable|
|
166
|
+
locals.push(proc.binding.eval(variable.to_s))
|
167
|
+
source = replace_local(source, variable, locals.size - 1)
|
156
168
|
end
|
157
|
-
|
169
|
+
|
158
170
|
end
|
171
|
+
|
159
172
|
Unparser.unparse(source)
|
160
173
|
end
|
161
174
|
|
162
175
|
def exctract_lambdas(node)
|
176
|
+
return unless node.is_a?(Parser::AST::Node)
|
163
177
|
if node.type == :block && node.children[0].type == :send && node.children[0].to_a == [nil, :lambda]
|
164
|
-
node.children[2]
|
178
|
+
[node.children[2]]
|
165
179
|
else
|
166
180
|
node.children.map { |child| exctract_lambdas(child) }.flatten.compact
|
167
|
-
end
|
181
|
+
end
|
168
182
|
end
|
169
183
|
|
170
184
|
def replace_lvar(node, old_variable, new_variable)
|
@@ -202,6 +216,31 @@ module Chewy
|
|
202
216
|
node
|
203
217
|
end
|
204
218
|
end
|
219
|
+
|
220
|
+
def replace_local(node, variable, local_index)
|
221
|
+
if node.is_a?(Parser::AST::Node)
|
222
|
+
if node.type == :send && node.children.to_a == [nil, variable]
|
223
|
+
node.updated(nil, [
|
224
|
+
Parser::AST::Node.new(:lvar, [:locals]),
|
225
|
+
:[],
|
226
|
+
Parser::AST::Node.new(:int, [local_index])
|
227
|
+
])
|
228
|
+
else
|
229
|
+
node.updated(nil, node.children.map { |child| replace_local(child, variable, local_index) })
|
230
|
+
end
|
231
|
+
else
|
232
|
+
node
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def binding_variable_list(node)
|
237
|
+
return unless node.is_a?(Parser::AST::Node)
|
238
|
+
if node.type == :send && node.children[0].nil?
|
239
|
+
node.children[1]
|
240
|
+
else
|
241
|
+
node.children.map { |child| binding_variable_list(child) }.flatten.compact.uniq
|
242
|
+
end
|
243
|
+
end
|
205
244
|
end
|
206
245
|
end
|
207
246
|
end
|
data/lib/chewy/type/wrapper.rb
CHANGED
@@ -19,34 +19,40 @@ module Chewy
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def method_missing(
|
23
|
-
|
24
|
-
|
22
|
+
def method_missing(method, *args, &block)
|
23
|
+
m = method.to_s
|
24
|
+
if (name = highlight_name(m))
|
25
|
+
highlight(name)
|
26
|
+
elsif @attributes.key?(m)
|
27
|
+
@attributes[m]
|
28
|
+
elsif attribute_defined?(m)
|
29
|
+
nil
|
30
|
+
else
|
31
|
+
super
|
25
32
|
end
|
26
|
-
return @attributes[method_name.to_s] if @attributes.key?(method_name.to_s)
|
27
|
-
return nil if attribute_defined?(method_name.to_s)
|
28
|
-
super
|
29
33
|
end
|
30
34
|
|
31
|
-
def respond_to_missing?(
|
32
|
-
|
33
|
-
|
34
|
-
attribute_defined?(method_name.to_s) ||
|
35
|
-
super
|
35
|
+
def respond_to_missing?(method, include_private = false)
|
36
|
+
m = method.to_s
|
37
|
+
highlight_name(m) || @attributes.key?(m) || attribute_defined?(m) || super
|
36
38
|
end
|
37
39
|
|
38
|
-
|
40
|
+
private
|
41
|
+
|
42
|
+
def highlight_name(method)
|
43
|
+
method.sub(/_highlight\z/, '') if method.end_with?('_highlight')
|
44
|
+
end
|
39
45
|
|
40
46
|
def attribute_defined?(attribute)
|
41
47
|
self.class.root_object && self.class.root_object.children.find { |a| a.name.to_s == attribute }.present?
|
42
48
|
end
|
43
49
|
|
44
50
|
def highlight(attribute)
|
45
|
-
_data[
|
51
|
+
_data['highlight'][attribute].first
|
46
52
|
end
|
47
53
|
|
48
54
|
def highlight?(attribute)
|
49
|
-
_data.key?(
|
55
|
+
_data.key?('highlight') && _data['highlight'].key?(attribute)
|
50
56
|
end
|
51
57
|
end
|
52
58
|
end
|
data/lib/chewy/version.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Chewy
|
2
2
|
module Generators
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
4
|
-
source_root File.expand_path(
|
4
|
+
source_root File.expand_path('../../templates', __FILE__)
|
5
5
|
|
6
6
|
def copy_configuration
|
7
|
-
template
|
7
|
+
template 'chewy.yml', 'config/chewy.yml'
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
data/lib/tasks/chewy.rake
CHANGED
@@ -2,48 +2,53 @@ require 'chewy/rake_helper'
|
|
2
2
|
|
3
3
|
namespace :chewy do
|
4
4
|
desc 'Destroy, recreate and import data to specified index'
|
5
|
-
task
|
5
|
+
task reset: :environment do |_task, args|
|
6
6
|
Chewy::RakeHelper.subscribed_task_stats do
|
7
|
+
indexes = args.extras
|
7
8
|
|
8
|
-
if
|
9
|
-
Chewy::RakeHelper.
|
9
|
+
if indexes.empty? || indexes.first.tr!('-', '')
|
10
|
+
Chewy::RakeHelper.reset_all(indexes)
|
10
11
|
else
|
11
|
-
Chewy::RakeHelper.
|
12
|
+
Chewy::RakeHelper.reset_index(indexes)
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
desc 'Updates data specified index'
|
18
|
+
task update: :environment do |_task, args|
|
19
|
+
Chewy::RakeHelper.subscribed_task_stats do
|
20
|
+
indexes = args.extras
|
20
21
|
|
21
|
-
|
22
|
-
Chewy::RakeHelper.
|
22
|
+
if indexes.empty? || indexes.first.tr!('-', '')
|
23
|
+
Chewy::RakeHelper.update_all(indexes)
|
24
|
+
else
|
25
|
+
Chewy::RakeHelper.update_index(indexes)
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
|
-
desc '
|
28
|
-
task :
|
30
|
+
desc 'Applies changes that were done from specified moment (as a timestamp)'
|
31
|
+
task apply_changes_from: :environment do |_task, args|
|
29
32
|
Chewy::RakeHelper.subscribed_task_stats do
|
33
|
+
params = args.extras
|
30
34
|
|
31
|
-
if
|
32
|
-
|
35
|
+
if params.empty?
|
36
|
+
puts 'Please specify a timestamp like chewy:apply_changes_from[1469528705]'
|
33
37
|
else
|
34
|
-
|
38
|
+
timestamp, retries = params
|
39
|
+
time = Time.at(timestamp.to_i)
|
40
|
+
Chewy::Journal::Apply.since(time, retries: (retries.to_i if retries))
|
35
41
|
end
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
45
|
+
desc 'Cleans journal index. It accepts timestamp until which journal will be cleaned'
|
46
|
+
task clean_journal: :environment do |_task, args|
|
47
|
+
timestamp = args.extras.first
|
48
|
+
if timestamp
|
49
|
+
Chewy::Journal::Clean.until(Time.at(timestamp.to_i))
|
50
|
+
else
|
51
|
+
Chewy::Journal.delete!
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|