riak-client-noenc 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +42 -0
  4. data/.rspec +1 -0
  5. data/Gemfile +17 -0
  6. data/Guardfile +20 -0
  7. data/LICENSE.md +16 -0
  8. data/README.markdown +640 -0
  9. data/RELEASE_NOTES.md +392 -0
  10. data/Rakefile +119 -0
  11. data/lib/riak.rb +22 -0
  12. data/lib/riak/bucket.rb +297 -0
  13. data/lib/riak/bucket_properties.rb +74 -0
  14. data/lib/riak/bucket_type.rb +77 -0
  15. data/lib/riak/bucket_typed/bucket.rb +121 -0
  16. data/lib/riak/client.rb +433 -0
  17. data/lib/riak/client/beefcake/bucket_properties_operator.rb +178 -0
  18. data/lib/riak/client/beefcake/crdt/counter_loader.rb +18 -0
  19. data/lib/riak/client/beefcake/crdt/map_loader.rb +64 -0
  20. data/lib/riak/client/beefcake/crdt/set_loader.rb +18 -0
  21. data/lib/riak/client/beefcake/crdt_loader.rb +84 -0
  22. data/lib/riak/client/beefcake/crdt_operator.rb +223 -0
  23. data/lib/riak/client/beefcake/footer +4 -0
  24. data/lib/riak/client/beefcake/header +6 -0
  25. data/lib/riak/client/beefcake/message_codes.rb +89 -0
  26. data/lib/riak/client/beefcake/message_overlay.rb +87 -0
  27. data/lib/riak/client/beefcake/messages.rb +772 -0
  28. data/lib/riak/client/beefcake/object_methods.rb +112 -0
  29. data/lib/riak/client/beefcake/protocol.rb +105 -0
  30. data/lib/riak/client/beefcake/socket.rb +260 -0
  31. data/lib/riak/client/beefcake_protobuffs_backend.rb +538 -0
  32. data/lib/riak/client/decaying.rb +36 -0
  33. data/lib/riak/client/feature_detection.rb +120 -0
  34. data/lib/riak/client/instrumentation.rb +19 -0
  35. data/lib/riak/client/node.rb +49 -0
  36. data/lib/riak/client/protobuffs_backend.rb +143 -0
  37. data/lib/riak/client/search.rb +27 -0
  38. data/lib/riak/client/yokozuna.rb +52 -0
  39. data/lib/riak/conflict.rb +13 -0
  40. data/lib/riak/core_ext.rb +7 -0
  41. data/lib/riak/core_ext/blank.rb +53 -0
  42. data/lib/riak/core_ext/deep_dup.rb +13 -0
  43. data/lib/riak/core_ext/extract_options.rb +7 -0
  44. data/lib/riak/core_ext/json.rb +15 -0
  45. data/lib/riak/core_ext/slice.rb +18 -0
  46. data/lib/riak/core_ext/stringify_keys.rb +10 -0
  47. data/lib/riak/core_ext/symbolize_keys.rb +10 -0
  48. data/lib/riak/core_ext/to_param.rb +31 -0
  49. data/lib/riak/counter.rb +101 -0
  50. data/lib/riak/crdt.rb +21 -0
  51. data/lib/riak/crdt/base.rb +183 -0
  52. data/lib/riak/crdt/batch_counter.rb +19 -0
  53. data/lib/riak/crdt/batch_map.rb +41 -0
  54. data/lib/riak/crdt/counter.rb +82 -0
  55. data/lib/riak/crdt/inner_counter.rb +81 -0
  56. data/lib/riak/crdt/inner_flag.rb +42 -0
  57. data/lib/riak/crdt/inner_map.rb +75 -0
  58. data/lib/riak/crdt/inner_register.rb +26 -0
  59. data/lib/riak/crdt/inner_set.rb +102 -0
  60. data/lib/riak/crdt/map.rb +121 -0
  61. data/lib/riak/crdt/operation.rb +19 -0
  62. data/lib/riak/crdt/set.rb +166 -0
  63. data/lib/riak/crdt/typed_collection.rb +181 -0
  64. data/lib/riak/encoding.rb +6 -0
  65. data/lib/riak/errors/backend_creation.rb +9 -0
  66. data/lib/riak/errors/base.rb +9 -0
  67. data/lib/riak/errors/connection_error.rb +50 -0
  68. data/lib/riak/errors/crdt_error.rb +38 -0
  69. data/lib/riak/errors/failed_request.rb +58 -0
  70. data/lib/riak/errors/protobuffs_error.rb +11 -0
  71. data/lib/riak/errors/search_error.rb +35 -0
  72. data/lib/riak/i18n.rb +7 -0
  73. data/lib/riak/index_collection.rb +71 -0
  74. data/lib/riak/instrumentation.rb +6 -0
  75. data/lib/riak/json.rb +52 -0
  76. data/lib/riak/link.rb +96 -0
  77. data/lib/riak/list_buckets.rb +28 -0
  78. data/lib/riak/locale/en.yml +107 -0
  79. data/lib/riak/locale/fr.yml +51 -0
  80. data/lib/riak/map_reduce.rb +295 -0
  81. data/lib/riak/map_reduce/filter_builder.rb +103 -0
  82. data/lib/riak/map_reduce/phase.rb +98 -0
  83. data/lib/riak/map_reduce/results.rb +49 -0
  84. data/lib/riak/map_reduce_error.rb +7 -0
  85. data/lib/riak/multiget.rb +122 -0
  86. data/lib/riak/preflist_item.rb +7 -0
  87. data/lib/riak/rcontent.rb +173 -0
  88. data/lib/riak/robject.rb +222 -0
  89. data/lib/riak/search.rb +11 -0
  90. data/lib/riak/search/index.rb +87 -0
  91. data/lib/riak/search/query.rb +141 -0
  92. data/lib/riak/search/result_collection.rb +144 -0
  93. data/lib/riak/search/result_document.rb +129 -0
  94. data/lib/riak/search/schema.rb +65 -0
  95. data/lib/riak/secondary_index.rb +81 -0
  96. data/lib/riak/serializers.rb +73 -0
  97. data/lib/riak/stamp.rb +77 -0
  98. data/lib/riak/util/escape.rb +80 -0
  99. data/lib/riak/util/tcp_socket_extensions.rb +58 -0
  100. data/lib/riak/util/translation.rb +18 -0
  101. data/lib/riak/version.rb +3 -0
  102. data/lib/riak/walk_spec.rb +145 -0
  103. data/spec/failover/failover.rb +59 -0
  104. data/spec/fixtures/bitcask.txt +25 -0
  105. data/spec/fixtures/cat.jpg +0 -0
  106. data/spec/fixtures/multipart-basic-conflict.txt +15 -0
  107. data/spec/fixtures/multipart-blank.txt +7 -0
  108. data/spec/fixtures/multipart-mapreduce.txt +10 -0
  109. data/spec/fixtures/multipart-with-body.txt +16 -0
  110. data/spec/fixtures/multipart-with-marked-tombstones.txt +17 -0
  111. data/spec/fixtures/multipart-with-unmarked-tombstone.txt +16 -0
  112. data/spec/fixtures/server.cert.crt +15 -0
  113. data/spec/fixtures/server.cert.key +15 -0
  114. data/spec/fixtures/test.pem +1 -0
  115. data/spec/fixtures/yz_schema_template.xml +18 -0
  116. data/spec/integration/riak/bucket_types_spec.rb +270 -0
  117. data/spec/integration/riak/conflict_resolution_spec.rb +96 -0
  118. data/spec/integration/riak/counters_spec.rb +36 -0
  119. data/spec/integration/riak/crdt/configuration_spec.rb +37 -0
  120. data/spec/integration/riak/crdt_search_spec.rb +176 -0
  121. data/spec/integration/riak/crdt_spec.rb +250 -0
  122. data/spec/integration/riak/crdt_validation/map_spec.rb +63 -0
  123. data/spec/integration/riak/crdt_validation/set_spec.rb +122 -0
  124. data/spec/integration/riak/preflist_spec.rb +31 -0
  125. data/spec/integration/riak/properties_spec.rb +69 -0
  126. data/spec/integration/riak/protobuffs/interrupted_request_spec.rb +33 -0
  127. data/spec/integration/riak/protobuffs_backends_spec.rb +40 -0
  128. data/spec/integration/riak/search_spec.rb +104 -0
  129. data/spec/integration/riak/secondary_index_spec.rb +72 -0
  130. data/spec/integration/riak/security_spec.rb +100 -0
  131. data/spec/integration/riak/threading_spec.rb +150 -0
  132. data/spec/integration/yokozuna/index_spec.rb +61 -0
  133. data/spec/integration/yokozuna/queries_spec.rb +115 -0
  134. data/spec/integration/yokozuna/schema_spec.rb +49 -0
  135. data/spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb +247 -0
  136. data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +222 -0
  137. data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +23 -0
  138. data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +189 -0
  139. data/spec/riak/beefcake_protobuffs_backend_spec.rb +162 -0
  140. data/spec/riak/bucket_properties_spec.rb +135 -0
  141. data/spec/riak/bucket_spec.rb +275 -0
  142. data/spec/riak/bucket_type_spec.rb +50 -0
  143. data/spec/riak/bucket_typed/bucket_spec.rb +62 -0
  144. data/spec/riak/client_spec.rb +246 -0
  145. data/spec/riak/core_ext/to_param_spec.rb +15 -0
  146. data/spec/riak/counter_spec.rb +122 -0
  147. data/spec/riak/crdt/counter_spec.rb +55 -0
  148. data/spec/riak/crdt/inner_counter_spec.rb +21 -0
  149. data/spec/riak/crdt/inner_flag_spec.rb +39 -0
  150. data/spec/riak/crdt/inner_map_spec.rb +47 -0
  151. data/spec/riak/crdt/inner_register_spec.rb +40 -0
  152. data/spec/riak/crdt/inner_set_spec.rb +33 -0
  153. data/spec/riak/crdt/map_spec.rb +78 -0
  154. data/spec/riak/crdt/set_spec.rb +61 -0
  155. data/spec/riak/crdt/shared_examples.rb +74 -0
  156. data/spec/riak/crdt/typed_collection_spec.rb +225 -0
  157. data/spec/riak/escape_spec.rb +72 -0
  158. data/spec/riak/feature_detection_spec.rb +77 -0
  159. data/spec/riak/index_collection_spec.rb +53 -0
  160. data/spec/riak/instrumentation_spec.rb +124 -0
  161. data/spec/riak/link_spec.rb +85 -0
  162. data/spec/riak/list_buckets_spec.rb +41 -0
  163. data/spec/riak/map_reduce/filter_builder_spec.rb +32 -0
  164. data/spec/riak/map_reduce/phase_spec.rb +142 -0
  165. data/spec/riak/map_reduce_spec.rb +434 -0
  166. data/spec/riak/multiget_spec.rb +81 -0
  167. data/spec/riak/node_spec.rb +26 -0
  168. data/spec/riak/robject_spec.rb +496 -0
  169. data/spec/riak/search/index_spec.rb +72 -0
  170. data/spec/riak/search/query_spec.rb +88 -0
  171. data/spec/riak/search/result_collection_spec.rb +89 -0
  172. data/spec/riak/search/result_document_spec.rb +106 -0
  173. data/spec/riak/search/schema_spec.rb +63 -0
  174. data/spec/riak/search_spec.rb +107 -0
  175. data/spec/riak/secondary_index_spec.rb +225 -0
  176. data/spec/riak/serializers_spec.rb +121 -0
  177. data/spec/riak/stamp_spec.rb +54 -0
  178. data/spec/riak/walk_spec_spec.rb +203 -0
  179. data/spec/spec_helper.rb +66 -0
  180. data/spec/support/certs/README.md +13 -0
  181. data/spec/support/certs/ca.crt +21 -0
  182. data/spec/support/certs/client.crl +13 -0
  183. data/spec/support/certs/client.crt +94 -0
  184. data/spec/support/certs/client.csr +18 -0
  185. data/spec/support/certs/client.key +27 -0
  186. data/spec/support/certs/empty_ca.crt +21 -0
  187. data/spec/support/certs/server.crl +13 -0
  188. data/spec/support/certs/server.crt +94 -0
  189. data/spec/support/certs/server.key +27 -0
  190. data/spec/support/crdt_search_config.rb +112 -0
  191. data/spec/support/crdt_search_fixtures.rb +42 -0
  192. data/spec/support/integration_setup.rb +10 -0
  193. data/spec/support/search_config.rb +83 -0
  194. data/spec/support/search_corpus_setup.rb +39 -0
  195. data/spec/support/test_client.rb +46 -0
  196. data/spec/support/test_client.yml.example +10 -0
  197. data/spec/support/unified_backend_examples.rb +380 -0
  198. data/spec/support/version_filter.rb +12 -0
  199. data/spec/support/wait_until.rb +20 -0
  200. metadata +511 -0
