eitil 1.1.6 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56c74ebd746f3df95bb5db69eea9c32c894c3a360c4f3da75d2fd5e776834800
4
- data.tar.gz: a61655e6fab7305708443fe00918513cf42ebd04bddf9f5114b7f346edc8a347
3
+ metadata.gz: 533d4d3d52d6d7559bdc922092cfad8ccad7cd525146d6dcf7375a6b2f2a7bf3
4
+ data.tar.gz: fbea7ab7c1ec676116f0b4c4465c8e1c6b89426bcd0b6ccc092e80432d1e7d2b
5
5
  SHA512:
6
- metadata.gz: 247df55a479fa73e45cba14dc6dd902b8e334d7ec4f9faa4a67142015489498abbd1a17b3f08053326837e47677e1886a5e2663e3d496ae0e98ba5a20feffefc
7
- data.tar.gz: 5844f97ccf79c3ccb7e4c9f7724fc2b9ff005e51e703477d4734b692b7180e4257fb81744a7a12ed4b292ab793fecb89f6d5f95d4f4866ddca6524ba4c57aeba
6
+ metadata.gz: 9ba784b5a5dd993b948e2eecd4cd992f28e43e2d253f90394b60740fc79d947d579b8910ae50c05c3f85367d058ad1d9b78ef6f3d246bc1e161542d836d2324e
7
+ data.tar.gz: db2c1be663f34dedfeb32a08f4c91dbd8f1830188c37977491100715c45c6a4ec259e983e42cb5e13f1563a82e602c302df02ae3ce2da23982a5500c07aed5bd
data/eitil_core/README.md CHANGED
@@ -161,6 +161,23 @@ args_to_ivars!(*local_vars)
161
161
  ```
162
162
 
163
163
 
164
+ ## Concerns
165
+
166
+ ```ruby
167
+
168
+ require "eitil_core/array"
169
+
170
+ ```
171
+
172
+ ```ruby
173
+ # require "eitil_core/array/slice_hashes"
174
+
175
+ slice_hashes(*keys)
176
+ # uses the given keys to slice each hash in the array of hashes
177
+ # call as: [{"a"=>1, "b"=>2, "c"=>3}, {"a"=>1, "b"=>2, "c"=>3}].slice_hashes("a", "b")
178
+ # => [{"a"=>1, "b"=>2}, {"a"=>1, "b"=>2}]
179
+ ```
180
+
164
181
  ## Concerns
165
182
 
166
183
  ```ruby
@@ -217,6 +234,24 @@ raise_error(_class_name, message = nil)
217
234
  ```
218
235
 
219
236
 
237
+ ## Files
238
+
239
+ ```ruby
240
+
241
+ require "eitil_core/files"
242
+
243
+ ```
244
+
245
+ ```ruby
246
+ # require "eitil_core/files/create_file"
247
+
248
+ create_file(file_name, data, directory: nil, suffix: nil, file_type: nil, append: false)
249
+ # writes data to a file (new or existing), with "#{Dir.home}/data" as default directory and with a timestamp as default suffix
250
+ # call as: create_file('test_file', {a: 1, b: {c: 2}}, append: true)
251
+ # => /Users/jurriaanschrofer/data/test_file__2021-06-30.17:30:49.json
252
+ ```
253
+
254
+
220
255
  ## Float
221
256
 
222
257
  ```ruby
@@ -2,6 +2,7 @@
2
2
  # require "eitil_core"
3
3
 
4
4
  # core class patches
5
+ require "eitil_core/array"
5
6
  require "eitil_core/hash"
6
7
  require "eitil_core/float"
7
8
  require "eitil_core/datetime"
@@ -24,4 +25,4 @@ require "eitil_core/setters"
24
25
  require "eitil_core/validations"
25
26
  require "eitil_core/lookups"
26
27
  require "eitil_core/concerns"
27
-
28
+ require "eitil_core/files"
@@ -0,0 +1,2 @@
1
+
2
+ require "eitil_core/array/slice_hashes"
@@ -0,0 +1,18 @@
1
+
2
+ # require "eitil_core/array/slice_hashes"
3
+
4
+ class Array
5
+
6
+ def slice_hashes(*keys)
7
+
8
+ return self if self.empty?
9
+
10
+ unless self.all? { |item| item.is_a? Hash }
11
+ raise ArgumentError, "Array#slice_hashes requires that all array items are Hash instances"
12
+ end
13
+
14
+ self.map { |item| item.slice(*keys) }
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,2 @@
1
+
2
+ require "eitil_core/files/create_file"
@@ -0,0 +1,28 @@
1
+
2
+ # require "eitil_core/files/create_file"
3
+
4
+ Kernel.module_eval do
5
+
6
+ def create_file(file_name, data, directory: nil, suffix: nil, file_type: nil, append: false)
7
+
8
+ directory = directory || "#{Dir.home}/data"
9
+ suffix = suffix || DateTime.now.prettify
10
+ file_type = file_type || "json"
11
+
12
+ if file_type = "json"
13
+ data = JSON.pretty_generate(data)
14
+ end
15
+
16
+ path = "#{directory}/#{file_name}_#{suffix}.#{file_type}"
17
+
18
+ if append and Dir[path].present?
19
+ File.open(path, "a+") { |f| f << data }
20
+ return path
21
+ end
22
+
23
+ File.write(path, data)
24
+ return path
25
+
26
+ end
27
+
28
+ end
@@ -1,3 +1,4 @@
1
1
 
