code-ruby 1.9.5 → 1.9.7
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/VERSION +1 -1
- data/lib/code/object/date.rb +15 -1
- data/lib/code/object/identifier_list.rb +88 -21
- data/lib/code/object/time.rb +19 -1
- data/spec/code_spec.rb +7 -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: 6333e864ab7337464252aefef70ff9d3bd5adbfa56a6824f26800a19e5edc776
|
|
4
|
+
data.tar.gz: 6556133a0bf11f1651f693d9af6edce9781f2c5b90a842fb46dbd0a45061034d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a4e8152a05e0f67801282b08d1ebc4a2ed8ebbb346d15cdb976f4e201a0358658922d7f457faf6b7bfe5d9e65f7d135a3b97741dcdc8ce10706c302e0e19fa8d
|
|
7
|
+
data.tar.gz: f24a4f62f8eac88f50c6627f07969deeb92a3a0e95d5f4b77769aa78b28f27136c13b573db5fb46a1737064af2be2eeedc62f3a0a16ebcf28ec24bce3674dcff
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.9.
|
|
1
|
+
1.9.7
|
data/lib/code/object/date.rb
CHANGED
|
@@ -7,6 +7,7 @@ class Code
|
|
|
7
7
|
|
|
8
8
|
class << self
|
|
9
9
|
delegate(
|
|
10
|
+
:code_zone,
|
|
10
11
|
:code_format,
|
|
11
12
|
:code_past?,
|
|
12
13
|
:code_future?,
|
|
@@ -84,6 +85,13 @@ class Code
|
|
|
84
85
|
code_second = code_arguments.code_second
|
|
85
86
|
|
|
86
87
|
case code_operator.to_s
|
|
88
|
+
when "zone="
|
|
89
|
+
sig(args) { String }
|
|
90
|
+
::Time.zone = code_value.raw
|
|
91
|
+
code_value
|
|
92
|
+
when "zone"
|
|
93
|
+
sig(args)
|
|
94
|
+
code_zone
|
|
87
95
|
when "after?"
|
|
88
96
|
sig(args) { (Date | Time).maybe }
|
|
89
97
|
code_after?(code_value)
|
|
@@ -334,6 +342,9 @@ class Code
|
|
|
334
342
|
code_second = code_arguments.code_second
|
|
335
343
|
|
|
336
344
|
case code_operator.to_s
|
|
345
|
+
when "zone"
|
|
346
|
+
sig(args)
|
|
347
|
+
code_zone
|
|
337
348
|
when "after?"
|
|
338
349
|
sig(args) { (Date | Time).maybe }
|
|
339
350
|
code_after?(code_value)
|
|
@@ -706,7 +717,6 @@ class Code
|
|
|
706
717
|
|
|
707
718
|
requested_locale = code_locale.raw&.to_s
|
|
708
719
|
locale = requested_locale&.presence_in(LOCALES)&.to_sym
|
|
709
|
-
locale ||= ::Current.locale if defined?(::Current)
|
|
710
720
|
locale ||= ::I18n.locale
|
|
711
721
|
locale = ::I18n.locale unless ::I18n.available_locales.include?(locale.to_sym)
|
|
712
722
|
|
|
@@ -859,6 +869,10 @@ class Code
|
|
|
859
869
|
|
|
860
870
|
Date.new(dup)
|
|
861
871
|
end
|
|
872
|
+
|
|
873
|
+
def code_zone
|
|
874
|
+
String.new(::Time.zone.name)
|
|
875
|
+
end
|
|
862
876
|
end
|
|
863
877
|
end
|
|
864
878
|
end
|
|
@@ -12,32 +12,99 @@ class Code
|
|
|
12
12
|
case code_operator.to_s
|
|
13
13
|
when /=$/
|
|
14
14
|
sig(args) { Object }
|
|
15
|
+
assignment_operator = code_operator.to_s
|
|
16
|
+
context = find_context_with_identifier(code_context, raw.first)
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
code_value
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
operator: code_operator.to_s.chop,
|
|
31
|
-
arguments: [code_value]
|
|
32
|
-
)
|
|
33
|
-
end
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
code_context.code_fetch(raw.last)
|
|
18
|
+
if context
|
|
19
|
+
assign_in_context(
|
|
20
|
+
context: context,
|
|
21
|
+
assignment_operator: assignment_operator,
|
|
22
|
+
code_value: code_value,
|
|
23
|
+
**args
|
|
24
|
+
)
|
|
25
|
+
else
|
|
26
|
+
assign_with_setter(
|
|
27
|
+
assignment_operator: assignment_operator,
|
|
28
|
+
code_value: code_value,
|
|
29
|
+
**args
|
|
30
|
+
)
|
|
31
|
+
end
|
|
37
32
|
else
|
|
38
33
|
super
|
|
39
34
|
end
|
|
40
35
|
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def find_context_with_identifier(context, identifier)
|
|
40
|
+
current = context
|
|
41
|
+
|
|
42
|
+
while current
|
|
43
|
+
return current if current.code_has_key?(identifier).truthy?
|
|
44
|
+
|
|
45
|
+
current = current.parent
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
nil
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def assign_in_context(context:, assignment_operator:, code_value:, **args)
|
|
52
|
+
receiver =
|
|
53
|
+
raw[..-2].reduce(context) do |value, code_identifier|
|
|
54
|
+
value.code_fetch(code_identifier)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
receiver.code_set(
|
|
58
|
+
raw.last,
|
|
59
|
+
if assignment_operator == "="
|
|
60
|
+
code_value
|
|
61
|
+
else
|
|
62
|
+
receiver.code_fetch(raw.last).call(
|
|
63
|
+
**args,
|
|
64
|
+
operator: assignment_operator.chop,
|
|
65
|
+
arguments: [code_value]
|
|
66
|
+
)
|
|
67
|
+
end
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
receiver.code_fetch(raw.last)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def assign_with_setter(assignment_operator:, code_value:, **args)
|
|
74
|
+
code_object = args.fetch(:object)
|
|
75
|
+
receiver =
|
|
76
|
+
raw[...-1].reduce(code_object) do |value, code_identifier|
|
|
77
|
+
value.call(
|
|
78
|
+
**args,
|
|
79
|
+
operator: code_identifier,
|
|
80
|
+
arguments: Object::List.new
|
|
81
|
+
)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
if assignment_operator == "="
|
|
85
|
+
receiver.call(
|
|
86
|
+
**args,
|
|
87
|
+
operator: "#{raw.last}=",
|
|
88
|
+
arguments: Object::List.new([code_value])
|
|
89
|
+
)
|
|
90
|
+
else
|
|
91
|
+
next_value = receiver.call(
|
|
92
|
+
**args,
|
|
93
|
+
operator: raw.last,
|
|
94
|
+
arguments: Object::List.new
|
|
95
|
+
).call(
|
|
96
|
+
**args,
|
|
97
|
+
operator: assignment_operator.chop,
|
|
98
|
+
arguments: Object::List.new([code_value])
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
receiver.call(
|
|
102
|
+
**args,
|
|
103
|
+
operator: "#{raw.last}=",
|
|
104
|
+
arguments: Object::List.new([next_value])
|
|
105
|
+
)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
41
108
|
end
|
|
42
109
|
end
|
|
43
110
|
end
|
data/lib/code/object/time.rb
CHANGED
|
@@ -97,6 +97,14 @@ class Code
|
|
|
97
97
|
code_second = code_arguments.code_second
|
|
98
98
|
|
|
99
99
|
case code_operator.to_s
|
|
100
|
+
when "zone="
|
|
101
|
+
sig(args) { String }
|
|
102
|
+
::Time.zone = code_value.raw
|
|
103
|
+
code_value
|
|
104
|
+
when "zone"
|
|
105
|
+
sig(args)
|
|
106
|
+
::Time.zone ||= DEFAULT_ZONE
|
|
107
|
+
code_zone
|
|
100
108
|
when "after?"
|
|
101
109
|
sig(args) { (Date | Time).maybe }
|
|
102
110
|
code_after?(code_value)
|
|
@@ -370,6 +378,10 @@ class Code
|
|
|
370
378
|
end
|
|
371
379
|
end
|
|
372
380
|
|
|
381
|
+
def self.code_zone
|
|
382
|
+
String.new(::Time.zone.name)
|
|
383
|
+
end
|
|
384
|
+
|
|
373
385
|
def call(**args)
|
|
374
386
|
code_operator = args.fetch(:operator, nil).to_code
|
|
375
387
|
code_arguments = args.fetch(:arguments, []).to_code
|
|
@@ -377,6 +389,9 @@ class Code
|
|
|
377
389
|
code_second = code_arguments.code_second
|
|
378
390
|
|
|
379
391
|
case code_operator.to_s
|
|
392
|
+
when "zone"
|
|
393
|
+
sig(args)
|
|
394
|
+
code_zone
|
|
380
395
|
when "after?"
|
|
381
396
|
sig(args) { (Date | Time).maybe }
|
|
382
397
|
code_after?(code_value)
|
|
@@ -815,7 +830,6 @@ class Code
|
|
|
815
830
|
|
|
816
831
|
requested_locale = code_locale.raw&.to_s
|
|
817
832
|
locale = requested_locale&.presence_in(LOCALES)&.to_sym
|
|
818
|
-
locale ||= ::Current.locale if defined?(::Current)
|
|
819
833
|
locale ||= ::I18n.locale
|
|
820
834
|
locale = ::I18n.locale unless ::I18n.available_locales.include?(locale.to_sym)
|
|
821
835
|
|
|
@@ -998,6 +1012,10 @@ class Code
|
|
|
998
1012
|
|
|
999
1013
|
Time.new(dup)
|
|
1000
1014
|
end
|
|
1015
|
+
|
|
1016
|
+
def code_zone
|
|
1017
|
+
String.new(raw.zone)
|
|
1018
|
+
end
|
|
1001
1019
|
end
|
|
1002
1020
|
end
|
|
1003
1021
|
end
|
data/spec/code_spec.rb
CHANGED
|
@@ -464,6 +464,7 @@ RSpec.describe Code do
|
|
|
464
464
|
["subject = 1 { subject }", "{ subject: 1 }"],
|
|
465
465
|
["subject = 1 { subject: }", "{ subject: 1 }"],
|
|
466
466
|
["'{1} {2}'", "'1 2'"],
|
|
467
|
+
['Time.zone = "Etc/UTC"', '"Etc/UTC"'],
|
|
467
468
|
%w[Json.parse("1") 1],
|
|
468
469
|
%w[{a:1}.to_query "a=1"],
|
|
469
470
|
["", ""]
|
|
@@ -532,4 +533,10 @@ RSpec.describe Code do
|
|
|
532
533
|
described_class.evaluate(input)
|
|
533
534
|
described_class.evaluate(format_input(input))
|
|
534
535
|
end
|
|
536
|
+
|
|
537
|
+
it "raises for undefined constant receiver assignment" do
|
|
538
|
+
expect do
|
|
539
|
+
described_class.evaluate("UnknownConstant.zone = 1")
|
|
540
|
+
end.to raise_error(Code::Error, /UnknownConstant is not defined/)
|
|
541
|
+
end
|
|
535
542
|
end
|