isomorfeus-data 1.0.0.zeta25 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +47 -21
  3. data/README.md +38 -46
  4. data/lib/isomorfeus/data/attribute_support.rb +176 -176
  5. data/lib/isomorfeus/data/config.rb +79 -110
  6. data/lib/isomorfeus/data/element_validator.rb +147 -147
  7. data/lib/isomorfeus/data/ferret_accelerator.rb +66 -0
  8. data/lib/isomorfeus/data/field_support.rb +110 -0
  9. data/lib/isomorfeus/data/generic_class_api.rb +136 -116
  10. data/lib/isomorfeus/data/generic_instance_api.rb +150 -145
  11. data/lib/isomorfeus/data/hamster_accelerator.rb +87 -0
  12. data/lib/isomorfeus/data/hamster_storage_expander.rb +94 -0
  13. data/lib/isomorfeus/data/handler/generic.rb +134 -138
  14. data/lib/isomorfeus/data/reducer.rb +30 -30
  15. data/lib/isomorfeus/data/version.rb +4 -4
  16. data/lib/isomorfeus-data.rb +56 -64
  17. data/lib/isomorfeus_data/lucid_document/base.rb +10 -0
  18. data/lib/isomorfeus_data/lucid_document/mixin.rb +148 -0
  19. data/lib/isomorfeus_data/lucid_file/base.rb +10 -0
  20. data/lib/isomorfeus_data/lucid_file/mixin.rb +217 -0
  21. data/lib/isomorfeus_data/lucid_object/base.rb +10 -0
  22. data/lib/isomorfeus_data/lucid_object/mixin.rb +216 -0
  23. data/lib/isomorfeus_data/lucid_query/base.rb +10 -0
  24. data/lib/isomorfeus_data/lucid_query/mixin.rb +81 -0
  25. data/lib/isomorfeus_data/lucid_query_result.rb +97 -0
  26. data/opal/uri/common.rb +18 -0
  27. data/opal/uri/generic.rb +47 -0
  28. data/opal/uri.rb +29 -0
  29. metadata +85 -96
  30. data/lib/isomorfeus/data/handler/arango.rb +0 -56
  31. data/lib/isomorfeus/data/handler/object_call.rb +0 -40
  32. data/lib/isomorfeus/data/handler/object_store.rb +0 -40
  33. data/lib/isomorfeus_data/lucid_data/array/base.rb +0 -13
  34. data/lib/isomorfeus_data/lucid_data/array/mixin.rb +0 -580
  35. data/lib/isomorfeus_data/lucid_data/collection/base.rb +0 -13
  36. data/lib/isomorfeus_data/lucid_data/collection/finders.rb +0 -83
  37. data/lib/isomorfeus_data/lucid_data/collection/mixin.rb +0 -737
  38. data/lib/isomorfeus_data/lucid_data/composition/base.rb +0 -13
  39. data/lib/isomorfeus_data/lucid_data/composition/mixin.rb +0 -234
  40. data/lib/isomorfeus_data/lucid_data/document/base.rb +0 -13
  41. data/lib/isomorfeus_data/lucid_data/document/mixin.rb +0 -9
  42. data/lib/isomorfeus_data/lucid_data/edge/base.rb +0 -13
  43. data/lib/isomorfeus_data/lucid_data/edge/mixin.rb +0 -286
  44. data/lib/isomorfeus_data/lucid_data/edge_collection/base.rb +0 -13
  45. data/lib/isomorfeus_data/lucid_data/edge_collection/finders.rb +0 -134
  46. data/lib/isomorfeus_data/lucid_data/edge_collection/mixin.rb +0 -747
  47. data/lib/isomorfeus_data/lucid_data/generic_collection.rb +0 -4
  48. data/lib/isomorfeus_data/lucid_data/generic_edge.rb +0 -4
  49. data/lib/isomorfeus_data/lucid_data/generic_edge_collection.rb +0 -4
  50. data/lib/isomorfeus_data/lucid_data/generic_node.rb +0 -4
  51. data/lib/isomorfeus_data/lucid_data/graph/base.rb +0 -13
  52. data/lib/isomorfeus_data/lucid_data/graph/finders.rb +0 -141
  53. data/lib/isomorfeus_data/lucid_data/graph/mixin.rb +0 -489
  54. data/lib/isomorfeus_data/lucid_data/hash/base.rb +0 -13
  55. data/lib/isomorfeus_data/lucid_data/hash/mixin.rb +0 -427
  56. data/lib/isomorfeus_data/lucid_data/link/base.rb +0 -13
  57. data/lib/isomorfeus_data/lucid_data/link/mixin.rb +0 -9
  58. data/lib/isomorfeus_data/lucid_data/link_collection/base.rb +0 -13
  59. data/lib/isomorfeus_data/lucid_data/link_collection/mixin.rb +0 -9
  60. data/lib/isomorfeus_data/lucid_data/node/base.rb +0 -13
  61. data/lib/isomorfeus_data/lucid_data/node/mixin.rb +0 -232
  62. data/lib/isomorfeus_data/lucid_data/query/base.rb +0 -13
  63. data/lib/isomorfeus_data/lucid_data/query/mixin.rb +0 -83
  64. data/lib/isomorfeus_data/lucid_data/query_result.rb +0 -95
  65. data/lib/isomorfeus_data/lucid_data/vertex/base.rb +0 -13
  66. data/lib/isomorfeus_data/lucid_data/vertex/mixin.rb +0 -9
  67. data/lib/lucid_arango/collection/base.rb +0 -13
  68. data/lib/lucid_arango/collection/mixin.rb +0 -18
  69. data/lib/lucid_arango/document/base.rb +0 -13
  70. data/lib/lucid_arango/document/mixin.rb +0 -9
  71. data/lib/lucid_arango/edge/base.rb +0 -13
  72. data/lib/lucid_arango/edge/mixin.rb +0 -18
  73. data/lib/lucid_arango/edge_collection/base.rb +0 -13
  74. data/lib/lucid_arango/edge_collection/mixin.rb +0 -18
  75. data/lib/lucid_arango/graph/base.rb +0 -13
  76. data/lib/lucid_arango/graph/mixin.rb +0 -18
  77. data/lib/lucid_arango/node/base.rb +0 -13
  78. data/lib/lucid_arango/node/mixin.rb +0 -79
  79. data/lib/lucid_arango/object/base.rb +0 -11
  80. data/lib/lucid_arango/object/mixin.rb +0 -158
  81. data/lib/lucid_arango/remote_object/base.rb +0 -11
  82. data/lib/lucid_arango/remote_object/mixin.rb +0 -17
  83. data/lib/lucid_arango/vertex/base.rb +0 -13
  84. data/lib/lucid_arango/vertex/mixin.rb +0 -9
