code-ruby 0.14.0 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/code/object/dictionary.rb +37 -0
- data/lib/code/object/time.rb +3 -2
- data/lib/code/version.rb +1 -1
- data/spec/code_spec.rb +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7027d0ca2225f4adf54f980dd7d08b7fa07c10c40c7e04b8e67e651a300f77b7
|
|
4
|
+
data.tar.gz: f652f053f3bb7710629deea3ad6cb0684c6117f1475cace386c4ea5005649eca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5ecea3358e470e50cb5571c0c5094837a1eb7fd68043e803d18dc3b691686e246cc0cb93a1a89fd4fbe1448b0dc45841883e4938b8510f9df6d45d7091d57447
|
|
7
|
+
data.tar.gz: 3c0d475b0420dd3a937dd0f2dcff648bc2d1924b0639415c3096e79429dda1e787579a684aa3ce8b236739b590f72ebfb2049c901224288fadfca4ce25c5c183
|
data/Gemfile.lock
CHANGED
|
@@ -107,6 +107,9 @@ class Code
|
|
|
107
107
|
when "merge"
|
|
108
108
|
sig(args) { [Dictionary.repeat, Function.maybe] }
|
|
109
109
|
code_merge(*arguments.raw, **globals)
|
|
110
|
+
when "merge!"
|
|
111
|
+
sig(args) { [Dictionary.repeat, Function.maybe] }
|
|
112
|
+
code_merge!(*arguments.raw, **globals)
|
|
110
113
|
when "nine?"
|
|
111
114
|
sig(args)
|
|
112
115
|
code_nine?
|
|
@@ -470,6 +473,40 @@ class Code
|
|
|
470
473
|
)
|
|
471
474
|
end
|
|
472
475
|
|
|
476
|
+
def code_merge!(*arguments, **globals)
|
|
477
|
+
conflict =
|
|
478
|
+
(
|
|
479
|
+
if arguments.last.is_a?(Function) && arguments.size > 1
|
|
480
|
+
arguments.last
|
|
481
|
+
end
|
|
482
|
+
)
|
|
483
|
+
|
|
484
|
+
arguments = arguments[..-2] if conflict
|
|
485
|
+
|
|
486
|
+
index = 0
|
|
487
|
+
|
|
488
|
+
raw.merge!(*arguments.map(&:raw)) do |key, old_value, new_value|
|
|
489
|
+
if conflict
|
|
490
|
+
conflict
|
|
491
|
+
.call(
|
|
492
|
+
arguments:
|
|
493
|
+
List.new(
|
|
494
|
+
[key, old_value, new_value, Integer.new(index), self]
|
|
495
|
+
),
|
|
496
|
+
**globals
|
|
497
|
+
)
|
|
498
|
+
.tap { index += 1 }
|
|
499
|
+
else
|
|
500
|
+
new_value.tap { index += 1 }
|
|
501
|
+
end
|
|
502
|
+
rescue Error::Next => e
|
|
503
|
+
index += 1
|
|
504
|
+
e.value || Nothing.new
|
|
505
|
+
end
|
|
506
|
+
|
|
507
|
+
self
|
|
508
|
+
end
|
|
509
|
+
|
|
473
510
|
def code_nine?
|
|
474
511
|
code_size.code_nine?
|
|
475
512
|
end
|
data/lib/code/object/time.rb
CHANGED
|
@@ -7,9 +7,10 @@ class Code
|
|
|
7
7
|
|
|
8
8
|
def initialize(*args, **_kargs, &_block)
|
|
9
9
|
::Time.zone ||= DEFAULT_ZONE
|
|
10
|
-
raw = args.first
|
|
10
|
+
raw = args.first
|
|
11
11
|
raw = raw.raw if raw.is_an?(Object)
|
|
12
|
-
|
|
12
|
+
raw = raw.presence || ::Time.zone.now
|
|
13
|
+
@raw = ::Time.zone.parse(raw.to_s).presence || ::Time.zone.now
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
def self.call(**args)
|
data/lib/code/version.rb
CHANGED
data/spec/code_spec.rb
CHANGED
|
@@ -62,6 +62,7 @@ RSpec.describe Code do
|
|
|
62
62
|
Parameter.new
|
|
63
63
|
IdentifierList.new
|
|
64
64
|
IdentifierList.new([])
|
|
65
|
+
Time.new(nothing).before?
|
|
65
66
|
].each { |input| it(input) { Code.evaluate(input) } }
|
|
66
67
|
|
|
67
68
|
[
|
|
@@ -270,6 +271,8 @@ RSpec.describe Code do
|
|
|
270
271
|
%w[1.to_json "1"],
|
|
271
272
|
%w[1.0.to_json '"1.0"'],
|
|
272
273
|
%w[1.1.to_json '"1.1"'],
|
|
274
|
+
["a = {} a.merge!(a: 1) a", "{a: 1}"],
|
|
275
|
+
["a = {} a.merge(a: 1) a", "{}"],
|
|
273
276
|
["", ""]
|
|
274
277
|
].each do |input, expected|
|
|
275
278
|
it "#{input} == #{expected}" do
|