taksi 0.2.1 → 0.2.2
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 +4 -4
- data/README.md +3 -0
- data/lib/taksi/component.rb +12 -0
- data/lib/taksi/components/field.rb +18 -1
- data/lib/taksi/components/skeleton.rb +8 -1
- data/lib/taksi/interface.rb +9 -1
- data/lib/taksi/registry.rb +1 -2
- data/lib/taksi/version.rb +1 -1
- data/lib/taksi.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e57c4a5876a120b859b3642f790bf13d7f45a691ca74e2a3967d094589b2605a
|
|
4
|
+
data.tar.gz: da96e2c711489b11c4d24f88cb8e3ae738774c484772e3a9c5e0106ab13f5573
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f52db226be934f1c70c127f2c75b105c1cdc65efd8443a76e338cb62769c95f2511e3b282521d753d6e34cc8791282889b7ef8d05bc471e3ad6b0fc87f8c316
|
|
7
|
+
data.tar.gz: 229d3fbd97e55eaa3e70a3dd735e2e3b6f4947d9b3b91a962d73a2680c8bccd0c9d04af2a63bff3fcd37810519e65af3c52adb37111c801b8098d2ebdec793e9
|
data/README.md
CHANGED
|
@@ -23,6 +23,7 @@ class Components::Users::ProfileResume
|
|
|
23
23
|
|
|
24
24
|
content do
|
|
25
25
|
name Taksi::Dynamic
|
|
26
|
+
profile_kind Taksi::Static, 'resume'
|
|
26
27
|
|
|
27
28
|
details do
|
|
28
29
|
age Taksi::Dynamic
|
|
@@ -69,8 +70,10 @@ Which provide us:
|
|
|
69
70
|
{
|
|
70
71
|
"name": "users/profile_resume",
|
|
71
72
|
"identifier": "component$0",
|
|
73
|
+
"requires_data": true,
|
|
72
74
|
"content": {
|
|
73
75
|
"name": null,
|
|
76
|
+
"profile_kind": "resume",
|
|
74
77
|
"details": {
|
|
75
78
|
"age": null,
|
|
76
79
|
"email": null
|
data/lib/taksi/component.rb
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Taksi
|
|
4
|
+
# A custom module to turn a class into a component on taksi protocol
|
|
5
|
+
#
|
|
6
|
+
# ```ruby
|
|
7
|
+
# class CustomComponent
|
|
8
|
+
# include Taksi::Component.new('customs/component_name')
|
|
9
|
+
#
|
|
10
|
+
# content do
|
|
11
|
+
# field_name Taksi::Static
|
|
12
|
+
# end
|
|
13
|
+
# end
|
|
14
|
+
# ```
|
|
15
|
+
#
|
|
4
16
|
class Component < ::Module
|
|
5
17
|
attr_reader :identifier
|
|
6
18
|
|
|
@@ -10,6 +10,10 @@ module Taksi
|
|
|
10
10
|
@name = name.to_sym
|
|
11
11
|
@parent = parent
|
|
12
12
|
|
|
13
|
+
raise <<~MESSAGE unless args.size.positive? || block_given?
|
|
14
|
+
You must provide a value or a block definition to build field
|
|
15
|
+
MESSAGE
|
|
16
|
+
|
|
13
17
|
@value = args.shift.new(skeleton, name, *args) if args.size.positive?
|
|
14
18
|
@nested_fields = []
|
|
15
19
|
|
|
@@ -23,6 +27,8 @@ module Taksi
|
|
|
23
27
|
"#{parent.name}.#{name}"
|
|
24
28
|
end
|
|
25
29
|
|
|
30
|
+
# Fetches the data for in `data` for the current field
|
|
31
|
+
# @return any
|
|
26
32
|
def fetch_from(data)
|
|
27
33
|
return value.as_json if value.static?
|
|
28
34
|
|
|
@@ -33,12 +39,17 @@ module Taksi
|
|
|
33
39
|
raise NameError, "Couldn't fetch #{key.inspect} from data: #{data.inspect}"
|
|
34
40
|
end
|
|
35
41
|
|
|
42
|
+
# Turns the field into his json representation
|
|
43
|
+
# The returned hash is compatible with the skeleton json specification
|
|
44
|
+
# @return Hash
|
|
36
45
|
def as_json
|
|
37
46
|
return {name => @nested_fields.map(&:as_json).inject({}, &:merge)} if nested?
|
|
38
47
|
|
|
39
48
|
{name => value.as_json}
|
|
40
49
|
end
|
|
41
50
|
|
|
51
|
+
# Builds up a interator over all fields included nested ones
|
|
52
|
+
# @returns Enumerable
|
|
42
53
|
def fields
|
|
43
54
|
Enumerator.new do |yielder|
|
|
44
55
|
@nested_fields.each do |field|
|
|
@@ -59,13 +70,19 @@ module Taksi
|
|
|
59
70
|
@parent.nil?
|
|
60
71
|
end
|
|
61
72
|
|
|
73
|
+
def dynamic?
|
|
74
|
+
return @nested_fields.any?(&:dynamic?) if @value.nil?
|
|
75
|
+
|
|
76
|
+
@value.dynamic?
|
|
77
|
+
end
|
|
78
|
+
|
|
62
79
|
def method_missing(name, *args, &block)
|
|
63
80
|
return super if @defined
|
|
64
81
|
|
|
65
82
|
@nested_fields << self.class.new(skeleton, name, *args, parent: self, &block)
|
|
66
83
|
end
|
|
67
84
|
|
|
68
|
-
def respond_to_missing?(name)
|
|
85
|
+
def respond_to_missing?(name, *)
|
|
69
86
|
return super if @defined
|
|
70
87
|
|
|
71
88
|
true
|
|
@@ -9,6 +9,8 @@ module Taksi
|
|
|
9
9
|
@parent = parent
|
|
10
10
|
@name = name
|
|
11
11
|
|
|
12
|
+
raise 'To build a component you need to provide a `content` block' unless block_given?
|
|
13
|
+
|
|
12
14
|
@content = ::Taksi::Components::Field.new(self, :content, &block)
|
|
13
15
|
end
|
|
14
16
|
|
|
@@ -20,10 +22,15 @@ module Taksi
|
|
|
20
22
|
content.fields
|
|
21
23
|
end
|
|
22
24
|
|
|
25
|
+
def dynamic?
|
|
26
|
+
@content.dynamic?
|
|
27
|
+
end
|
|
28
|
+
|
|
23
29
|
def as_json
|
|
24
30
|
{
|
|
25
31
|
name: name,
|
|
26
|
-
identifier: id
|
|
32
|
+
identifier: id,
|
|
33
|
+
requires_data: dynamic?
|
|
27
34
|
}.tap do |json|
|
|
28
35
|
json.merge!(content.as_json)
|
|
29
36
|
end
|
data/lib/taksi/interface.rb
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Taksi
|
|
4
|
+
# A custom module that turns a class into a interface on taksi protocol
|
|
5
|
+
#
|
|
4
6
|
class Interface < ::Module
|
|
5
7
|
attr_reader :interface_name, :version_pattern, :alternatives
|
|
6
8
|
|
|
9
|
+
# Finds for a interface by its name and the current version
|
|
10
|
+
# @param name [String]
|
|
11
|
+
# @param version [String] just like '0.2.1'
|
|
12
|
+
# @param alternatives: [Array]
|
|
13
|
+
# @raises`::Taksi::Registry::InterfaceNotFoundError`
|
|
14
|
+
# @return Class the class of interface
|
|
7
15
|
def self.find(name, version, alternative: nil)
|
|
8
16
|
::Taksi::Registry.find(name, version, alternative)
|
|
9
17
|
end
|
|
@@ -28,7 +36,7 @@ module Taksi
|
|
|
28
36
|
attr_reader :skeleton
|
|
29
37
|
|
|
30
38
|
def find(version, alternative = nil)
|
|
31
|
-
::Taksi::Registry.find(interface_name, version, alternative)
|
|
39
|
+
::Taksi::Registry.find(@interface_definition.interface_name, version, alternative)
|
|
32
40
|
end
|
|
33
41
|
|
|
34
42
|
def initiate(interface_definition)
|
data/lib/taksi/registry.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'forwardable'
|
|
4
3
|
module Taksi
|
|
5
4
|
class Registry
|
|
6
5
|
include ::Singleton
|
|
@@ -41,7 +40,7 @@ module Taksi
|
|
|
41
40
|
|
|
42
41
|
next true if alternative.nil?
|
|
43
42
|
|
|
44
|
-
next true if interface.alternatives.
|
|
43
|
+
next true if interface.alternatives.nil?
|
|
45
44
|
|
|
46
45
|
next true if interface.alternatives.include?(alternative)
|
|
47
46
|
|
data/lib/taksi/version.rb
CHANGED
data/lib/taksi.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: taksi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Israel Trindade
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-07-
|
|
11
|
+
date: 2023-07-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|