@@ -0,0 +1,19 @@
1
+ module Riak
2
+ module Crdt
3
+ class BatchCounter
4
+ attr_reader :accumulator
5
+
6
+ def initialize
7
+ @accumulator = 0
8
+ end
9
+
10
+ def increment(amount = 1)
11
+ @accumulator += amount
12
+ end
13
+
14
+ def decrement(amount = 1)
15
+ increment -amount
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ module Riak
2
+ module Crdt
3
+ # A map that queues up its operations for the parent {Map} to send to
4
+ # Riak all at once.
5
+ class BatchMap
6
+ attr_reader :counters, :flags, :maps, :registers, :sets
7
+
8
+ # @api private
9
+ def initialize(parent)
10
+ @parent = parent
11
+ @queue = []
12
+
13
+ initialize_collections
14
+ end
15
+
16
+ # @api private
17
+ def operate(operation)
18
+ @queue << operation
19
+ end
20
+
21
+ # @api private
22
+ def operations
23
+ @queue.map do |q|
24
+ Operation::Update.new.tap do |op|
25
+ op.type = :map
26
+ op.value = q
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+ def initialize_collections
33
+ @counters = @parent.counters.reparent self
34
+ @flags = @parent.flags.reparent self
35
+ @maps = @parent.maps.reparent self
36
+ @registers = @parent.registers.reparent self
37
+ @sets = @parent.sets.reparent self
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,82 @@
1
+ module Riak
2
+ module Crdt
3
+
4
+ # A distributed counter that supports incrementing and decrementing. This
5
+ # `Counter` uses the Riak 2 Data Types feature. If you're interested in
6
+ # Riak 1.4 Counters, see {Riak::Counter}.
7
+ class Counter < Base
8
+
9
+ # Create a counter instance. The bucket type is determined by the first of
10
+ # these sources:
11
+ #
12
+ # 1. The `bucket_type` String argument
13
+ # 2. A {BucketTyped::Bucket} as the `bucket` argument
14
+ # 3. The `Crdt::Base::DEFAULT_BUCKET_TYPES[:counter]` entry
15
+ #
16
+ # @param [Bucket] bucket the {Riak::Bucket} for this counter
17
+ # @param [String, nil] key The name of the counter. A nil key makes
18
+ # Riak assign a key.
19
+ # @param [String] bucket_type The optional bucket type for this counter.
20
+ # The default is in `Crdt::Base::DEFAULT_BUCKET_TYPES[:counter]`.
21
+ # @param [Hash] options
22
+ def initialize(bucket, key, bucket_type = nil, options = {})
23
+ super(bucket, key, bucket_type || :counter, options)
24
+ end
25
+
26
+ # The current value of the counter; hits the server if the value has
27
+ # not been fetched or if the counter has been incremented.
28
+ def value
29
+ reload if dirty?
30
+ return @value
31
+ end
32
+
33
+ # Increment the counter.
34
+ #
35
+ # @param [Integer] amount
36
+ # @param [Hash] options
37
+ def increment(amount = 1, options = {})
38
+ operate operation(amount), options
39
+ end
40
+
41
+ # Yields a {BatchCounter} to turn multiple increments into a single
42
+ # Riak hit.
43
+ #
44
+ # @yieldparam [BatchCounter] batch_counter collects multiple increments
45
+ def batch
46
+ batcher = BatchCounter.new
47
+
48
+ yield batcher
49
+
50
+ increment batcher.accumulator
51
+ end
52
+
53
+ alias :to_i :value
54
+
55
+ # Decrement the counter.
56
+ #
57
+ # @param [Integer] amount
58
+ def decrement(amount = 1)
59
+ increment -amount
60
+ end
61
+
62
+ def pretty_print(pp)
63
+ super pp do
64
+ pp.comma_breakable
65
+ pp.text "value=#{value}"
66
+ end
67
+ end
68
+
69
+ private
70
+ def vivify(value)
71
+ @value = value
72
+ end
73
+
74
+ def operation(amount)
75
+ Operation::Update.new.tap do |op|
76
+ op.type = :counter
77
+ op.value = amount
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,81 @@
1
+ module Riak
2
+ module Crdt
3
+ # The {InnerCounter} lives inside a {Map}, or an {InnerMap} inside of a
4
+ # {Map}, and is accessed through a {TypedCollection}.
5
+ #
6
+ # Much like the {Riak::Crdt::Counter}, it provides an integer value that can
7
+ # be incremented and decremented.
8
+ class InnerCounter
9
+ # The name of this counter inside a map.
10
+ #
11
+ # @api private
12
+ attr_accessor :name
13
+
14
+ # The value of this counter.
15
+ #
16
+ # @return [Integer] counter value
17
+ attr_reader :value
18
+ alias :to_i :value
19
+
20
+ # The parent of this counter.
21
+ #
22
+ # @api private
23
+ attr_reader :parent
24
+
25
+ # @api private
26
+ def initialize(parent, value = 0)
27
+ @parent = parent
28
+ @value = value
29
+ end
30
+
31
+ # Increment the counter.
32
+ #
33
+ # @param [Integer] amount How much to increment the counter by.
34
+ def increment(amount = 1)
35
+ @parent.increment name, amount
36
+ end
37
+
38
+ # Decrement the counter. Opposite of increment.
39
+ #
40
+ # @param [Integer] amount How much to decrement from the counter.
41
+ def decrement(amount = 1)
42
+ increment -amount
43
+ end
44
+
45
+ # Perform multiple increments against this counter, and collapse
46
+ # them into a single operation.
47
+ #
48
+ # @yieldparam [BatchCounter] batch_counter actually collects the
49
+ # operations.
50
+ def batch
51
+ batcher = BatchCounter.new
52
+
53
+ yield batcher
54
+
55
+ increment batcher.accumulator
56
+ end
57
+
58
+ def pretty_print(pp)
59
+ pp.object_group self do
60
+ pp.breakable
61
+ pp.pp value
62
+ end
63
+ end
64
+
65
+ # @api private
66
+ def self.update(increment)
67
+ Operation::Update.new.tap do |op|
68
+ op.value = increment
69
+ op.type = :counter
70
+ end
71
+ end
72
+
73
+ # @api private
74
+ def self.delete
75
+ Operation::Delete.new.tap do |op|
76
+ op.type = :counter
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,42 @@
1
+ module Riak
2
+ module Crdt
3
+ # The {InnerFlag} is a boolean member of a {Map}. Since flag operations are
4
+ # extremely simple, this object simply provides internal API methods for
5
+ # {TypedCollection} to use.
6
+ #
7
+ # @api private
8
+ class InnerFlag
9
+ def self.new(parent, value = false)
10
+ ensure_boolean value
11
+
12
+ return value
13
+ end
14
+
15
+ def self.update(value)
16
+ ensure_boolean value
17
+
18
+ Operation::Update.new.tap do |op|
19
+ op.value = value
20
+ op.type = :flag
21
+ end
22
+ end
23
+
24
+ def self.delete
25
+ Operation::Delete.new.tap do |op|
26
+ op.type = :flag
27
+ end
28
+ end
29
+
30
+ private
31
+ def self.ensure_boolean(value)
32
+ return if value.is_a? TrueClass
33
+ return if value.is_a? FalseClass
34
+
35
+ raise FlagError, t('crdt.flag.not_boolean')
36
+ end
37
+
38
+ class FlagError < ArgumentError
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,75 @@
1
+ module Riak
2
+ module Crdt
3
+ # A map that exists inside a {TypedCollection} inside another map.
4
+ class InnerMap
5
+ attr_reader :counters, :flags, :maps, :registers, :sets
6
+
7
+ attr_accessor :name
8
+
9
+ # The parent of this counter.
10
+ #
11
+ # @api private
12
+ attr_reader :parent
13
+
14
+ # @api private
15
+ def initialize(parent, value = {})
16
+ @parent = parent
17
+ @value = value.symbolize_keys
18
+
19
+ initialize_collections
20
+ end
21
+
22
+ # @api private
23
+ def operate(inner_operation)
24
+ wrapped_operation = Operation::Update.new.tap do |op|
25
+ op.value = inner_operation
26
+ op.type = :map
27
+ end
28
+
29
+ @parent.operate(name, wrapped_operation)
30
+ end
31
+
32
+ def pretty_print(pp)
33
+ pp.object_group self do
34
+ %w{counters flags maps registers sets}.each do |h|
35
+ pp.comma_breakable
36
+ pp.text "#{h}="
37
+ pp.pp send h
38
+ end
39
+ end
40
+ end
41
+
42
+ def pretty_print_cycle(pp)
43
+ pp.text "InnerMap"
44
+ end
45
+
46
+ def to_value_h
47
+ %w{counters flags maps registers sets}.map do |k|
48
+ [k, send(k).to_value_h]
49
+ end.to_h
50
+ end
51
+
52
+ alias :value :to_value_h
53
+
54
+ # @api private
55
+ def self.delete
56
+ Operation::Delete.new.tap do |op|
57
+ op.type = :map
58
+ end
59
+ end
60
+
61
+ def context?
62
+ @parent.context?
63
+ end
64
+
65
+ private
66
+ def initialize_collections
67
+ @counters = TypedCollection.new InnerCounter, self, @value[:counters]
68
+ @flags = TypedCollection.new InnerFlag, self, @value[:flags]
69
+ @maps = TypedCollection.new InnerMap, self, @value[:maps]
70
+ @registers = TypedCollection.new InnerRegister, self, @value[:registers]
71
+ @sets = TypedCollection.new InnerSet, self, @value[:sets]
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,26 @@
1
+ module Riak
2
+ module Crdt
3
+ class InnerRegister < String
4
+ attr_reader :parent
5
+
6
+ def initialize(parent, *args, &block)
7
+ @parent = parent
8
+ super(*args, &block)
9
+ freeze
10
+ end
11
+
12
+ def self.update(value)
13
+ Operation::Update.new.tap do |op|
14
+ op.value = value
15
+ op.type = :register
16
+ end
17
+ end
18
+
19
+ def self.delete
20
+ Operation::Delete.new.tap do |op|
21
+ op.type = :register
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,102 @@
1
+ module Riak
2
+ module Crdt
3
+ # The {InnerSet} is similar to a {Riak::Crdt::Set}, except it is part of
4
+ # a {Map} (or an {InnerMap} inside of a {Map}). It is usually accessed
5
+ # through a {TypedCollection}.
6
+ #
7
+ # Just like a {Riak::Crdt::Set}, it's a set of {String Strings} that can
8
+ # be added to or removed from.
9
+ class InnerSet
10
+ # The name of this set inside a map.
11
+ #
12
+ # @api private
13
+ attr_accessor :name
14
+
15
+ # The {::Set} value of this {InnerSet}.
16
+ #
17
+ # @return [::Set] set value
18
+ attr_reader :value
19
+ alias :members :value
20
+
21
+ # The parent of this counter.
22
+ #
23
+ # @api private
24
+ attr_reader :parent
25
+
26
+ # @api private
27
+ def initialize(parent, value = [])
28
+ @parent = parent
29
+ frozen_value = value.to_a.tap{ |v| v.each(&:freeze) }
30
+ @value = ::Set.new frozen_value
31
+ @value.freeze
32
+ end
33
+
34
+ # Casts this {InnerSet} to an {Array}.
35
+ #
36
+ # @return [Array] an array of all the members of this set
37
+ def to_a
38
+ value.to_a
39
+ end
40
+
41
+ # Check if this {InnerSet} is empty.
42
+ #
43
+ # @return [Boolean} whether this structure is empty or not
44
+ def empty?
45
+ value.empty?
46
+ end
47
+
48
+ # Check if a given string is in this structure.
49
+ #
50
+ # @param [String] element candidate string to check for inclusion
51
+ # @return [Boolean] whether the candidate is in this set or not
52
+ def include?(element)
53
+ value.include? element
54
+ end
55
+
56
+ # Add a {String} to the {InnerSet}
57
+ #
58
+ # @param [String] element the element to add
59
+ def add(element)
60
+ @parent.operate name, update(add: element)
61
+ end
62
+
63
+ # Remove a {String} from this set
64
+ #
65
+ # @param [String] element the element to remove
66
+ def remove(element)
67
+ raise CrdtError::SetRemovalWithoutContextError unless context?
68
+ @parent.operate name, update(remove: element)
69
+ end
70
+
71
+
72
+ # Does the map containing this set have the context necessary to remove elements?
73
+ #
74
+ # @return [Boolean] if the set has a defined context
75
+ def context?
76
+ @parent.context?
77
+ end
78
+
79
+ def pretty_print(pp)
80
+ pp.object_group self do
81
+ pp.breakable
82
+ pp.pp to_a
83
+ end
84
+ end
85
+
86
+ # @api private
87
+ def update(changes)
88
+ Operation::Update.new.tap do |op|
89
+ op.value = changes.symbolize_keys
90
+ op.type = :set
91
+ end
92
+ end
93
+
94
+ # @api private
95
+ def self.delete
96
+ Operation::Delete.new.tap do |op|
97
+ op.type = :set
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end