eitil 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7472becb49f3ad8ed37b1af23436257255cd050fd6d101a552fad3b35d020e38
|
4
|
+
data.tar.gz: 3508a76cd84733740cc9b8e9be223406ec4f620f38d9ba86048118743c058dd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52c7c51884686864b8b1aede6fc70a03028636614ef309ef59f9a70336091bd1e122ca2e7ccd99dcd824e371c60a83db73924cda249c373fda62b6f548af32fd
|
7
|
+
data.tar.gz: 47071fee4cd78efdda04753406985bb093150b70e4d1bcfd355091f3c402cd08603a508c234e3dec2d9d324c1e2a23f0f86c2ae33d1bd914b0c5f1d3631d0de6
|
data/README.md
CHANGED
@@ -50,15 +50,21 @@ args_to_ivars(binding, *local_vars)
|
|
50
50
|
# sets specified keywords arguments of the method's local binding to instance variables
|
51
51
|
# call as: all_args_to_ivars binding :user_id, :user_name
|
52
52
|
|
53
|
-
all_kwargs_to_ivars(
|
53
|
+
all_kwargs_to_ivars(local_binding, namespace=:kwargs)
|
54
54
|
# sets the method's **kwargs argument to instance variables, with each key as the ivar's "@#{name}" and the value as its value
|
55
55
|
# call as: kwargs_to_ivars binding
|
56
|
+
# the keywords container name can be overwritten, e.g. the common :attributes
|
56
57
|
|
57
58
|
set_ivars(*ivars)
|
58
59
|
# sets instance variables named @"#{ivar}" for each symbol passed, by invoking send("set_#{ivar}")
|
59
60
|
# e.g. set_ivars(:user) sets @user with the value returned by your local method .set_user
|
60
61
|
# call as: set_ivars :user, :authentication, :connection
|
61
62
|
|
63
|
+
run_validations(*validations)
|
64
|
+
# calls a method for each argument, namespaced as "validate_#{argument}"
|
65
|
+
# call as: run_validations(:single_receipt, :single_order)
|
66
|
+
# => calls #validate_single_receipt and #validate_single_order
|
67
|
+
|
62
68
|
safe_send(method, *args, return_value: nil)
|
63
69
|
# a safe version of .send, which in case of an error rescues and returns return_value (default: nil) instead
|
64
70
|
|
@@ -92,6 +98,7 @@ include_concerns_of(*directories, namespace: nil)
|
|
92
98
|
# call as: include_concerns_of :user, :mail
|
93
99
|
# => includes all modules of models/concerns/user/* and models/oncerns/mail/*
|
94
100
|
# or call as: include_concerns_of :request_service, namespace: Eivid::Concerns
|
101
|
+
# tip: call Class.included_modules to view all included modules
|
95
102
|
```
|
96
103
|
|
97
104
|
|
@@ -242,15 +249,7 @@ The new_job macro is monkey patched into Kernel, therefore no configuration is r
|
|
242
249
|
|
243
250
|
### Info
|
244
251
|
|
245
|
-
The Eitil scopes wrapper creates various default scopes for a model
|
246
|
-
|
247
|
-
```ruby
|
248
|
-
# models/user.rb
|
249
|
-
|
250
|
-
class User < ApplicationRecord
|
251
|
-
use_eitil_scopes
|
252
|
-
end
|
253
|
-
```
|
252
|
+
The Eitil scopes wrapper creates various default scopes for a model.
|
254
253
|
|
255
254
|
### The Scopes
|
256
255
|
|
@@ -6,9 +6,8 @@ module ApplicationRecordMonkey
|
|
6
6
|
|
7
7
|
def self.all_associations
|
8
8
|
reflect_on_all_associations.map do |assoc|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
9
|
+
{ assoc.name => assoc.association_class.to_s.demodulize }
|
10
|
+
end.inject &:merge
|
12
11
|
end
|
13
12
|
|
14
13
|
end
|
@@ -12,8 +12,8 @@ Kernel.module_eval do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def all_kwargs_to_ivars(local_binding)
|
16
|
-
local_binding.local_variable_get(
|
15
|
+
def all_kwargs_to_ivars(local_binding, namespace=:kwargs)
|
16
|
+
local_binding.local_variable_get(namespace).each do |name, value|
|
17
17
|
instance_variable_set "@#{name}", value
|
18
18
|
end
|
19
19
|
end
|
@@ -24,6 +24,10 @@ Kernel.module_eval do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
def run_validations(*validations)
|
28
|
+
validations.each { |v| eval "validate_#{v}" }
|
29
|
+
end
|
30
|
+
|
27
31
|
def safe_call(*args, return_value: nil, &block)
|
28
32
|
block.call self, *args
|
29
33
|
rescue
|
@@ -31,7 +31,13 @@ module Eitil
|
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
+
def self.inherited(subclass)
|
35
|
+
use_eitil_scopes
|
36
|
+
super
|
37
|
+
end
|
38
|
+
|
34
39
|
def use_eitil_scopes
|
40
|
+
return if abstract_class?
|
35
41
|
%i[boolean datetime date integer float].each { |_type| send :"create_eitil_#{_type}_scopes" }
|
36
42
|
end
|
37
43
|
|
@@ -44,32 +50,32 @@ module Eitil
|
|
44
50
|
end
|
45
51
|
|
46
52
|
def create_eitil_boolean_scopes
|
47
|
-
columns_of_type(:boolean)
|
53
|
+
columns_of_type(:boolean)&.map do |column, object|
|
48
54
|
eitil_scope :"#{column}_true", -> { where(column => true) }
|
49
55
|
eitil_scope :"#{column}_false", -> { where(column => [false, nil]) }
|
50
56
|
end
|
51
57
|
end
|
52
58
|
|
53
59
|
def create_eitil_datetime_scopes
|
54
|
-
columns_of_type(:datetime)
|
60
|
+
columns_of_type(:datetime)&.map do |column, object|
|
55
61
|
SharableDateScopes.call column
|
56
62
|
end
|
57
63
|
end
|
58
64
|
|
59
65
|
def create_eitil_date_scopes
|
60
|
-
columns_of_type(:date)
|
66
|
+
columns_of_type(:date)&.map do |column, object|
|
61
67
|
SharableDateScopes.call column
|
62
68
|
end
|
63
69
|
end
|
64
70
|
|
65
71
|
def create_eitil_integer_scopes
|
66
|
-
columns_of_type(:integer)
|
72
|
+
columns_of_type(:integer)&.map do |column, object|
|
67
73
|
SharableNumScopes.call column
|
68
74
|
end
|
69
75
|
end
|
70
76
|
|
71
77
|
def create_eitil_float_scopes
|
72
|
-
columns_of_type(:float)
|
78
|
+
columns_of_type(:float)&.map do |column, object|
|
73
79
|
SharableNumScopes.call column
|
74
80
|
end
|
75
81
|
end
|
data/lib/eitil/version.rb
CHANGED
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: 0.3.
|
4
|
+
version: 0.3.3
|
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-
|
11
|
+
date: 2021-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|