jimmy 2.0.3 → 2.1.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: 0d18b13c6558a49c5a5247d5f4cdc0f7d12805b2583b2bab2557d75c29bd823f
4
- data.tar.gz: bc2e9e773f340dbd4ee3bcf07e6f2eb47fed1d6b5ebb1d4e0f9f195e94ab0d2e
3
+ metadata.gz: c29ca2691ce60d6ca698f214635267bf12a42fa5bac9e11a4b9ac481e0815588
4
+ data.tar.gz: 47a0adde3910f636342b685fed70b10861e0e2145f3a9bf76267f82ef1b4a537
5
5
  SHA512:
6
- metadata.gz: 5133ac0b7b56a3b6b4272a02099e8b1cad2a3b58435cea3b0f0984bf8844128f23a8f6d2c5a4970e0335c134638b768c02befc727bc2ca7f0ac4a08dfc486cc9
7
- data.tar.gz: d5f0148b17deab8950954970e6a1b6f1964db0144c3121176822b35c140a5a5f7029c95a36a3f62e37366da131a71fc1c9f6687a1cbcf8f529d7e0d90bbe904a
6
+ metadata.gz: d33b595d483877f6f1617af4c45550447219dc758913586bd956ddae81ae28fd862cd055124f43581a6404747c008a100f0f1aab99606d0966cabb1f17eeaba7
7
+ data.tar.gz: 9f7a0af3a887108a9ef799979755b4e5a98f6ed951fb2585f74cc327049ffbade07509b040b0edb047b973eb8124797ea0fe2d8b7612dc03448de3b62e2c4254
@@ -127,10 +127,7 @@ module Jimmy
127
127
  property_name = cast_key(property_name)
128
128
  key = cast_key(key)
129
129
  hash = getset(property_name) { {} }
130
- assert !hash.key?(key) do
131
- "Property '#{property_name}' already has a member '#{key}'"
132
- end
133
- schema = cast_schema(schema)
130
+ schema = cast_schema(schema)
134
131
  yield schema if block_given?
135
132
  hash[key] = schema
136
133
  self
@@ -35,6 +35,13 @@ module Jimmy
35
35
 
36
36
  alias << push
37
37
 
38
+ # Assign a member to the array at the given index.
39
+ # @param [Integer] index
40
+ # @param [Object] value
41
+ def []=(index, value)
42
+ @members[index] = cast_value(value)
43
+ end
44
+
38
45
  # Iterate over items in the array. If a block with a single argument is
39
46
  # given, only values will be yielded. Otherwise, indexes and values will
40
47
  # be yielded.
@@ -75,6 +82,13 @@ module Jimmy
75
82
  alias count length
76
83
  alias size length
77
84
 
85
+ # Returns true if the array contains the given +obj+.
86
+ # @param [Object] obj
87
+ # @return [true, false]
88
+ def include?(obj)
89
+ @members.include? obj
90
+ end
91
+
78
92
  protected
79
93
 
80
94
  def export_pairs(pairs)
@@ -67,6 +67,20 @@ module Jimmy
67
67
  self
68
68
  end
69
69
 
70
+ # Duplicate the collection.
71
+ # @return [Jimmy::Json::Collection]
72
+ def dup
73
+ self.class.new @members
74
+ end
75
+
76
+ # Duplicate the collection and all of its members, recursively.
77
+ # @return [Jimmy::Json::Collection]
78
+ def deep_dup(index = {})
79
+ return index[object_id] if index.key? object_id
80
+
81
+ deep_dup_enumerable(self, index) { |new, k, v| new[k] = v }
82
+ end
83
+
70
84
  protected
71
85
 
72
86
  def cast_value(value)
@@ -82,6 +96,18 @@ module Jimmy
82
96
  value.as_json
83
97
  end
84
98
  end
99
+
100
+ def deep_dup_value(value = self, index = {})
101
+ return value.deep_dup(index) if value.is_a? Collection
102
+
103
+ value.dup
104
+ end
105
+
106
+ def deep_dup_enumerable(value, index)
107
+ index[value.object_id] = new = value.class.new
108
+ value.each { |*args, v| yield new, *args, deep_dup_value(v, index) }
109
+ new
110
+ end
85
111
  end
86
112
  end
87
113
  end
@@ -115,6 +115,19 @@ module Jimmy
115
115
  PROPERTY_SEQUENCE.fetch(key) { raise KeyError, 'Not a valid schema key' }
116
116
  end
117
117
 
118
+ # Duplicate the schema with a shallow copy. Collections like properties,
119
+ # enum, etc, will be shared with the duplicate.
120
+ # @return [Jimmy::Json::Schema]
121
+ def dup
122
+ nothing? ? self.class.new.nothing : super
123
+ end
124
+
125
+ # Duplicate the schema.
126
+ # @return [Jimmy::Json::Schema]
127
+ def deep_dup(*)
128
+ nothing? ? self.class.new.nothing : super
129
+ end
130
+
118
131
  protected
119
132
 
120
133
  def schema
@@ -58,7 +58,9 @@ module Jimmy
58
58
  if name.is_a? Hash
59
59
  self.properties name, required: true, &block
60
60
  else
61
- getset('required') { Set.new } << validate_property_name(name)
61
+ arr = getset('required') { [] }
62
+ name = validate_property_name(name)
63
+ arr << name unless arr.include? name
62
64
  end
63
65
  end
64
66
  self
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jimmy
4
- VERSION = '2.0.3'
4
+ VERSION = '2.1.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jimmy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil E. Pearson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-02 00:00:00.000000000 Z
11
+ date: 2020-06-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Jimmy the Gem
14
14
  email: