code-ruby 1.2.5 → 1.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc5cea2598154d67fcc651c39a7bfeee5b573fa52aadc4d5f975534c578ef887
4
- data.tar.gz: 5f22af50a64fba0be71573c48a5e3bcec67a75de558c239062646d6c640737c1
3
+ metadata.gz: d8f07ece7647c8a08b818c2221a625076d0108018a015c9752c3dd2b40e88a0b
4
+ data.tar.gz: 288fe4424fe0739514fc34479ecf1292b6e0277369e1b4e1bdf00445eebd18c1
5
5
  SHA512:
6
- metadata.gz: 9b20becc62e2a60a82913b8a3d9d19132c0ec9df971fe294b716646da21b3b51578536234d365b18d67cb7692f9743067091c99daaff5493804cdb676d6eea97
7
- data.tar.gz: c18685983db2eb1995ded8f30161ead10e941d43fd164a8e13b0c45afd09d9d8cf41a53e3f41b9d994ac957c190666dbe37444dcdd45d64621f662463c640701
6
+ metadata.gz: aec2589dc56ae830a82d36dd3f9005427d9ac3008381397a7b876187d990ffceb00b69a0c781a39871da3c6ffcaf53ece8749633c24b18cddf1f6993bbb79f1e
7
+ data.tar.gz: 26ac7c6070382e493c9b879807eb11962ccdd579a4ad054bacc039dda8d0e66ee05beaad14d36f192d2c41119032eda75992830a184804c8effcbd54b6bdf0eb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (1.2.5)
4
+ code-ruby (1.2.6)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.5
1
+ 1.2.6
@@ -22,7 +22,7 @@ class Code
22
22
  end
23
23
 
24
24
  def call?
25
- operator == DOT || operator == COLON_COLON
25
+ [DOT, COLON_COLON].include?(operator)
26
26
  end
27
27
 
28
28
  def safe_call?
@@ -30,11 +30,11 @@ class Code
30
30
  end
31
31
 
32
32
  def or?
33
- operator == OR_KEYWORD || operator == PIPE_PIPE
33
+ [OR_KEYWORD, PIPE_PIPE].include?(operator)
34
34
  end
35
35
 
36
36
  def and?
37
- operator == AND_KEYWORD || operator == AMPERSAND_AMPERSAND
37
+ [AND_KEYWORD, AMPERSAND_AMPERSAND].include?(operator)
38
38
  end
39
39
  end
40
40
 
@@ -169,6 +169,9 @@ class Code
169
169
  when "transform_values"
170
170
  sig(args) { Function }
171
171
  code_transform_values(code_value, **globals)
172
+ when "to_query"
173
+ sig(args) { String.maybe }
174
+ code_to_query(code_value)
172
175
  when "two?"
173
176
  sig(args)
174
177
  code_two?
@@ -632,6 +635,12 @@ class Code
632
635
  List.new(raw.to_a.map { |key_value| List.new(key_value) })
633
636
  end
634
637
 
638
+ def code_to_query(namespace = nil)
639
+ code_namespace = namespace.to_code
640
+
641
+ String.new(raw.to_query(code_namespace.raw))
642
+ end
643
+
635
644
  def code_transform_values(function, **globals)
636
645
  code_function = function.to_code
637
646
 
@@ -101,9 +101,6 @@ class Code
101
101
  when "delete"
102
102
  sig(args) { SIG }
103
103
  code_delete(*code_arguments.raw)
104
- when "connect"
105
- sig(args) { SIG }
106
- code_connect(*code_arguments.raw)
107
104
  when "options"
108
105
  sig(args) { SIG }
109
106
  code_options(*code_arguments.raw)
@@ -141,10 +138,6 @@ class Code
141
138
  code_fetch("delete", ...)
142
139
  end
143
140
 
144
- def self.code_connect(...)
145
- code_fetch("connect", ...)
146
- end
147
-
148
141
  def self.code_options(...)
149
142
  code_fetch("options", ...)
150
143
  end
@@ -192,8 +185,6 @@ class Code
192
185
  ::Net::HTTP::Put
193
186
  when "delete"
194
187
  ::Net::HTTP::Delete
195
- when "connect"
196
- ::Net::HTTP::Get
197
188
  when "options"
