elasticsearch-rails-dynamic-json-support 0.0.5 → 0.0.6

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: e92105a25788097c08f205783d49a2ca4ffc488d
4
- data.tar.gz: 27ad97de60bfef4b595e836913799ebf5eba7592
3
+ metadata.gz: 566cc9fe9bf6aa1283f82504a7827327076adaf9
4
+ data.tar.gz: 1d6b9bfc94575e2d0be746d8ddf213e8e6da2335
5
5
  SHA512:
6
- metadata.gz: 1de5aa05408a2f2bb3fc5d5a56669d77a24bb72a35a19c727d4390965e816b88694f62045fc7e1f12cf10eb19aac5061ad0e9af7405fefc138283a269f1704e4
7
- data.tar.gz: 2c1ed2db427152286624d55d020c227f4175fe72fa9ab2f07c6f070052c88740a57e0d2905642e3a467b2a12525da886558944818c96e1a7f695ab7e3cb27426
6
+ metadata.gz: e007c4d66893a761c4bdda9a98ca0e2f969ba0f8a0447e7e08bc785e910e9ccc693b7cd7ebe07fcc453432dd74e1b9bde0cc90996e4af6bfa65ed1335b7d2abf
7
+ data.tar.gz: 7e491753074c9b82dd1dfe576bd53d7f1c5354522f6ff9a5f03d2fa706adc5d84d664c3df4c22671d63434f1b5aa3632d6c8fcc7db598db1408f0a3be76e145e
data/README.md CHANGED
@@ -97,6 +97,13 @@ Example usage (which solves the 2 issues above) is as given below:
97
97
  end
98
98
  ```
99
99
 
100
+ # More features
101
+ - Exclusion of keys: simply call
102
+ `record.as_indexed_json: exclude_keys: %w[keys you do not like]`.
103
+ - Selective Import: `es_to_json_when(scope_name, &condition_check_block)`. if
104
+ the scope_name is not given, it would import all by default.
105
+ `condition_check_block` is for checking before making the import
106
+
100
107
  # ToDos
101
108
 
102
109
  - [ ] Tests.. since I don't have time to write test case for this project yet.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: elasticsearch-rails-dynamic-json-support 0.0.5 ruby lib
5
+ # stub: elasticsearch-rails-dynamic-json-support 0.0.6 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "elasticsearch-rails-dynamic-json-support".freeze
9
- s.version = "0.0.5"
9
+ s.version = "0.0.6"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Song Yangyu".freeze]
14
- s.date = "2016-08-31"
14
+ s.date = "2016-09-01"
15
15
  s.description = "Enhance elasticsearch-rails with `elasticsearch_json_changes` to translate the attribute changes into document updates".freeze
16
16
  s.email = "flyfy1@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "elasticsearch-rails-dynamic-json-support.gemspec",
30
30
  "lib/elasticsearch-rails-dynamic-json-support.rb",
31
31
  "lib/elasticsearch/model/cascade_update.rb",
32
+ "lib/elasticsearch/model/importing_decorator.rb",
32
33
  "lib/elasticsearch/model/indexing_decorator.rb",
33
34
  "test/helper.rb",
34
35
  "test/test_elasticsearch-rails-dynamic-json-support.rb"
@@ -39,6 +39,10 @@ module Elasticsearch
39
39
  end
40
40
 
41
41
  class_methods do
42
+ def es_to_json_when(scope_name, &condition_block)
43
+ @@_es_condition_block = condition_block
44
+ @@_es_scope_name = scope_name
45
+ end
42
46
 
43
47
  # attributes is a pair of <key, block>
44
48
  def es_register_attrs *attributes
@@ -59,9 +63,6 @@ module Elasticsearch
59
63
  key_name = key_name.to_s
60
64
  return json_relationship_registry[key_name] unless blk
61
65
 
62
- # If key_name has been defined, then fail fast
63
- fail "json key_name has been already defined: #{key_name} for class #{self.name}" if json_relationship_registry[key_name]
64
-
65
66
  relationship_name = key_name unless relationship_name
66
67
  relationship_name = relationship_name.to_s
67
68
 
@@ -70,10 +71,6 @@ module Elasticsearch
70
71
 
71
72
  reflection = reflect_on_association relationship_name
72
73
 
73
- # The fail is safe since it's in the initialization process
74
- # TODO: make the initializer to include the fail
75
- fail "Reflection not found for #{relationship_name} from class: #{self.name}" unless reflection
76
-
77
74
  reflected_class = reflection.class_name.constantize
78
75
 
79
76
  actor = Actor.new relationship_name, get_singularity(reflection), blk
@@ -0,0 +1,16 @@
1
+ module Elasticsearch
2
+ module Model
3
+ module Importing
4
+ module PrecheckAspect
5
+ def import options={}, &blk
6
+ options[:scope] = self.class_variable_get(:@@_es_scope_name) if self.class_variable_defined?(:@@_es_scope_name) && !options[:scope]
7
+ super options, &blk
8
+ end
9
+ end
10
+
11
+ module ClassMethods
12
+ prepend PrecheckAspect
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,6 +1,32 @@
1
1
  module Elasticsearch
2
2
  module Model
3
3
  module Indexing
4
+ module PrecheckAspect
5
+ def index_document(*args)
6
+ super if _should_pass_to_es
7
+ end
8
+
9
+ def delete_document(*args)
10
+ super if _should_pass_to_es
11
+ end
12
+
13
+ def update_document(*args)
14
+ super if _should_pass_to_es
15
+ end
16
+
17
+ def update_document_attributes(*args)
18
+ super if _should_pass_to_es
19
+ end
20
+
21
+ private
22
+ def _should_pass_to_es
23
+ tclz = target.class
24
+ return true unless tclz.class_variable_defined?(:@@_es_condition_block)
25
+ condition_blk = tclz.class_variable_get(:@@_es_condition_block)
26
+ !condition_blk || condition_blk[self]
27
+ end
28
+ end
29
+
4
30
  module InstanceMethods
5
31
  def update_document options = {}
6
32
  if changed_attributes = self.instance_variable_get(:@__changed_attributes)
@@ -17,6 +43,8 @@ module Elasticsearch
17
43
  index_document(options)
18
44
  end
19
45
  end
46
+
47
+ prepend PrecheckAspect
20
48
  end
21
49
  end
22
50
  end
@@ -1,4 +1,5 @@
1
1
  require 'elasticsearch/model'
2
2
 
3
3
  require_relative 'elasticsearch/model/indexing_decorator'
4
+ require_relative 'elasticsearch/model/importing_decorator'
4
5
  require_relative 'elasticsearch/model/cascade_update'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-rails-dynamic-json-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Song Yangyu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-31 00:00:00.000000000 Z
11
+ date: 2016-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch-rails
@@ -127,6 +127,7 @@ files:
127
127
  - elasticsearch-rails-dynamic-json-support.gemspec
128
128
  - lib/elasticsearch-rails-dynamic-json-support.rb
129
129
  - lib/elasticsearch/model/cascade_update.rb
130
+ - lib/elasticsearch/model/importing_decorator.rb
130
131
  - lib/elasticsearch/model/indexing_decorator.rb
131
132
  - test/helper.rb
132
133
  - test/test_elasticsearch-rails-dynamic-json-support.rb