dry-elastic_model 0.1.4 → 0.5.0

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
  SHA256:
3
- metadata.gz: 22daff8f3ddd6c86ca64c773a341229917bc9930bd0897c3090fe8bc51dbd3c6
4
- data.tar.gz: f6abb2425966e98eb112ada1da931831a21da6e4641de261431d8c01b1326148
3
+ metadata.gz: 0c47c5ef6440828b4a4831171717c9e722b08ea032b55b0c819b015b2e76c255
4
+ data.tar.gz: 8cf4efdf8b275b1c383653d258975e0f021b0bdcb04ebbe98eb25718e3d85c85
5
5
  SHA512:
6
- metadata.gz: 943f4654fc39e200de139ed30e9afa48262b1795ef845699b18764b1c60e011d536b5c873d1202d5388d3e6b0fa036977977e0abf47a92d263639c97422579b8
7
- data.tar.gz: 2d9e317a152a567a1ea583922b3e01b607b24d2b5192bf834b439613b771cb8cde90cc5bad70d73e4baab9db22c6a462271e6c5479a42e4b06b78017445cd1b6
6
+ metadata.gz: 7d1b30ff6ab233453824c3fb9d0760b60dfd4943d36cb175b4367659adfd1233ded6ef7e108c818966ec62c1b3bed2fe7d7a878c51cc0eb0e95127d7a8e08abd
7
+ data.tar.gz: f4a470ba333f261daaa902ec8b58420112759fba05e9a6fe5ef9766b2daf5e198ce3ac94bb0d502c1fee18a59169aaaf1d467e9671d9e53be494a67b405d5da1
@@ -1,19 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dry-elastic_model (0.1.4)
4
+ dry-elastic_model (0.5.0)
5
5
  dry-struct (~> 1.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  coderay (1.1.2)
11
- concurrent-ruby (1.1.5)
11
+ concurrent-ruby (1.1.6)
12
12
  diff-lcs (1.3)
13
13
  docile (1.3.1)
14
- dry-configurable (0.9.0)
14
+ dry-configurable (0.11.5)
15
15
  concurrent-ruby (~> 1.0)
16
16
  dry-core (~> 0.4, >= 0.4.7)
17
+ dry-equalizer (~> 0.2)
17
18
  dry-container (0.7.2)
18
19
  concurrent-ruby (~> 1.0)
19
20
  dry-configurable (~> 0.1, >= 0.1.3)
@@ -21,20 +22,20 @@ GEM
21
22
  concurrent-ruby (~> 1.0)
22
23
  dry-equalizer (0.3.0)
23
24
  dry-inflector (0.2.0)
24
- dry-logic (1.0.5)
25
+ dry-logic (1.0.6)
25
26
  concurrent-ruby (~> 1.0)
26
27
  dry-core (~> 0.2)
27
28
  dry-equalizer (~> 0.2)
28
- dry-struct (1.1.1)
29
- dry-core (~> 0.4, >= 0.4.3)
30
- dry-equalizer (~> 0.2)
31
- dry-types (~> 1.0)
29
+ dry-struct (1.3.0)
30
+ dry-core (~> 0.4, >= 0.4.4)
31
+ dry-equalizer (~> 0.3)
32
+ dry-types (~> 1.3)
32
33
  ice_nine (~> 0.11)
33
- dry-types (1.2.1)
34
+ dry-types (1.4.0)
34
35
  concurrent-ruby (~> 1.0)
35
36
  dry-container (~> 0.3)
36
37
  dry-core (~> 0.4, >= 0.4.4)
37
- dry-equalizer (~> 0.2, >= 0.2.2)
38
+ dry-equalizer (~> 0.3)
38
39
  dry-inflector (~> 0.1, >= 0.1.2)
39
40
  dry-logic (~> 1.0, >= 1.0.2)
40
41
  ice_nine (0.11.2)
@@ -77,4 +78,4 @@ DEPENDENCIES
77
78
  simplecov-lcov (~> 0)
78
79
 
79
80
  BUNDLED WITH
80
- 2.0.1
81
+ 2.1.4
data/README.md CHANGED
@@ -37,6 +37,7 @@ Sample model:
37
37
  ```ruby
38
38
  class FooBar < Dry::ElasticModel::Base
39
39
  field :text_field, :text
40
+ field :newly_added_text_field, :text, allow_missing: true
40
41
  field :keyword_field, :keyword, index: false
41
42
  field :date_field, :date
42
43
  field :long_field, :long
@@ -58,6 +59,10 @@ This corresponds to following Elasticsearch mapping (calling `Foo.mapping.to_jso
58
59
  "type": "text",
59
60
  "index": "not_analyzed"
60
61
  },