2
2
  require "eitil_core/safe_executions/safe_send"
3
- require "eitil_core/safe_executions/safe_call"
3
+ require "eitil_core/safe_executions/safe_call"
4
+ require "eitil_core/safe_executions/safe_rescue"
@@ -0,0 +1,37 @@
1
+
2
+ # require "eitil_core/safe_executions/safe_rescue"
3
+
4
+ Kernel.module_eval do
5
+
6
+ # WORK IN PROCESS
7
+ # => accept a second block, prefarabbly not as proc, with code to be exceuted in case of rescue
8
+ # => or would it be possible to patch the 'rescue' keyword itself, so that we don't have to accept
9
+ # blocks as arguments?
10
+
11
+ def safe_rescue(error, &blk)
12
+
13
+ unless blk
14
+ raise ArgumentError, "a block should be passed"
15
+ end
16
+
17
+ unless error.is_a?(Class) or error.is_a?(String)
18
+ raise ArgumentError, "the given 'error' should either be a constant or string"
19
+ end
20
+
21
+ if error.is_a?(Class)
22
+ error_const = error
23
+
24
+ elsif error.is_a?(String) and Object.const_defined?(error)
25
+ error_const = error.constantize
26
+
27
+ elsif error.is_a?(String)
28
+ error_const = Object.const_set(error, Class.new(StandardError))
29
+
30
+ end
31
+
32
+ blk.call
33
+
34
+ rescue error_const
35
+ end
36
+
37
+ end
@@ -59,7 +59,7 @@ The Eitil jobs wrapper enables you to create perform_now and perform_later jobs
59
59
 
60
60
  The macro new_job accepts a :method as argument and defines a new method :method_job. The newly defined :method_job, when called, performs the orginal :method in the background. The new_job macro accepts both instance methods and singleton methods, which are defined within there own method scope.
61
61
 
62
- In contrast, the new_job_debugger macro defines a new :method_job_debugger method, which performs in the foreground.
62
+ In contrast, the new_job_now macro defines a new :method_job_now method, which performs in the foreground.
63
63
 
64
64
  ```ruby
65
65
  # require "eitil_wrapper/jobs/new_job"
@@ -70,11 +70,11 @@ new_job(_method, *args, **kwargs)
70
70
  ```
71
71
 
72
72
  ```ruby
73
- # require "eitil_wrapper/jobs/new_job_debugger"
73
+ # require "eitil_wrapper/jobs/new_job_now"
74
74
 
75
- new_job_debugger(_method, *args, **kwargs)
76
- # assuming a method :hello_world, call as: new_job_debugger :hello_world
77
- # => defines :hello_world_job_debugger
75
+ new_job_now(_method, *args, **kwargs)
76
+ # assuming a method :hello_world, call as: new_job_now :hello_world
77
+ # => defines :hello_world_job_now
78
78
  ```
79
79
 
80
80
 
@@ -1,4 +1,4 @@
1
1
 
2
2
  require "eitil_wrapper/jobs/new_job"
3
- require "eitil_wrapper/jobs/new_job_debugger"
3
+ require "eitil_wrapper/jobs/new_job_now"
4
4
  require "eitil_wrapper/jobs/single_method_job"
@@ -1,5 +1,5 @@
1
1
 
2
- # require "eitil_wrapper/jobs/new_job_debugger"
2
+ # require "eitil_wrapper/jobs/new_job_now"
3
3
 
4
4
  require "eitil_wrapper/jobs/single_method_job"
5
5
 
@@ -14,10 +14,10 @@ Kernel.module_eval do
14
14
  # being that 'id' works for objects that have a database record, while '_self'
15
15
  # works for non database supported instanes, such as an Exporter instance.
16
16
 
17
- def new_job_debugger(_method, *args, **kwargs)
17
+ def new_job_now(_method, *args, **kwargs)
18
18
 
19
19
  if instance_methods(false).include? _method
20
- define_method "#{_method}_job_debugger" do |_self = nil, *args, **kwargs|
20
+ define_method "#{_method}_job_now" do |_self = nil, *args, **kwargs|
21
21
 
