logic_pro 0.1.1 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/logic_pro/active_record_types.rb +30 -0
- data/lib/logic_pro/form.rb +1 -3
- data/lib/logic_pro/interactor_form.rb +9 -7
- data/lib/logic_pro/primitive_types.rb +1 -0
- data/lib/logic_pro/types.rb +1 -0
- data/lib/logic_pro/version.rb +1 -1
- data/lib/logic_pro.rb +1 -1
- data/logic_pro-0.2.gem +0 -0
- data/logic_pro-0.4.1.gem +0 -0
- data/logic_pro-0.4.2.gem +0 -0
- data/logic_pro.gemspec +3 -3
- metadata +9 -6
- data/lib/logic_pro/models_types.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e39d0315970503a400579582036f7b473cf690edd10d071a107564a76248af81
|
4
|
+
data.tar.gz: 81f0767b3c9b3054b384da1c9fbc5c3e3056c8cbcaf9db3d647b2a3ed87722d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cff05ffa4a46f15c628441160af3ce502e14691947c878209964e749615d50138d35531e026b59f1ceb4321925e9f9a36bf89be5b0d37d726e34a01bd66bd787
|
7
|
+
data.tar.gz: f8e915851d6a170575c11cc5407071e8715962a89fe9449ece33bfec1d7d657a073dc5894af20f904a884ebd172f0e1995e23eaf9c3dea380dd0e05949fba4f5
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
logic_pro (
|
4
|
+
logic_pro (1.0)
|
5
5
|
activemodel
|
6
6
|
dry-struct
|
7
7
|
interactor
|
@@ -40,7 +40,7 @@ GEM
|
|
40
40
|
concurrent-ruby (~> 1.0)
|
41
41
|
ice_nine (0.11.2)
|
42
42
|
interactor (3.1.2)
|
43
|
-
minitest (5.16.
|
43
|
+
minitest (5.16.3)
|
44
44
|
rake (12.3.3)
|
45
45
|
rspec (3.11.0)
|
46
46
|
rspec-core (~> 3.11.0)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module LogicPro
|
2
|
+
module ActiveRecordTypes
|
3
|
+
def define_types(classes)
|
4
|
+
classes.each do |active_record_class_name|
|
5
|
+
active_record_class = "::#{active_record_class_name}".constantize
|
6
|
+
type_class_name = active_record_class.to_s.gsub('::', '_')
|
7
|
+
|
8
|
+
record_constructor = Constructor(active_record_class) do |entity|
|
9
|
+
if entity.blank? || entity.class.name == active_record_class.name
|
10
|
+
entity
|
11
|
+
else
|
12
|
+
raise "Invalid collection type #{collection.class} for #{active_record_class.name}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
collection_constructor = Constructor(active_record_class.none.class) do |collection|
|
17
|
+
if collection.respond_to?(:model) && collection.model.name == active_record_class.name
|
18
|
+
collection
|
19
|
+
else
|
20
|
+
raise "Invalid collection type #{collection.class} for #{active_record_class.name}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
const_set(type_class_name, record_constructor.meta(class_name: active_record_class.name))
|
25
|
+
|
26
|
+
const_set("#{type_class_name}Collection", collection_constructor.meta(class_name: active_record_class.none.class))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/logic_pro/form.rb
CHANGED
@@ -2,13 +2,15 @@ module LogicPro
|
|
2
2
|
module InteractorForm
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
|
6
|
-
include LogicPro::Types
|
7
|
-
end
|
5
|
+
Types = LogicPro::Types
|
8
6
|
|
9
7
|
class_methods do
|
10
8
|
def context_form
|
11
|
-
@context_form ||=
|
9
|
+
@context_form ||= begin
|
10
|
+
new_class = Class.new(LogicPro::Form)
|
11
|
+
|
12
|
+
self.const_set('ContextForm', new_class)
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
16
|
def attribute(*args)
|
@@ -27,13 +29,13 @@ module LogicPro
|
|
27
29
|
context_form.validates(*args)
|
28
30
|
end
|
29
31
|
|
30
|
-
def validate(*args)
|
31
|
-
context_form.validate(*args)
|
32
|
+
def validate(*args, **options)
|
33
|
+
context_form.validate(*args, **options)
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
35
37
|
def context_form
|
36
|
-
@context_form ||=
|
38
|
+
@context_form ||= ContextForm.new(context.to_h)
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
@@ -9,5 +9,6 @@ module LogicPro
|
|
9
9
|
Float = Constructor(::Float, &:to_f)
|
10
10
|
Integer = Constructor(::Integer, &:to_i)
|
11
11
|
DateTime = Constructor(::DateTime) { |value| ::DateTime.parse(value.to_s) if value.present? }
|
12
|
+
InteractorType = Constructor(::Interactor) { |value| value }
|
12
13
|
end
|
13
14
|
end
|
data/lib/logic_pro/types.rb
CHANGED
data/lib/logic_pro/version.rb
CHANGED
data/lib/logic_pro.rb
CHANGED
data/logic_pro-0.2.gem
ADDED
Binary file
|
data/logic_pro-0.4.1.gem
ADDED
Binary file
|
data/logic_pro-0.4.2.gem
ADDED
Binary file
|
data/logic_pro.gemspec
CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
19
|
end
|
20
20
|
|
21
|
-
spec.add_dependency
|
22
|
-
spec.add_dependency
|
23
|
-
spec.add_dependency
|
21
|
+
spec.add_dependency 'activemodel'
|
22
|
+
spec.add_dependency 'dry-struct'
|
23
|
+
spec.add_dependency 'interactor'
|
24
24
|
|
25
25
|
spec.bindir = 'exe'
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logic_pro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '1.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bezrukavyi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activemodel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: dry-struct
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: interactor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -71,13 +71,16 @@ files:
|
|
71
71
|
- bin/console
|
72
72
|
- bin/setup
|
73
73
|
- lib/logic_pro.rb
|
74
|
+
- lib/logic_pro/active_record_types.rb
|
74
75
|
- lib/logic_pro/form.rb
|
75
76
|
- lib/logic_pro/interactor.rb
|
76
77
|
- lib/logic_pro/interactor_form.rb
|
77
|
-
- lib/logic_pro/models_types.rb
|
78
78
|
- lib/logic_pro/primitive_types.rb
|
79
79
|
- lib/logic_pro/types.rb
|
80
80
|
- lib/logic_pro/version.rb
|
81
|
+
- logic_pro-0.2.gem
|
82
|
+
- logic_pro-0.4.1.gem
|
83
|
+
- logic_pro-0.4.2.gem
|
81
84
|
- logic_pro.gemspec
|
82
85
|
homepage: https://github.com/bezrukavyi/logic_pro
|
83
86
|
licenses:
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module LogicPro
|
2
|
-
module ModelsTypes
|
3
|
-
def self.add(base, classes)
|
4
|
-
classes.each do |active_record_class_name|
|
5
|
-
active_record_class = active_record_class_name.constantize
|
6
|
-
type_class_name = active_record_class.to_s.gsub('Ratesmgr::', '').gsub('::', '_')
|
7
|
-
|
8
|
-
base.const_set(type_class_name, base::Instance(active_record_class).meta(class_name: active_record_class.name).optional)
|
9
|
-
|
10
|
-
collection_constructor = base::Constructor(active_record_class.none.class) do |collection|
|
11
|
-
if collection.respond_to?(:model) && collection.model == active_record_class
|
12
|
-
collection
|
13
|
-
else
|
14
|
-
raise "Invalid collection type #{collection.class} for #{active_record_class.name}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
base.const_set("#{type_class_name}Collection", collection_constructor.meta(class_name: active_record_class.none.class))
|
19
|
-
end
|
20
|
-
|
21
|
-
parent
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|