62
+ "newly_added_text_field": {
63
+ "type": "text",
64
+ "index": "not_analyzed"
65
+ },
61
66
  "keyword_field": {
62
67
  "type": "keyword",
63
68
  "index": false
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.5.0
@@ -4,6 +4,7 @@ module Dry
4
4
  module ElasticModel
5
5
  module Attributes
6
6
  def field(name, type, opts = {})
7
+ allow_missing = opts.delete(:allow_missing)
7
8
  type_definition = Types::TYPES.fetch(type.to_sym)
8
9
 
9
10
  type_options_klass = type_definition.meta[:type_options]
@@ -15,26 +16,54 @@ module Dry
15
16
  end
16
17
 
17
18
  default_opts = type_definition.meta[:opts] || {}
18
- attribute(name,
19
- type_definition.meta(opts: default_opts.merge(options.to_h)))
19
+ define_attribute(
20
+ name,
21
+ type_definition.meta(opts: default_opts.merge(options.to_h)),
22
+ allow_missing: allow_missing
23
+ )
20
24
  end
21
25
 
22
26
  def range(name, type, opts = {})
27
+ allow_missing = allow_missing
23
28
  member = Types::RANGE_TYPES.fetch(type.to_sym)
24
29
 
25
30
  type_definition = Types::Range.call(member)
26
31
 
27
32
  default_opts = type_definition.meta[:opts] || {}
28
- attribute(name, type_definition.meta(opts: default_opts.merge(opts)))
33
+ define_attribute(
34
+ name,
35
+ type_definition.meta(opts: default_opts.merge(opts)),
36
+ allow_missing: opts[:allow_missing]
37
+ )
29
38
  end
30
39
 
31
40
  def list(name, type, opts = {})
41
+ allow_missing = opts.delete(:allow_missing)
32
42
  member = Types::TYPES.fetch(type.to_sym)
33
43
 
34
44
  type_definition = Types::Array.call(member)
35
45
 
36
46
  default_opts = type_definition.meta[:opts] || {}
37
- attribute(name, type_definition.meta(opts: default_opts.merge(opts)))
47
+ define_attribute(
48
+ name,
49
+ type_definition.meta(opts: default_opts.merge(opts)),
50
+ allow_missing: allow_missing
51
+ )
52
+ end
53
+
54
+ private
55
+
56
+ def define_attribute(name, type_definition, allow_missing:)
57
+ public_send(
58
+ attr_definition_method(allow_missing),
59
+ name,
60
+ type_definition
61
+ )
62
+ end
63
+
64
+ def attr_definition_method(allow_missing)
65
+ allow_missing = false if allow_missing.nil?
66
+ allow_missing ? :attribute? : :attribute
38
67
  end
39
68
  end
40
69
  end
@@ -10,21 +10,35 @@ module Dry
10
10
 
11
11
  # rubocop:disable Metrics/LineLength
12
12
  # String datatypes
13
- Text = Types::Strict::String.meta(es_name: "text",
13
+ Text = (Types::Strict::String | Types::Strict::Nil).optional.meta(es_name: "text",
14
14
  type_options: TypeOptions::Text,
15
15
  opts: { index: "not_analyzed" })
16
- Keyword = (Types::Strict::String | Types::Strict::Symbol).
16
+ Keyword = (Types::Strict::String | Types::Strict::Symbol).optional.
17
17
  meta(type_options: TypeOptions::Keyword, es_name: "keyword")
18
18
 
19
19
  # Binary datatype
20
20
  # TODO: Verify if correct Base64
21
- Binary = Types::Strict::String.meta(es_name: "binary",
22
- type_options: TypeOptions::Binary)
21
+ Binary = Types::Strict::String.optional.
22
+ meta(
23
+ es_name: "binary",
24
+ type_options: TypeOptions::Binary
25
+ )
23
26
 
24
27
  # Date datatype
25
- # TODO: Test strings
26
- Date = (Types::Strict::Date | Types::Strict::Time | Types.Value("now")).
27
- meta(es_name: "date", type_options: TypeOptions::Date)
28
+ Date = (
29
+ Types::Strict::Date |
30
+ Types::JSON::Date |
31
+ Types.Value("now")
32
+ ).optional.meta(es_name: "date", type_options: TypeOptions::Date)
33
+
34
+ MAX_UNIX_TIME = 2147468400000 # 2038-01-19
35
+ DateTime = (
36
+ Types::Strict::Time |
37
+ Types::Strict::DateTime |
38
+ Types::JSON::DateTime |
39
+ Types::Integer.constrained(gteq: 0, lteq: MAX_UNIX_TIME) |
40
+ Types.Value("now")
41
+ ).optional.meta(es_name: "date", type_options: TypeOptions::Date)
28
42
 
29
43
  # Numeric datatypes
30
44
  LONG_LIMIT = 2**63
@@ -32,46 +46,46 @@ module Dry
32
46
  SHORT_LIMIT = 2**15
33
47
  BYTE_LIMIT = 2**8
34
48
 
35
- Long = Types::Strict::Integer.
49
+ Long = Types::Strict::Integer.optional.
36
50
  constrained(gteq: -LONG_LIMIT, lteq: LONG_LIMIT - 1).
37
51
  meta(type_options: TypeOptions::Numeric, es_name: "long")
38
52
 
39
- Integer = Types::Strict::Integer.
53
+ Integer = Types::Strict::Integer.optional.
40
54
  constrained(gteq: -INTEGER_LIMIT, lteq: INTEGER_LIMIT - 1).
41
55
  meta(type_options: TypeOptions::Numeric, es_name: "integer")
42
56
 
43
- Short = Types::Strict::Integer.
57
+ Short = Types::Strict::Integer.optional.
44
58
  constrained(gteq: -SHORT_LIMIT, lteq: SHORT_LIMIT - 1).
45
59
  meta(type_options: TypeOptions::Numeric, es_name: "short")
46
60
 
47
- Byte = Types::Strict::Integer.
61
+ Byte = Types::Strict::Integer.optional.
48
62
  constrained(gteq: -BYTE_LIMIT, lteq: BYTE_LIMIT - 1).
49
63
  meta(type_options: TypeOptions::Numeric, es_name: "byte")
50
64
 
51
- Double = (Types::Strict::Integer | Types::Strict::Float).
65
+ Double = (Types::Strict::Integer | Types::Strict::Float).optional.
52
66
  meta(es_name: "double")
53
- Float = (Types::Strict::Integer | Types::Strict::Float).
67
+ Float = (Types::Strict::Integer | Types::Strict::Float).optional.
54
68
  meta(type_options: TypeOptions::Numeric, es_name: "float")
55
69
 
56
- HalfFloat = (Types::Strict::Integer | Types::Strict::Float).
70
+ HalfFloat = (Types::Strict::Integer | Types::Strict::Float).optional.
57
71
  meta(type_options: TypeOptions::Numeric, es_name: "half_float")
58
72
 
59
- ScaledFloat = (Types::Strict::Integer | Types::Strict::Float).
73
+ ScaledFloat = (Types::Strict::Integer | Types::Strict::Float).optional.
60
74
  meta(type_options: TypeOptions::ScaledFloat,
61
75
  es_name: "scaled_float")
62
76
 
63
77
  # Boolean datatype
64
- Boolean = (Types::Strict::Bool | Types.Value("true") | Types.Value("false")).
78
+ Boolean = (Types::Strict::Bool | Types.Value("true") | Types.Value("false")).optional.
65
79
  meta(es_name: "boolean", type_options: TypeOptions::Boolean)
66
80
 
67
81
  # IP datatype
68
82
  IP = (
69
83
  Types::Strict::String.constrained(format: Resolv::IPv4::Regex) |
70
84
  Types::Strict::String.constrained(format: Resolv::IPv6::Regex)
71
- ).meta(es_name: "ip", type_options: TypeOptions::IP)
85
+ ).optional.meta(es_name: "ip", type_options: TypeOptions::IP)
72
86
 
73
87
  Array = lambda do |type|
74
- Types::Strict::Array.of(type).meta(es_name: type.meta[:es_name])
88
+ Types::Strict::Array.of(type).meta(es_name: type.meta[:es_name]).optional
75
89
  end
76
90
 
77
91
  Range = lambda do |type|
@@ -84,14 +98,15 @@ module Dry
84
98
  type_options: TypeOptions::Range)
85
99
  end
86
100
 
87
- ObjectType = Types::Strict::Hash.meta(es_name: "object",
88
- type_options: TypeOptions::Object)
101
+ ObjectType = Types::Strict::Hash.optional.meta(es_name: "object",
102
+ type_options: TypeOptions::Object)
89
103
 
90
104
  TYPES = {
91
105
  text: Text,
92
106
  binary: Binary,
93
107
  keyword: Keyword,
94
108
  date: Date,
109
+ datetime: DateTime,
95
110
  long: Long,
96
111
  integer: Integer,
97
112
  short: Short,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-elastic_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konrad Oleksiuk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-25 00:00:00.000000000 Z
11
+ date: 2020-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -168,8 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  - !ruby/object:Gem::Version
169
169
  version: '0'
170
170
  requirements: []
171
- rubyforge_project:
172
- rubygems_version: 2.7.3
171
+ rubygems_version: 3.0.6
173
172
  signing_key:
174
173
  specification_version: 4
175
174
  summary: Create Elasticsearch models and mappings from code.