22
22
  EitilWrapper::SingleMethodJob.perform_now(
23
23
  *args, _class: self.class.to_s, _method: _method.to_s, id: safe_send(:id), _self: self.to_json, **kwargs
@@ -25,7 +25,7 @@ Kernel.module_eval do
25
25
  end
26
26
 
27
27
  elsif singleton_methods(false).include? _method
28
- define_singleton_method "#{_method}_job_debugger" do |*args, **kwargs|
28
+ define_singleton_method "#{_method}_job_now" do |*args, **kwargs|
29
29
 
30
30
  EitilWrapper::SingleMethodJob.perform_now(
31
31
  *args, _class: to_s, _method: _method.to_s, **kwargs
@@ -36,7 +36,20 @@ module EitilWrapper
36
36
  else
37
37
  _class.constantize
38
38
  end
39
- object.send _method, *args, **kwargs
39
+
40
+ if args.present? and kwargs.present?
41
+ object.send _method, *args, **kwargs
42
+
43
+ elsif args.present?
44
+ object.send _method, *args
45
+
46
+ elsif kwargs.present?
47
+ object.send _method, **kwargs
48
+
49
+ else
50
+ object.send _method
51
+ end
52
+
40
53
  end; end; end; end
41
54
 
42
55
 
data/lib/eitil/all.rb CHANGED
@@ -7,7 +7,7 @@ Eitil::Layers.each do |layer|
7
7
  begin
8
8
  require "#{layer}/railtie"
9
9
  require "#{layer}"
10
- puts "succesfully required #{layer} and #{layer}/railtie" if Rails.env.development?
10
+ # puts "succesfully required #{layer} and #{layer}/railtie" if Rails.env.development?
11
11
 
12
12
  rescue LoadError => e
13
13
  puts "failed to require #{layer} and #{layer}/railtie"
data/lib/eitil/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Eitil
2
2
 
3
- VERSION = '1.1.6'
3
+ VERSION = '1.1.7'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eitil
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurriaan Schrofer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-30 00:00:00.000000000 Z
11
+ date: 2021-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -101,12 +101,16 @@ files:
101
101
  - eitil_core/lib/eitil_core/argument_helpers/args_to_h_bang.rb
102
102
  - eitil_core/lib/eitil_core/argument_helpers/args_to_ivars.rb
103
103
  - eitil_core/lib/eitil_core/argument_helpers/args_to_ivars_bang.rb
104
+ - eitil_core/lib/eitil_core/array.rb
105
+ - eitil_core/lib/eitil_core/array/slice_hashes.rb
104
106
  - eitil_core/lib/eitil_core/concerns.rb
105
107
  - eitil_core/lib/eitil_core/concerns/include_concerns_of.rb
106
108
  - eitil_core/lib/eitil_core/datetime.rb
107
109
  - eitil_core/lib/eitil_core/datetime/prettify.rb
108
110
  - eitil_core/lib/eitil_core/errors.rb
109
111
  - eitil_core/lib/eitil_core/errors/raise_error.rb
112
+ - eitil_core/lib/eitil_core/files.rb
113
+ - eitil_core/lib/eitil_core/files/create_file.rb
110
114
  - eitil_core/lib/eitil_core/float.rb
111
115
  - eitil_core/lib/eitil_core/float/safe_to_i.rb
112
116
  - eitil_core/lib/eitil_core/formatters.rb
@@ -123,6 +127,7 @@ files:
123
127
  - eitil_core/lib/eitil_core/railtie.rb
124
128
  - eitil_core/lib/eitil_core/safe_executions.rb
125
129
  - eitil_core/lib/eitil_core/safe_executions/safe_call.rb
130
+ - eitil_core/lib/eitil_core/safe_executions/safe_rescue.rb
126
131
  - eitil_core/lib/eitil_core/safe_executions/safe_send.rb
127
132
  - eitil_core/lib/eitil_core/setters.rb
128
133
  - eitil_core/lib/eitil_core/setters/set_ivars.rb
@@ -175,7 +180,7 @@ files:
175
180
  - eitil_wrapper/lib/eitil_wrapper/decorators/controller_decorator.rb
176
181
  - eitil_wrapper/lib/eitil_wrapper/jobs.rb
177
182
  - eitil_wrapper/lib/eitil_wrapper/jobs/new_job.rb
178
- - eitil_wrapper/lib/eitil_wrapper/jobs/new_job_debugger.rb
183
+ - eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
179
184
  - eitil_wrapper/lib/eitil_wrapper/jobs/single_method_job.rb
180
185
  - eitil_wrapper/lib/eitil_wrapper/railtie.rb
181
186
  - eitil_wrapper/lib/eitil_wrapper/request_logger.rb