code-ruby 0.7.6 → 0.7.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +24 -1
- data/code-ruby.gemspec +1 -0
- data/lib/code/object/class.rb +14 -0
- data/lib/code/object/date.rb +30 -0
- data/lib/code/object/duration.rb +41 -0
- data/lib/code/object/global.rb +6 -0
- data/lib/code/object/integer.rb +7 -0
- data/lib/code/object/time.rb +32 -0
- data/lib/code/version.rb +1 -1
- data/lib/code-ruby.rb +3 -0
- data/spec/code_spec.rb +8 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bbad84793e5bbf2f414b6f151f528534f7925ae62182cb101afb3d4c3d79ef0
|
4
|
+
data.tar.gz: 76759f9e4dc4ac0a1abce13727d003930cd498933ffabe83b8b83334850e5af1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2058ad57bcd88790c5b7201c3509df3fc3ff876db19a53811a7db679e5687ff95800df13cecdc114dbd4ec4b3cec4b36c3778a7800f1568ba251f6b770a5fd9
|
7
|
+
data.tar.gz: 7628080cb943ae6169e4e859849fecabe8b4ddc0ac938cdd81f34a689938d6caf3bfd56c0f3d25a76088a6f18789b1309bc80e94ca99922882733bc9ab6b6abc
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
code-ruby (0.7.
|
4
|
+
code-ruby (0.7.8)
|
5
|
+
activesupport (~> 7)
|
5
6
|
bigdecimal (~> 3)
|
6
7
|
language-ruby (~> 0)
|
7
8
|
zeitwerk (~> 2)
|
@@ -9,10 +10,29 @@ PATH
|
|
9
10
|
GEM
|
10
11
|
remote: https://rubygems.org/
|
11
12
|
specs:
|
13
|
+
activesupport (7.1.3)
|
14
|
+
base64
|
15
|
+
bigdecimal
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
connection_pool (>= 2.2.5)
|
18
|
+
drb
|
19
|
+
i18n (>= 1.6, < 2)
|
20
|
+
minitest (>= 5.1)
|
21
|
+
mutex_m
|
22
|
+
tzinfo (~> 2.0)
|
23
|
+
base64 (0.2.0)
|
12
24
|
bigdecimal (3.1.6)
|
25
|
+
concurrent-ruby (1.2.3)
|
26
|
+
connection_pool (2.4.1)
|
13
27
|
diff-lcs (1.5.1)
|
28
|
+
drb (2.2.0)
|
29
|
+
ruby2_keywords
|
30
|
+
i18n (1.14.1)
|
31
|
+
concurrent-ruby (~> 1.0)
|
14
32
|
language-ruby (0.6.2)
|
15
33
|
zeitwerk (~> 2)
|
34
|
+
minitest (5.22.2)
|
35
|
+
mutex_m (0.2.0)
|
16
36
|
rspec (3.13.0)
|
17
37
|
rspec-core (~> 3.13.0)
|
18
38
|
rspec-expectations (~> 3.13.0)
|
@@ -27,6 +47,9 @@ GEM
|
|
27
47
|
rspec-support (~> 3.13.0)
|
28
48
|
rspec-support (3.13.0)
|
29
49
|
ruby-prof (1.7.0)
|
50
|
+
ruby2_keywords (0.0.5)
|
51
|
+
tzinfo (2.0.6)
|
52
|
+
concurrent-ruby (~> 1.0)
|
30
53
|
zeitwerk (2.6.13)
|
31
54
|
|
32
55
|
PLATFORMS
|
data/code-ruby.gemspec
CHANGED
data/lib/code/object/class.rb
CHANGED
@@ -9,6 +9,20 @@ class Code
|
|
9
9
|
@raw = raw
|
10
10
|
end
|
11
11
|
|
12
|
+
def call(**args)
|
13
|
+
operator = args.fetch(:operator, nil)
|
14
|
+
|
15
|
+
if raw == Time && operator.to_s == "tomorrow"
|
16
|
+
sig(args)
|
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
|
24
|
+
end
|
25
|
+
|
12
26
|
def self.name
|
13
27
|
"Class"
|
14
28
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Code
|
4
|
+
class Object
|
5
|
+
class Date < Object
|
6
|
+
attr_reader :raw
|
7
|
+
|
8
|
+
def initialize(date)
|
9
|
+
@raw = date
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.name
|
13
|
+
"Date"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.code_tomorrow
|
17
|
+
::Time.zone ||= Time::DEFAULT_ZONE
|
18
|
+
new(::Time.zone.tomorrow)
|
19
|
+
end
|
20
|
+
|
21
|
+
def inspect
|
22
|
+
to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
raw.to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Code
|
4
|
+
class Object
|
5
|
+
class Duration < Object
|
6
|
+
attr_reader :raw
|
7
|
+
|
8
|
+
def initialize(duration)
|
9
|
+
@raw = duration
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.name
|
13
|
+
"Duration"
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(**args)
|
17
|
+
operator = args.fetch(:operator, nil)
|
18
|
+
|
19
|
+
case operator.to_s
|
20
|
+
when "from_now"
|
21
|
+
sig(args)
|
22
|
+
code_from_now
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def code_from_now
|
29
|
+
Time.new(raw.from_now)
|
30
|
+
end
|
31
|
+
|
32
|
+
def inspect
|
33
|
+
to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
raw.to_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/code/object/global.rb
CHANGED
@@ -22,6 +22,9 @@ class Code
|
|
22
22
|
when "Class"
|
23
23
|
sig(args) { Object.maybe }
|
24
24
|
value ? value.code_to_class : Class.new(Class)
|
25
|
+
when "Date"
|
26
|
+
sig(args) { Object.maybe }
|
27
|
+
value ? value.code_to_date : Class.new(Date)
|
25
28
|
when "Decimal"
|
26
29
|
sig(args) { Object.maybe }
|
27
30
|
value ? value.code_to_decimal : Class.new(Decimal)
|
@@ -55,6 +58,9 @@ class Code
|
|
55
58
|
when "String"
|
56
59
|
sig(args) { Object.maybe }
|
57
60
|
value ? value.code_to_string : Class.new(String)
|
61
|
+
when "Time"
|
62
|
+
sig(args) { Object.maybe }
|
63
|
+
value ? value.code_to_time : Class.new(Time)
|
58
64
|
when "context"
|
59
65
|
sig(args) { String.maybe }
|
60
66
|
value ? context.code_get(value) || Nothing.new : context
|
data/lib/code/object/integer.rb
CHANGED
@@ -103,6 +103,9 @@ class Code
|
|
103
103
|
when "four?"
|
104
104
|
sig(args)
|
105
105
|
code_four?
|
106
|
+
when "hour", "hours"
|
107
|
+
sig(args)
|
108
|
+
code_hours
|
106
109
|
when "increment!"
|
107
110
|
sig(args) { Integer.maybe }
|
108
111
|
code_increment!(value)
|
@@ -382,6 +385,10 @@ class Code
|
|
382
385
|
Boolean.new(raw.zero?)
|
383
386
|
end
|
384
387
|
|
388
|
+
def code_hours
|
389
|
+
Duration.new(raw.hours)
|
390
|
+
end
|
391
|
+
|
385
392
|
def inspect
|
386
393
|
to_s
|
387
394
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Code
|
4
|
+
class Object
|
5
|
+
class Time < Object
|
6
|
+
DEFAULT_ZONE = "Etc/UTC"
|
7
|
+
|
8
|
+
attr_reader :raw
|
9
|
+
|
10
|
+
def initialize(time)
|
11
|
+
@raw = time
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.name
|
15
|
+
"Time"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.code_tomorrow
|
19
|
+
::Time.zone ||= DEFAULT_ZONE
|
20
|
+
new(::Time.zone.tomorrow.beginning_of_day)
|
21
|
+
end
|
22
|
+
|
23
|
+
def inspect
|
24
|
+
to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
raw.to_s
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/code/version.rb
CHANGED
data/lib/code-ruby.rb
CHANGED
@@ -5,6 +5,9 @@ require "stringio"
|
|
5
5
|
require "timeout"
|
6
6
|
require "zeitwerk"
|
7
7
|
require "language-ruby"
|
8
|
+
require "active_support"
|
9
|
+
require "active_support/core_ext/numeric/time"
|
10
|
+
require "active_support/core_ext/date/conversions"
|
8
11
|
|
9
12
|
loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
|
10
13
|
loader.ignore("#{__dir__}/code-ruby.rb")
|
data/spec/code_spec.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.7.
|
4
|
+
version: 0.7.8
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bigdecimal
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '7'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: zeitwerk
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,8 +118,10 @@ files:
|
|
104
118
|
- lib/code/object/boolean.rb
|
105
119
|
- lib/code/object/class.rb
|
106
120
|
- lib/code/object/context.rb
|
121
|
+
- lib/code/object/date.rb
|
107
122
|
- lib/code/object/decimal.rb
|
108
123
|
- lib/code/object/dictionary.rb
|
124
|
+
- lib/code/object/duration.rb
|
109
125
|
- lib/code/object/function.rb
|
110
126
|
- lib/code/object/global.rb
|
111
127
|
- lib/code/object/identifier_list.rb
|
@@ -116,6 +132,7 @@ files:
|
|
116
132
|
- lib/code/object/range.rb
|
117
133
|
- lib/code/object/ruby_function.rb
|
118
134
|
- lib/code/object/string.rb
|
135
|
+
- lib/code/object/time.rb
|
119
136
|
- lib/code/parser.rb
|
120
137
|
- lib/code/parser/addition.rb
|
121
138
|
- lib/code/parser/and_operator.rb
|