@@ -1,116 +1,136 @@
1
- module Isomorfeus
2
- module Data
3
- module GenericClassApi
4
- if RUBY_ENGINE == 'opal'
5
- def destroy(key:)
6
- promise_destroy(key: key)
7
- true
8
- end
9
-
10
- def promise_destroy(key:)
11
- Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', self.name, :destroy, key: key).then do |agent|
12
- if agent.processed
13
- agent.result
14
- else
15
- agent.processed = true
16
- if agent.response.key?(:error)
17
- Isomorfeus.raise_error(message: agent.response[:error])
18
- end
19
- Isomorfeus.store.dispatch(type: 'DATA_DESTROY', data: [self.name, key])
20
- agent.result = true
21
- end
22
- end
23
- end
24
-
25
- def load(key:)
26
- instance = self.new(key: key)
27
- promise_load(key: key, instance: instance) unless instance.loaded?
28
- instance
29
- end
30
-
31
- def promise_load(key:, instance: nil)
32
- instance = self.new(key: key) unless instance
33
- Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', self.name, :load, key: key).then do |agent|
34
- if agent.processed
35
- agent.result
36
- else
37
- agent.processed = true
38
- if agent.response.key?(:error)
39
- Isomorfeus.raise_error(message: agent.response[:error])
40
- end
41
- instance._load_from_store!
42
- Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: agent.full_response[:data])
43
- agent.result = instance
44
- end
45
- end
46
- end
47
-
48
- # execute
49
- def execute_create(_); end
50
- def execute_destroy(_); end
51
- def execute_load(_); end
52
- def execute_save(_); end
53
- else
54
- def destroy(key:)
55
- !!instance_exec(key: key, &@_destroy_block)
56
- end
57
-
58
- def promise_load(key:)
59
- instance = self.load(key: key)
60
- result_promise = Promise.new
61
- result_promise.resolve(instance)
62
- result_promise
63
- end
64
-
65
- def load(key:)
66
- data = instance_exec(key: key, &@_load_block)
67
- return nil unless data
68
- return data if data.class == self
69
- Isomorfeus.raise_error(message: "#{self.to_s}: execute_load must return a instance of #{self.to_s} or nil. Returned was: #{data.class}.") if data.class != self
70
- data
71
- end
72
-
73
- # execute
74
- def execute_create(&block)
75
- @_create_block = block
76
- end
77
-
78
- def execute_destroy(&block)
79
- @_destroy_block = block
80
- end
81
-
82
- def execute_load(&block)
83
- @_load_block = block
84
- end
85
-
86
- def execute_save(&block)
87
- @_save_block = block
88
- end
89
- end
90
-
91
- def create(key:, **things)
92
- new(key: key, **things).create
93
- end
94
-
95
- def promise_create(key:, **things)
96
- new(key: key, **things).promise_create
97
- end
98
-
99
- def save(instance:)
100
- instance.save
101
- end
102
-
103
- def promise_save(instance:)
104
- instance.promise_save
105
- end
106
-
107
- def current_user
108
- Isomorfeus.current_user
109
- end
110
-
111
- def pub_sub_client
112
- Isomorfeus.pub_sub_client
113
- end
114
- end
115
- end
116
- end
1
+ module Isomorfeus
2
+ module Data
3
+ module GenericClassApi
4
+ if RUBY_ENGINE == 'opal'
5
+ def destroy(key:)
6
+ promise_destroy(key: key)
7
+ true
8
+ end
9
+
10
+ def promise_destroy(key:)
11
+ Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', self.name, :destroy, key: key).then do |agent|
12
+ if agent.processed
13
+ agent.result
14
+ else
15
+ agent.processed = true
16
+ if agent.response.key?(:error)
17
+ Isomorfeus.raise_error(message: agent.response[:error])
18
+ end
19
+ Isomorfeus.store.dispatch(type: 'DATA_DESTROY', data: [self.name, key])
20
+ agent.result = true
21
+ end
22
+ end
23
+ end
24
+
25
+ def load(key:)
26
+ instance = self.new(key: key)
27
+ promise_load(key: key, instance: instance) unless instance.loaded?
28
+ instance
29
+ end
30
+
31
+ def promise_load(key:, instance: nil)
32
+ instance = self.new(key: key) unless instance
33
+ if instance.loaded?
34
+ Promise.new.resolve(instance)
35
+ else
36
+ promise_load!(key: key, instance: instance)
37
+ end
38
+ end
39
+
40
+ def load!(key:)
41
+ instance = self.new(key: key)
42
+ promise_load!(key: key, instance: instance) unless instance.loaded?
43
+ instance
44
+ end
45
+
46
+ def promise_load!(key:, instance: nil)
47
+ instance = self.new(key: key) unless instance
48
+ Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', self.name, :load, key: key).then do |agent|
49
+ if agent.processed
50
+ agent.result
51
+ else
52
+ agent.processed = true
53
+ if agent.response.key?(:error)
54
+ Isomorfeus.raise_error(message: agent.response[:error])
55
+ end
56
+ instance._load_from_store!
57
+ Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: agent.full_response[:data])
58
+ agent.result = instance
59
+ end
60
+ end
61
+ end
62
+
63
+ # execute
64
+ def execute_create(_); end
65
+ def execute_destroy(_); end
66
+ def execute_load(_); end
67
+ def execute_save(_); end
68
+ else # RUBY_ENGINE
69
+ def destroy(key:)
70
+ !!instance_exec(key: key, &@_destroy_block)
71
+ end
72
+
73
+ def promise_load(key:)
74
+ instance = self.load(key: key)
75
+ result_promise = Promise.new
76
+ result_promise.resolve(instance)
77
+ result_promise
78
+ end
79
+ alias promise_load! promise_load
80
+
81
+ def load(key:)
82
+ data = instance_exec(key: key, &@_load_block)
83
+ return nil unless data
84
+ return data if data.class == self
85
+ Isomorfeus.raise_error(message: "#{self.to_s}: execute_load must return a instance of #{self.to_s} or nil. Returned was: #{data.class}.") if data.class != self
86
+ data
87
+ end
88
+ alias load! load
89
+
90
+ def execute_create(&block)
91
+ @_create_block = block
92
+ end
93
+
94
+ def execute_destroy(&block)
95
+ @_destroy_block = block
96
+ end
97
+
98
+ def execute_load(&block)
99
+ @_load_block = block
100
+ end
101
+
102
+ def execute_save(&block)
103
+ @_save_block = block
104
+ end
105
+ end # RUBY_ENGINE
106
+
107
+ def gen_sid_s(key)
108
+ "[#{self.name}|#{key}]"
109
+ end
110
+
111
+ def create(key: nil, **things)
112
+ new(key: key, **things).create
113
+ end
114
+
115
+ def promise_create(key: nil, **things)
116
+ new(key: key, **things).promise_create
117
+ end
118
+
119
+ def save(instance:)
120
+ instance.save
121
+ end
122
+
123
+ def promise_save(instance:)
124
+ instance.promise_save
125
+ end
126
+
127
+ def current_user
128
+ Isomorfeus.current_user
129
+ end
130
+
131
+ def pub_sub_client
132
+ Isomorfeus.pub_sub_client
133
+ end
134
+ end
135
+ end
136
+ end
@@ -1,145 +1,150 @@
1
- module Isomorfeus
2
- module Data
3
- module GenericInstanceApi
4
- def key
5
- @key
6
- end
7
-
8
- def key=(k)
9
- @key = k.to_s
10
- end
11
-
12
- def revision
13
- @_revision
14
- end
15
-
16
- def to_sid
17
- [@class_name, @key]
18
- end
19
-
20
- if RUBY_ENGINE == 'opal'
21
- def loaded?
22
- Redux.fetch_by_path(*@_store_path) ? true : false
23
- end
24
-
25
- def create
26
- promise_create
27
- self
28
- end
29
-
30
- def promise_create
31
- data_hash = { instance: to_transport }
32
- data_hash.deep_merge!(included_items: included_items_to_transport) if respond_to?(:included_items_to_transport)
33
- class_name = self.class.name
34
- Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', class_name, :create, data_hash).then do |agent|
35
- if agent.processed
36
- agent.result
37
- else
38
- agent.processed = true
39
- if agent.response.key?(:error)
40
- Isomorfeus.raise_error(message: agent.response[:error])
41
- end
42
- data = agent.full_response[:data]
43
- if data.key?(class_name) && data[class_name].key?(@key) && data[class_name][@key].key?('new_key')
44
- @key = data[class_name][@key]['new_key']
45
- @revision = data[class_name][@key]['revision'] if data[class_name][@key].key?('revision')
46
- _update_paths
47
- end
48
- _load_from_store!
49
- Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: data)
50
- agent.result = self
51
- end
52
- end
53
- end
54
-
55
- def destroy
56
- promise_destroy
57
- nil
58
- end
59
-
60
- def promise_destroy
61
- self.class.promise_destroy(@key)
62
- end
63
-
64
- def reload
65
- self.class.promise_load(@key, self)
66
- self
67
- end
68
-
69
- def promise_reload
70
- self.class.promise_load(@key, self)
71
- end
72
-
73
- def promise_save
74
- data_hash = { instance: to_transport }
75
- data_hash.deep_merge!(included_items: included_items_to_transport) if respond_to?(:included_items_to_transport)
76
- class_name = self.class.name
77
- Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', class_name, :save, data_hash).then do |agent|
78
- if agent.processed
79
- agent.result
80
- else
81
- agent.processed = true
82
- if agent.response.key?(:error)
83
- Isomorfeus.raise_error(message: agent.response[:error])
84
- end
85
- data = agent.full_response[:data]
86
- if data.key?(class_name) && data[class_name].key?(@key) && data[class_name][@key].key?('new_key')
87
- @key = data[class_name][@key]['new_key']
88
- @revision = data[class_name][@key]['revision'] if data[class_name][@key].key?('revision')
89
- _update_paths
90
- end
91
- _load_from_store!
92
- Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: data)
93
- agent.result = self
94
- end
95
- end
96
- end
97
-
98
- # TODO update -> only send partial change
99
- # included_changed_items
100
- else # RUBY_ENGINE
101
- def loaded?
102
- true
103
- end
104
-
105
- def create
106
- previous_key = self.key
107
- instance = instance_exec(&self.class.instance_variable_get(:@_create_block))
108
- return nil unless instance
109
- Isomorfeus.raise_error(message: "#{self.to_s}: execute_create must return self or nil. Returned was: #{instance.class}.") if instance != self
110
- instance_variable_set(:@previous_key, previous_key) if key != previous_key
111
- _unchange!
112
- self
113
- end
114
-
115
- def promise_create
116
- promise = Promise.new
117
- promise.resolve(create)
118
- end
119
-
120
- def save
121
- previous_key = self.key
122
- instance = instance_exec(&self.class.instance_variable_get(:@_save_block))
123
- return nil unless instance
124
- Isomorfeus.raise_error(message: "#{self.to_s}: execute_save must return self or nil. Returned was: #{instance.class}.") if instance != self
125
- instance_variable_set(:@previous_key, previous_key) if key != previous_key
126
- _unchange!
127
- self
128
- end
129
-
130
- def promise_save
131
- promise = Promise.new
132
- promise.resolve(save)
133
- end
134
- end # RUBY_ENGINE
135
-
136
- def current_user
137
- Isomorfeus.current_user
138
- end
139
-
140
- def pub_sub_client
141
- Isomorfeus.pub_sub_client
142
- end
143
- end
144
- end
145
- end
1
+ module Isomorfeus
2
+ module Data
3
+ module GenericInstanceApi
4
+ def key
5
+ @key
6
+ end
7
+
8
+ def key=(k)
9
+ @key = k.to_s
10
+ end
11
+
12
+ def changed?
13
+ @_changed
14
+ end
15
+
16
+ def revision
17
+ @_revision
18
+ end
19
+
20
+ def sid
21
+ [@class_name, @key]
22
+ end
23
+
24
+ def sid_s
25
+ "[#{@class_name}|#{@key}]"
26
+ end
27
+
28
+ if RUBY_ENGINE == 'opal'
29
+ def loaded?
30
+ Redux.fetch_by_path(*@_store_path) ? true : false
31
+ end
32
+
33
+ def create
34
+ promise_create
35
+ self
36
+ end
37
+
38
+ def promise_create
39
+ data_hash = { instance: to_transport }
40
+ data_hash.deep_merge!(included_items: included_items_to_transport) if respond_to?(:included_items_to_transport)
41
+ class_name = self.class.name
42
+ Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', class_name, :create, data_hash).then do |agent|
43
+ if agent.processed
44
+ agent.result
45
+ else
46
+ agent.processed = true
47
+ if agent.response.key?(:error)
48
+ Isomorfeus.raise_error(message: agent.response[:error])
49
+ end
50
+ data = agent.full_response[:data]
51
+ if data.key?(class_name) && data[class_name].key?(@key) && data[class_name][@key].key?('new_key')
52
+ @key = data[class_name][@key]['new_key']
53
+ @revision = data[class_name][@key]['revision'] if data[class_name][@key].key?('revision')
54
+ _update_paths
55
+ end
56
+ _load_from_store!
57
+ Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: data)
58
+ agent.result = self
59
+ end
60
+ end
61
+ end
62
+
63
+ def destroy
64
+ promise_destroy
65
+ nil
66
+ end
67
+
68
+ def promise_destroy
69
+ self.class.promise_destroy(@key)
70
+ end
71
+
72
+ def reload
73
+ self.class.promise_load!(@key, self)
74
+ self
75
+ end
76
+
77
+ def promise_reload
78
+ self.class.promise_load!(@key, self)
79
+ end
80
+
81
+ def promise_save
82
+ data_hash = { instance: to_transport }
83
+ data_hash.deep_merge!(included_items: included_items_to_transport) if respond_to?(:included_items_to_transport)
84
+ class_name = self.class.name
85
+ Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', class_name, :save, data_hash).then do |agent|
86
+ if agent.processed
87
+ agent.result
88
+ else
89
+ agent.processed = true
90
+ if agent.response.key?(:error)
91
+ Isomorfeus.raise_error(message: agent.response[:error])
92
+ end
93
+ data = agent.full_response[:data]
94
+ if data.key?(class_name) && data[class_name].key?(@key) && data[class_name][@key].key?('new_key')
95
+ @key = data[class_name][@key]['new_key']
96
+ @revision = data[class_name][@key]['revision'] if data[class_name][@key].key?('revision')
97
+ _update_paths
98
+ end
99
+ _load_from_store!
100
+ Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: data)
101
+ agent.result = self
102
+ end
103
+ end
104
+ end
105
+ else # RUBY_ENGINE
106
+ def loaded?
107
+ true
108
+ end
109
+
110
+ def create
111
+ previous_key = self.key
112
+ instance = instance_exec(&self.class.instance_variable_get(:@_create_block))
113
+ return nil unless instance
114
+ Isomorfeus.raise_error(message: "#{self.to_s}: execute_create must return self or nil. Returned was: #{instance.class}.") if instance != self
115
+ instance_variable_set(:@previous_key, previous_key) if key != previous_key
116
+ _unchange!
117
+ self
118
+ end
119
+
120
+ def promise_create
121
+ promise = Promise.new
122
+ promise.resolve(create)
123
+ end
124
+
125
+ def save
126
+ previous_key = self.key
127
+ instance = instance_exec(&self.class.instance_variable_get(:@_save_block))
128
+ return nil unless instance
129
+ Isomorfeus.raise_error(message: "#{self.to_s}: execute_save must return self or nil. Returned was: #{instance.class}.") if instance != self
130
+ instance_variable_set(:@previous_key, previous_key) if key != previous_key
131
+ _unchange!
132
+ self
133
+ end
134
+
135
+ def promise_save
136
+ promise = Promise.new
137
+ promise.resolve(save)
138
+ end
139
+ end # RUBY_ENGINE
140
+
141
+ def current_user
142
+ Isomorfeus.current_user
143
+ end
144
+
145
+ def pub_sub_client
146
+ Isomorfeus.pub_sub_client
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,87 @@
1
+ module Isomorfeus
2
+ module Data
3
+ class HamsterAccelerator
4
+ class << self
5
+ def index
6
+ @index
7
+ end
8
+
9
+ def index=(idx)
10
+ @index = idx
11
+ end
12
+
13
+ def ref
14
+ @ref ||= 0
15
+ end
16
+
17
+ def ref=(val)
18
+ @ref = val
19
+ end
20
+
21
+ def refa
22
+ self.ref += 1
23
+ end
24
+
25
+ def refs
26
+ self.ref -= 1 if self.ref > 0
27
+ end
28
+
29
+ def finalize(cls)
30
+ proc do
31
+ cls.refs
32
+ cls.index.close if cls.ref == 0
33
+ end
34
+ end
35
+ end
36
+
37
+ def initialize(&block)
38
+ if block_given?
39
+ res = block.call(self)
40
+ self.class.index = res unless self.class.index
41
+ else
42
+ open_index
43
+ end
44
+ ObjectSpace.define_finalizer(self, self.class.finalize(self.class))
45
+ end
46
+
47
+ def destroy_index
48
+ close_index
49
+ FileUtils.rm_rf(Isomorfeus.data_object_idx_path)
50
+ end
51
+
52
+ def destroy_doc(id)
53
+ self.class.index.delete(id)
54
+ true
55
+ end
56
+
57
+ def load_doc(id)
58
+ self.class.index.doc(id)&.load
59
+ end
60
+
61
+ def save_doc(id, document)
62
+ self.class.index.update(id, document)
63
+ end
64
+
65
+ def search_each(query, options, &block)
66
+ self.class.index.search_each(query, options, &block)
67
+ end
68
+
69
+ private
70
+
71
+ def open_index
72
+ return self.class.refa if self.class.index
73
+ unless Dir.exist?(Isomorfeus.data_object_idx_path)
74
+ FileUtils.mkdir_p(Isomorfeus.data_object_idx_path)
75
+ fis = Isomorfeus::Ferret::Index::FieldInfos.new
76
+ fis.add_field(:attribute, store: :no)
77
+ fis.add_field(:class_name, store: :no)
78
+ fis.add_field(:value, store: :no)
79
+ fis.add_field(:sid_s_attr, store: :yes)
80
+ fis.create_index(Isomorfeus.data_object_idx_path)
81
+ end
82
+ self.class.index = Isomorfeus::Ferret::Index::Index.new(path: Isomorfeus.data_object_idx_path, id_field: :sid_s_attr)
83
+ self.class.refa
84
+ end
85
+ end
86
+ end
87
+ end