code-ruby 0.7.8 → 0.8.1
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/lib/code/object/class.rb +9 -11
- data/lib/code/object/date.rb +12 -0
- data/lib/code/object/time.rb +12 -0
- data/lib/code/object.rb +146 -1
- data/lib/code/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 53530542bdf5a824a43456c8a1d16ef187c0e040f614d797caf0316d821611fc
|
|
4
|
+
data.tar.gz: 7c21efbe6de1846a76ee403a59c9c1e90f0259af2523d4bbbee21759a6bf99c6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 85ea6c55e13230861d8d6c3aa8a80dca114c382edcf9a2c2781e7fbb74d924027756e47b418a4ce69e05d63f93ca1957fe086aa62d831ec8226f52fba4b805fd
|
|
7
|
+
data.tar.gz: afa54fcd58082f980d7dc72d4cfd06c61a73f26aeb88700e8d87928ebaeb02c3c4b42d08c9bcb0284807e2f795f4d30ebe20d5a7e3b892b3bdf5235cfb418747
|
data/lib/code/object/class.rb
CHANGED
|
@@ -9,18 +9,16 @@ class Code
|
|
|
9
9
|
@raw = raw
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def call(
|
|
13
|
-
|
|
12
|
+
def call(...)
|
|
13
|
+
raw.call(...)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_s
|
|
17
|
+
raw.name
|
|
18
|
+
end
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Time.code_tomorrow
|
|
18
|
-
elsif raw == Date && operator.to_s == "tomorrow"
|
|
19
|
-
sig(args)
|
|
20
|
-
Date.code_tomorrow
|
|
21
|
-
else
|
|
22
|
-
super
|
|
23
|
-
end
|
|
20
|
+
def inspect
|
|
21
|
+
to_s
|
|
24
22
|
end
|
|
25
23
|
|
|
26
24
|
def self.name
|
data/lib/code/object/date.rb
CHANGED
|
@@ -13,6 +13,18 @@ class Code
|
|
|
13
13
|
"Date"
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
def self.call(**args)
|
|
17
|
+
operator = args.fetch(:operator, nil)
|
|
18
|
+
|
|
19
|
+
case operator.to_s
|
|
20
|
+
when "tomorrow"
|
|
21
|
+
sig(args)
|
|
22
|
+
code_tomorrow
|
|
23
|
+
else
|
|
24
|
+
super
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
16
28
|
def self.code_tomorrow
|
|
17
29
|
::Time.zone ||= Time::DEFAULT_ZONE
|
|
18
30
|
new(::Time.zone.tomorrow)
|
data/lib/code/object/time.rb
CHANGED
|
@@ -15,6 +15,18 @@ class Code
|
|
|
15
15
|
"Time"
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
def self.call(**args)
|
|
19
|
+
operator = args.fetch(:operator, nil)
|
|
20
|
+
|
|
21
|
+
case operator.to_s
|
|
22
|
+
when "tomorrow"
|
|
23
|
+
sig(args)
|
|
24
|
+
code_tomorrow
|
|
25
|
+
else
|
|
26
|
+
super
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
18
30
|
def self.code_tomorrow
|
|
19
31
|
::Time.zone ||= DEFAULT_ZONE
|
|
20
32
|
new(::Time.zone.tomorrow.beginning_of_day)
|
data/lib/code/object.rb
CHANGED
|
@@ -18,6 +18,147 @@ class Code
|
|
|
18
18
|
Type::Or.new(self, other)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
def self.sig(args, &block)
|
|
22
|
+
Type::Sig.sig(args, object: self, &block)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.call(**args)
|
|
26
|
+
operator = args.fetch(:operator, nil)
|
|
27
|
+
arguments = args.fetch(:arguments, [])
|
|
28
|
+
value = arguments.first&.value
|
|
29
|
+
|
|
30
|
+
case operator.to_s
|
|
31
|
+
when "!", "not"
|
|
32
|
+
sig(args)
|
|
33
|
+
code_exclamation_point
|
|
34
|
+
when "!=", "different"
|
|
35
|
+
sig(args) { Object }
|
|
36
|
+
code_different(value)
|
|
37
|
+
when "&&", "and"
|
|
38
|
+
sig(args) { Object }
|
|
39
|
+
code_and_operator(value)
|
|
40
|
+
when "+", "self"
|
|
41
|
+
sig(args)
|
|
42
|
+
code_self
|
|
43
|
+
when "..", "inclusive_range"
|
|
44
|
+
sig(args) { Object }
|
|
45
|
+
code_inclusive_range(value)
|
|
46
|
+
when "...", "exclusive_range"
|
|
47
|
+
sig(args) { Object }
|
|
48
|
+
code_exclusive_range(value)
|
|
49
|
+
when "==", "equal"
|
|
50
|
+
sig(args) { Object }
|
|
51
|
+
code_equal_equal(value)
|
|
52
|
+
when "===", "strict_equal"
|
|
53
|
+
sig(args) { Object }
|
|
54
|
+
code_equal_equal_equal(value)
|
|
55
|
+
when "falsy?"
|
|
56
|
+
sig(args)
|
|
57
|
+
Boolean.new(falsy?)
|
|
58
|
+
when "to_string"
|
|
59
|
+
sig(args)
|
|
60
|
+
code_to_string
|
|
61
|
+
when "truthy?"
|
|
62
|
+
sig(args)
|
|
63
|
+
Boolean.new(truthy?)
|
|
64
|
+
when "||", "or"
|
|
65
|
+
sig(args) { Object }
|
|
66
|
+
code_or_operator(value)
|
|
67
|
+
when /=$/
|
|
68
|
+
sig(args) { Object }
|
|
69
|
+
|
|
70
|
+
if operator == "="
|
|
71
|
+
context = args[:context]
|
|
72
|
+
context.code_set(self, value)
|
|
73
|
+
else
|
|
74
|
+
context = args[:context].lookup!(self)
|
|
75
|
+
context.code_set(
|
|
76
|
+
self,
|
|
77
|
+
context.code_fetch(self).call(
|
|
78
|
+
**args,
|
|
79
|
+
operator: operator[..-2],
|
|
80
|
+
arguments: [Argument.new(value)]
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context.code_fetch(self)
|
|
86
|
+
else
|
|
87
|
+
raise(
|
|
88
|
+
Code::Error::Undefined,
|
|
89
|
+
"#{operator} not defined on #{inspect}:Class"
|
|
90
|
+
)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def self.code_and_operator(other)
|
|
95
|
+
truthy? ? other : self
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def self.code_different(other)
|
|
99
|
+
Boolean.new(self != other)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def self.code_equal_equal(other)
|
|
103
|
+
Boolean.new(self == other)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def self.code_exclamation_point
|
|
107
|
+
Boolean.new(falsy?)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def self.code_exclusive_range(value)
|
|
111
|
+
Range.new(self, value, exclude_end: true)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def self.code_inclusive_range(value)
|
|
115
|
+
Range.new(self, value, exclude_end: false)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def self.code_or_operator(other)
|
|
119
|
+
truthy? ? self : other
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def self.code_self
|
|
123
|
+
self
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def self.code_equal_equal_equal(other)
|
|
127
|
+
Boolean.new(self === other)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def self.code_to_string
|
|
131
|
+
String.new(to_s)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def self.falsy?
|
|
135
|
+
!truthy?
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def self.multi_fetch(hash, *keys)
|
|
139
|
+
keys.map { |key| [key, hash.fetch(key)] }.to_h
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def self.sig(args, &block)
|
|
143
|
+
Type::Sig.sig(args, object: self, &block)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def self.name
|
|
147
|
+
raise NotImplementedError, "name"
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def self.to_s
|
|
151
|
+
name
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def self.inspect
|
|
155
|
+
to_s
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def self.truthy?
|
|
159
|
+
true
|
|
160
|
+
end
|
|
161
|
+
|
|
21
162
|
def <=>(other)
|
|
22
163
|
if respond_to?(:raw)
|
|
23
164
|
raw <=> (other.respond_to?(:raw) ? other.raw : other)
|
|
@@ -117,7 +258,7 @@ class Code
|
|
|
117
258
|
end
|
|
118
259
|
|
|
119
260
|
def code_exclamation_point
|
|
120
|
-
|
|
261
|
+
Boolean.new(falsy?)
|
|
121
262
|
end
|
|
122
263
|
|
|
123
264
|
def code_exclusive_range(value)
|
|
@@ -168,6 +309,10 @@ class Code
|
|
|
168
309
|
raise NotImplementedError, "#{self.class.name}#to_s"
|
|
169
310
|
end
|
|
170
311
|
|
|
312
|
+
def inspect
|
|
313
|
+
to_s
|
|
314
|
+
end
|
|
315
|
+
|
|
171
316
|
def truthy?
|
|
172
317
|
true
|
|
173
318
|
end
|
data/lib/code/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: code-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dorian Marié
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-02-
|
|
11
|
+
date: 2024-02-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bigdecimal
|