198
189
  ::Net::HTTP::Options
199
190
  when "trace"
@@ -117,10 +117,13 @@ class Code
117
117
  if code_argument.nothing?
118
118
  true.tap { index += 1 }
119
119
  else
120
- code_argument.call(
121
- arguments: List.new([code_element, Integer.new(index), self]),
122
- **globals
123
- ).truthy?.tap { index += 1 }
120
+ code_argument
121
+ .call(
122
+ arguments: List.new([code_element, Integer.new(index), self]),
123
+ **globals
124
+ )
125
+ .truthy?
126
+ .tap { index += 1 }
124
127
  end
125
128
  rescue Error::Next => e
126
129
  e.code_value.tap { index += 1 }
@@ -271,10 +274,13 @@ class Code
271
274
  if code_argument.nothing?
272
275
  code_element.truthy?.tap { index += 1 }
273
276
  else
274
- code_argument.call(
275
- arguments: List.new([code_element, Integer.new(index), self]),
276
- **globals
277
- ).truthy?.tap { index += 1 }
277
+ code_argument
278
+ .call(
279
+ arguments: List.new([code_element, Integer.new(index), self]),
280
+ **globals
281
+ )
282
+ .truthy?
283
+ .tap { index += 1 }
278
284
  end
279
285
  rescue Error::Next => e
280
286
  e.code_value.truthy?.tap { index += 1 }
@@ -310,10 +316,13 @@ class Code
310
316
  if code_argument.nothing?
311
317
  code_element.truthy?.tap { index += 1 }
312
318
  else
313
- code_argument.call(
314
- arguments: List.new([code_element, Integer.new(index), self]),
315
- **globals
316
- ).truthy?.tap { index += 1 }
319
+ code_argument
320
+ .call(
321
+ arguments: List.new([code_element, Integer.new(index), self]),
322
+ **globals
323
+ )
324
+ .truthy?
325
+ .tap { index += 1 }
317
326
  end
318
327
  rescue Error::Next => e
319
328
  e.code_value.truhty?.tap { index += 1 }
@@ -330,10 +339,13 @@ class Code
330
339
  if code_argument.nothing?
331
340
  code_element.truthy?.tap { index += 1 }
332
341
  else
333
- code_argument.call(
334
- arguments: List.new([code_element, Integer.new(index), self]),
335
- **globals
336
- ).truthy?.tap { index += 1 }
342
+ code_argument
343
+ .call(
344
+ arguments: List.new([code_element, Integer.new(index), self]),
345
+ **globals
346
+ )
347
+ .truthy?
348
+ .tap { index += 1 }
337
349
  end
338
350
  rescue Error::Next => e
339
351
  e.code_value.truhty?.tap { index += 1 }
@@ -23,9 +23,57 @@ class Code
23
23
  when "yesterday"
24
24
  sig(args)
25
25
  code_yesterday
26
+ when "year"
27
+ sig(args)
28
+ code_year
29
+ when "years"
30
+ sig(args)
31
+ code_years
32
+ when "month"
33
+ sig(args)
34
+ code_month
35
+ when "months"
36
+ sig(args)
37
+ code_months
38
+ when "week"
39
+ sig(args)
40
+ code_week
41
+ when "weeks"
42
+ sig(args)
43
+ code_weeks
44
+ when "week_day"
45
+ sig(args)
46
+ code_week_day
47
+ when "week_days"
48
+ sig(args)
49
+ code_week_days
50
+ when "day"
51
+ sig(args)
52
+ code_day
53
+ when "days"
54
+ sig(args)
55
+ code_days
26
56
  when "hour"
27
57
  sig(args)
28
58
  code_hour
59
+ when "hours"
60
+ sig(args)
61
+ code_hours
62
+ when "minute"
63
+ sig(args)
64
+ code_minute
65
+ when "minutes"
66
+ sig(args)
67
+ code_minutes
68
+ when "second"
69
+ sig(args)
70
+ code_second
71
+ when "seconds"
72
+ sig(args)
73
+ code_seconds
74
+ when "format"
75
+ sig(args) { String }
76
+ code_format(code_value)
29
77
  else
30
78
  super
31
79
  end
@@ -50,6 +98,74 @@ class Code
50
98
  new(::Time.zone.now)
51
99
  end
52
100
 
