mocca 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 55cf25dab2f1f7c26d52780ccc7cf1d13bd7fdb9413463e68e8e2a7a177d3843
4
+ data.tar.gz: 2a7cc8938a95187be25568b79f6584a35102534ff2338c185fd8972789809a0c
5
+ SHA512:
6
+ metadata.gz: f4c1b286ca3488b7b33ddab65ec4b12a579c54bd19636a80920dcbe599e5c73d66df6dd48c1f373bf249f58be4e11c4493ae3456dbea449b96abb45ca99da34c
7
+ data.tar.gz: 835072699c399f2b43da456273f4010f9f448650e3b6f1f4396b25c5cbfb91ec8686ebe6ab7d36ab3974145d5882908a565bf7e1c9eeacf1cfcbf805ff45c933
@@ -0,0 +1,3 @@
1
+ require 'tchae'
2
+ require_relative 'mocca/version'
3
+ require_relative 'mocca/struct'
@@ -0,0 +1,67 @@
1
+ module Mocca
2
+ class VStruct
3
+ @isa_wrapper = {}
4
+ def self.is_a_wrapper(modklass)
5
+ return @isa_wrapper[modklass] if @isa_wrapper.key?(modklass)
6
+ @isa_wrapper[modklass] = Tchae.Wrapper.args.positional.expect do
7
+ arg {is_a? modklass }
8
+ end
9
+ end
10
+ def initialize
11
+ @values = {}
12
+ end
13
+ end
14
+
15
+
16
+
17
+ def self.VStruct(**props)
18
+ Class.new(VStruct) do
19
+ @props = props
20
+ wrapper_raise = Tchae.Wrapper
21
+ wrapper_retor = Tchae.Wrapper(::Tchae::Handling::RETURN_RESULT_OR_ERROR )
22
+ wrapper_retwra = Tchae.Wrapper(::Tchae::Handling::RETURN_WRAPPER )
23
+ h = {}
24
+ p = []
25
+ props.each{|a,klassmod|
26
+ asym = a.to_sym
27
+ define_method(asym) do
28
+ @values[asym]
29
+ end
30
+ create_validated_method("#{a}=", VStruct.is_a_wrapper(klassmod)) do |val| @values[asym] = val end
31
+ h[asym] = ->{ is_a? klassmod }
32
+ p << ->{ is_a? klassmod }
33
+ }
34
+ wrapper_raise.args.positional.expect(*p)
35
+ wrapper_retwra.args.positional.expect(*p)
36
+ wrapper_retor.args.positional.expect(*p)
37
+
38
+ wrapper_raise.args.keyword.expect(**h)
39
+ wrapper_retwra.args.keyword.expect(**h)
40
+ wrapper_retor.args.keyword.expect(**h)
41
+
42
+ create_validated_singleton_method(:create_or_raise, wrapper_raise) do |*p, **kwparms|
43
+ new(*p, **kwparms)
44
+ end
45
+ create_validated_singleton_method(:create_and_wrap,
46
+ wrapper_retwra) do |*p, **kwparms|
47
+ new(*p, **kwparms)
48
+ end
49
+
50
+ create_validated_singleton_method(:create_valid_or_error,
51
+ wrapper_retor) do |*p, **kwparms|
52
+ new(*p, **kwparms)
53
+ end
54
+
55
+ private_class_method :new
56
+ define_method :initialize do |*p, **kwvals|
57
+ super()
58
+
59
+ p.zip(props.keys).each{|val, a| @values[a] = val}
60
+ kwvals.each{|a, val| @values[a] = val }
61
+
62
+ end
63
+
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module Mocca
2
+ VERSION = '0.0.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mocca
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - D.M.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tchae
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.51'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.51'
55
+ description: Mocca's are validated/typed structures
56
+ email: dev@aithscel.eu
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - lib/mocca.rb
62
+ - lib/mocca/struct.rb
63
+ - lib/mocca/version.rb
64
+ homepage: https://gitlab.com/dm0da/mocca
65
+ licenses:
66
+ - MIT
67
+ metadata:
68
+ bug_tracker_uri: https://gitlab.com/dm0da/mocca/issues
69
+ changelog_uri: https://gitlab.com/dm0da/mocca/blob/master/CHANGELOG
70
+ source_code_uri: https://gitlab.com/dm0da/mocca/tree/master
71
+ wiki_uri: https://gitlab.com/dm0da/mocca/wikis/home
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 2.4.0
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.1.2
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Mocca's are validated/typed structures
91
+ test_files: []