elasticsearch-model-globalize 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73152b6ab5a5fca4125554d24e26eb382f76bae1
4
- data.tar.gz: 20384046654caf29cd66fa662592559a39020848
3
+ metadata.gz: 3f0b5b689830ed73d970fc292f946df65d4543c5
4
+ data.tar.gz: 65c64bd1d0a1c28c78c79dda0152d72974519b95
5
5
  SHA512:
6
- metadata.gz: aa247dc18ebae5d1c025438b8db343db3f407f1bec865a915fd06bfeb4e9b1b549c85abc03010bf208ba4b70c9b6e6922ff43faace64daf3b0f73725d00c4c77
7
- data.tar.gz: 2c74cc6a49e2bed921960edc66e3fa7319cc1db20cd2ad9d410113d9d5ee446d2fa2bc45b3885175c90c349cd72ecb972423d0b5d7cc299e1cc9b7dedcdbcf6a
6
+ metadata.gz: c4e38850098a974fb27823a0e61003eb24a4f5e1628e746aabb845ee2280db3a60f516e6dac95e81c3c8eb4bba7a7ff75cfb54b1b1a864938ffc8965814e3b8c
7
+ data.tar.gz: 28469f813d0cefec20e9cec1e224e8a275203e48ba61fd5dab9b6f3c078a7322121bf88197846f5b2968fb78238fa71390316d4c7da675c92319cf274de2e365
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # Elasticsearch::Model::Globalize
2
2
 
3
- `elasticsearch-model-globalize` library allows you to use `elasticsearch-model` library
4
- with `Globalize` gem.
3
+ `elasticsearch-model-globalize` library allows you to use
4
+ [elasticsearch-model](https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-model)
5
+ \[[LICENSE](https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/LICENSE.txt)\]
6
+ with [Globalize](https://github.com/globalize/globalize) \[[LICENSE](https://github.com/globalize/globalize/blob/master/LICENSE)\].
5
7
 
6
8
 
7
9
  ## Installation
@@ -21,7 +23,9 @@ Or install it yourself as:
21
23
 
22
24
  ## Usage
23
25
 
24
- There are a few ways to use `elasticsearch-model` with `Globalize`.
26
+ There are a few ways to use
27
+ [elasticsearch-model](https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-model)
28
+ with [Globalize](https://github.com/globalize/globalize).
25
29
 
26
30
  This gem has two modules, one is `MultipleFields` and the other is `OneIndexPerLanguage`.
27
31
  You can choose one for each model to fit your needs by simply including a module.
@@ -48,14 +52,6 @@ class Item < ActiveRecord::Base
48
52
  include Elasticsearch::Model
49
53
  include Elasticsearch::Model::Callbacks
50
54
  include Elasticsearch::Model::Globalize::MultipleFields
51
-
52
- mapping do
53
- indexes :id, type: 'integer'
54
- indexes :name_ja, analyzer: 'kuromoji'
55
- indexes :name_en, analyzer: 'snowball'
56
- indexes :description_ja, analyzer: 'kuromoji'
57
- indexes :description_en, analyzer: 'snowball'
58
- end
59
55
  end
60
56
  ```
61
57
 
@@ -73,7 +69,50 @@ Elasticsearch::Model::Globalize::MultipleFields.localized_name do |name, locale|
73
69
  end
74
70
  ```
75
71
 
76
- One thing you have to care about is that put `translates` line before includeing
72
+ The way to define `mappings` and `as_indexed_json` is same as
73
+ [elasticsearch-model](https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-model)
74
+ without this library.
75
+
76
+ ```ruby
77
+ class Item < ActiveRecord::Base
78
+ translates :name, :description
79
+ include Elasticsearch::Model
80
+ include Elasticsearch::Model::Callbacks
81
+ include Elasticsearch::Model::Globalize::MultipleFields
82
+
83
+ mapping do
84
+ indexes :id, type: 'integer'
85
+ indexes :name_ja, analyzer: 'kuromoji'
86
+ indexes :name_en, analyzer: 'snowball'
87
+ indexes :description_ja, analyzer: 'kuromoji'
88
+ indexes :description_en, analyzer: 'snowball'
89
+ end
90
+
91
+ def as_indexed_json(options={})
92
+ { id: id,
93
+ name_ja: name_ja,
94
+ name_en: name_en,
95
+ description_ja: description_ja,
96
+ description_en: description_en }
97
+ end
98
+ end
99
+ ```
100
+
101
+ Getters and setters of the derived fields are automatically added by `MultipleFields` module.
102
+
103
+ ```ruby
104
+ I18n.locale = :en
105
+ item = Item.new
106
+ item.name_ja = '輪ゴム'
107
+ item.name_ja # => "輪ゴム"
108
+ item.name # => nil
109
+ Globalize.with_locale(:ja) { item.name } # => "輪ゴム"
110
+ item.name = 'elastic'
111
+ item.name # => "elastic"
112
+ item.name_en # => "elastic"
113
+ ```
114
+
115
+ One thing you have to care about is that put `translates` line before including
77
116
  `Elasticsearch::Model::Globalize::MultipleFields`, otherwise `MultipleFields` module are not able to
78
117
  know from which fields to derive localized fields.
79
118
 
@@ -107,8 +107,9 @@ module Elasticsearch
107
107
  else
108
108
  errors = Hash.new
109
109
  I18n.available_locales.each do |locale|
110
+ super_options = options.clone
110
111
  ::Globalize.with_locale(locale) do
111
- errors[locale] = super(options, &block)
112
+ errors[locale] = super(super_options, &block)
112
113
  end
113
114
  end
114
115
  self.find_each do |record|
@@ -1,7 +1,7 @@
1
1
  module Elasticsearch
2
2
  module Model
3
3
  module Globalize
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-model-globalize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kentaro Imai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-23 00:00:00.000000000 Z
11
+ date: 2016-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch-model