101
+ def self.code_year
102
+ code_now.code_year
103
+ end
104
+
105
+ def self.code_years
106
+ code_now.code_years
107
+ end
108
+
109
+ def self.code_month
110
+ code_now.code_month
111
+ end
112
+
113
+ def self.code_months
114
+ code_now.code_months
115
+ end
116
+
117
+ def self.code_week
118
+ code_now.code_week
119
+ end
120
+
121
+ def self.code_weeks
122
+ code_now.code_weeks
123
+ end
124
+
125
+ def self.code_week_day
126
+ code_now.code_week_day
127
+ end
128
+
129
+ def self.code_week_days
130
+ code_now.code_week_days
131
+ end
132
+
133
+ def self.code_day
134
+ code_now.code_day
135
+ end
136
+
137
+ def self.code_days
138
+ code_now.code_days
139
+ end
140
+
141
+ def self.code_hour
142
+ code_now.code_hour
143
+ end
144
+
145
+ def self.code_hours
146
+ code_now.code_hours
147
+ end
148
+
149
+ def self.code_minute
150
+ code_now.code_minute
151
+ end
152
+
153
+ def self.code_minutes
154
+ code_now.code_minutes
155
+ end
156
+
157
+ def self.code_second
158
+ code_now.code_second
159
+ end
160
+
161
+ def self.code_seconds
162
+ code_now.code_seconds
163
+ end
164
+
165
+ def self.code_format(format)
166
+ code_now.code_format(format)
167
+ end
168
+
53
169
  def call(**args)
54
170
  code_operator = args.fetch(:operator, nil).to_code
55
171
  code_arguments = args.fetch(:arguments, []).to_code
@@ -80,6 +196,18 @@ class Code
80
196
  when "months"
81
197
  sig(args)
82
198
  code_months
199
+ when "week"
200
+ sig(args)
201
+ code_week
202
+ when "weeks"
203
+ sig(args)
204
+ code_weeks
205
+ when "week_day"
206
+ sig(args)
207
+ code_week_day
208
+ when "week_days"
209
+ sig(args)
210
+ code_week_days
83
211
  when "day"
84
212
  sig(args)
85
213
  code_day
@@ -150,6 +278,22 @@ class Code
150
278
  Integer.new(raw.month)
151
279
  end
152
280
 
281
+ def code_week
282
+ Integer.new(raw.to_date.cweek)
283
+ end
284
+
285
+ def code_weeks
286
+ Integer.new(raw.to_date.cweek)
287
+ end
288
+
289
+ def code_week_day
290
+ Integer.new(raw.wday)
291
+ end
292
+
293
+ def code_week_days
294
+ Integer.new(raw.wday)
295
+ end
296
+
153
297
  def code_day
154
298
  Integer.new(raw.day)
155
299
  end
@@ -3,7 +3,7 @@
3
3
  require "spec_helper"
4
4
 
5
5
  RSpec.describe Code::Object::Http do
6
- %w[get head post put delete connect options trace patch].each do |verb|
6
+ %w[get head post put delete options trace patch].each do |verb|
7
7
  describe ".#{verb}" do
8
8
  {
9
9
  continue: 100,
data/spec/code_spec.rb CHANGED
@@ -17,6 +17,18 @@ RSpec.describe Code do
17
17
  Time.now.months
18
18
  Time.now.year
19
19
  Time.now.years
20
+ Time.second
21
+ Time.seconds
22
+ Time.minute
23
+ Time.minutes
24
+ Time.hour
25
+ Time.hours
26
+ Time.day
27
+ Time.days
28
+ Time.month
29
+ Time.months
30
+ Time.year
31
+ Time.years
20
32
  1.day.ago
21
33
  1.day.from_now
22
34
  1.hour.ago
@@ -329,6 +341,7 @@ RSpec.describe Code do
329
341
  ["[1, 2, 3].none?(&:even?)", "false"],
330
342
  ["'{1} {2}'", "'1 2'"],
331
343
  %w[Json.parse("1") 1],
344
+ %w[{a:1}.to_query "a=1"],
332
345
  ["", ""]
333
346
  ].each do |input, expected|
334
347
  it "#{input} == #{expected}" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-04 00:00:00.000000000 Z
10
+ date: 2025-03-24 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport