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.
- checksums.yaml +4 -4
- data/LICENSE +47 -21
- data/README.md +38 -46
- data/lib/isomorfeus/data/attribute_support.rb +176 -176
- data/lib/isomorfeus/data/config.rb +79 -110
- data/lib/isomorfeus/data/element_validator.rb +147 -147
- data/lib/isomorfeus/data/ferret_accelerator.rb +66 -0
- data/lib/isomorfeus/data/field_support.rb +110 -0
- data/lib/isomorfeus/data/generic_class_api.rb +136 -116
- data/lib/isomorfeus/data/generic_instance_api.rb +150 -145
- data/lib/isomorfeus/data/hamster_accelerator.rb +87 -0
- data/lib/isomorfeus/data/hamster_storage_expander.rb +94 -0
- data/lib/isomorfeus/data/handler/generic.rb +134 -138
- data/lib/isomorfeus/data/reducer.rb +30 -30
- data/lib/isomorfeus/data/version.rb +4 -4
- data/lib/isomorfeus-data.rb +56 -64
- data/lib/isomorfeus_data/lucid_document/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_document/mixin.rb +148 -0
- data/lib/isomorfeus_data/lucid_file/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_file/mixin.rb +217 -0
- data/lib/isomorfeus_data/lucid_object/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_object/mixin.rb +216 -0
- data/lib/isomorfeus_data/lucid_query/base.rb +10 -0
- data/lib/isomorfeus_data/lucid_query/mixin.rb +81 -0
- data/lib/isomorfeus_data/lucid_query_result.rb +97 -0
- data/opal/uri/common.rb +18 -0
- data/opal/uri/generic.rb +47 -0
- data/opal/uri.rb +29 -0
- metadata +85 -96
- data/lib/isomorfeus/data/handler/arango.rb +0 -56
- data/lib/isomorfeus/data/handler/object_call.rb +0 -40
- data/lib/isomorfeus/data/handler/object_store.rb +0 -40
- data/lib/isomorfeus_data/lucid_data/array/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/array/mixin.rb +0 -580
- data/lib/isomorfeus_data/lucid_data/collection/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/collection/finders.rb +0 -83
- data/lib/isomorfeus_data/lucid_data/collection/mixin.rb +0 -737
- data/lib/isomorfeus_data/lucid_data/composition/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/composition/mixin.rb +0 -234
- data/lib/isomorfeus_data/lucid_data/document/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/document/mixin.rb +0 -9
- data/lib/isomorfeus_data/lucid_data/edge/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/edge/mixin.rb +0 -286
- data/lib/isomorfeus_data/lucid_data/edge_collection/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/edge_collection/finders.rb +0 -134
- data/lib/isomorfeus_data/lucid_data/edge_collection/mixin.rb +0 -747
- data/lib/isomorfeus_data/lucid_data/generic_collection.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/generic_edge.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/generic_edge_collection.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/generic_node.rb +0 -4
- data/lib/isomorfeus_data/lucid_data/graph/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/graph/finders.rb +0 -141
- data/lib/isomorfeus_data/lucid_data/graph/mixin.rb +0 -489
- data/lib/isomorfeus_data/lucid_data/hash/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/hash/mixin.rb +0 -427
- data/lib/isomorfeus_data/lucid_data/link/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/link/mixin.rb +0 -9
- data/lib/isomorfeus_data/lucid_data/link_collection/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/link_collection/mixin.rb +0 -9
- data/lib/isomorfeus_data/lucid_data/node/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/node/mixin.rb +0 -232
- data/lib/isomorfeus_data/lucid_data/query/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/query/mixin.rb +0 -83
- data/lib/isomorfeus_data/lucid_data/query_result.rb +0 -95
- data/lib/isomorfeus_data/lucid_data/vertex/base.rb +0 -13
- data/lib/isomorfeus_data/lucid_data/vertex/mixin.rb +0 -9
- data/lib/lucid_arango/collection/base.rb +0 -13
- data/lib/lucid_arango/collection/mixin.rb +0 -18
- data/lib/lucid_arango/document/base.rb +0 -13
- data/lib/lucid_arango/document/mixin.rb +0 -9
- data/lib/lucid_arango/edge/base.rb +0 -13
- data/lib/lucid_arango/edge/mixin.rb +0 -18
- data/lib/lucid_arango/edge_collection/base.rb +0 -13
- data/lib/lucid_arango/edge_collection/mixin.rb +0 -18
- data/lib/lucid_arango/graph/base.rb +0 -13
- data/lib/lucid_arango/graph/mixin.rb +0 -18
- data/lib/lucid_arango/node/base.rb +0 -13
- data/lib/lucid_arango/node/mixin.rb +0 -79
- data/lib/lucid_arango/object/base.rb +0 -11
- data/lib/lucid_arango/object/mixin.rb +0 -158
- data/lib/lucid_arango/remote_object/base.rb +0 -11
- data/lib/lucid_arango/remote_object/mixin.rb +0 -17
- data/lib/lucid_arango/vertex/base.rb +0 -13
- 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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
def
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
def
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
13
|
-
@
|
14
|
-
end
|
15
|
-
|
16
|
-
def
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
self
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
def
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
self
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|