expo 0.10.0 → 0.11.0
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/lib/expo3.rb +122 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24a14d5d628dae20b89f9c99c511d3222a9c7ec8
|
4
|
+
data.tar.gz: 659ebc926f106ebf5e3812e2d78aa2131a8cb38f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cc778a6f60de2e7c8398be118d130dcc1f83e3d61d4781001e56bb33ac2591091367eae2087dea55c97f359ed1525faf33e58ac2ecc7c5dd2e8614a11a579cf
|
7
|
+
data.tar.gz: 8e7a6c2dfb6fda7caa5b78d620d00f77cbf4349ea634a72af470d4238504c52bb262796867c2e982f35c296422888ae0f6e4c39499c6e6843cdf00ecb42abad1
|
data/lib/expo3.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
class Expo3
|
2
|
+
class Builder
|
3
|
+
def initialize(expo)
|
4
|
+
@expo = expo
|
5
|
+
@output = {}
|
6
|
+
@blocks = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def expose(*keys)
|
10
|
+
key_map = key_map(keys)
|
11
|
+
output = @output
|
12
|
+
@blocks << Proc.new do |obj, **context|
|
13
|
+
key_map.each do |k,v|
|
14
|
+
output[v] = obj.send(k)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def augment(another, *keys)
|
20
|
+
return if another.nil?
|
21
|
+
key_map = key_map(keys)
|
22
|
+
output = @output
|
23
|
+
@blocks << Proc.new do |obj, **context|
|
24
|
+
key_map.each do |k,v|
|
25
|
+
output[v] = another.send(k)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def sub_expo(key, another, sub_expo=nil, &block)
|
31
|
+
return if another.nil?
|
32
|
+
output = @output
|
33
|
+
@blocks << Proc.new do |obj, **context|
|
34
|
+
sub = sub_expo || Expo3.new(&block)
|
35
|
+
out = sub.expo(another, **context)
|
36
|
+
output[key] = out
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def merge_expo(another, sub_expo=nil, &block)
|
41
|
+
return if another.nil?
|
42
|
+
output = @output
|
43
|
+
@blocks << Proc.new do |obj, **context|
|
44
|
+
sub = sub_expo || Expo3.new(&block)
|
45
|
+
out = sub.expo(another,**context)
|
46
|
+
output.merge! out
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def collection(key, anothers, sub_expo=nil, &block)
|
51
|
+
return if anothers.nil?
|
52
|
+
output = @output
|
53
|
+
sub = (sub_expo || Expo3.new).upgrade(&block)
|
54
|
+
@blocks << Proc.new do |obj,**context|
|
55
|
+
out = anothers.map.with_index do |o, i|
|
56
|
+
if sub.expects?(:index)
|
57
|
+
sub.expo(o, **(context.merge(index: i)))
|
58
|
+
else
|
59
|
+
sub.expo(o, **context)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
output[key] = out
|
63
|
+
end
|
64
|
+
sub
|
65
|
+
end
|
66
|
+
|
67
|
+
def inline(hash)
|
68
|
+
@output.merge!(hash)
|
69
|
+
end
|
70
|
+
|
71
|
+
def current_expo
|
72
|
+
@expo
|
73
|
+
end
|
74
|
+
|
75
|
+
def output(obj=nil,**context)
|
76
|
+
@blocks.each do |b|
|
77
|
+
b.call(obj,**context)
|
78
|
+
end
|
79
|
+
@output
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
def key_map(keys)
|
84
|
+
array, hash = ArgumentParser.new.parse_arguments(keys)
|
85
|
+
HashHelper.new.hasherize(array).merge(hash)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def initialize(**context, &block)
|
90
|
+
@block = block
|
91
|
+
@context = context
|
92
|
+
end
|
93
|
+
|
94
|
+
def expects?(keyparam)
|
95
|
+
@block.parameters.detect{|k,param| param == keyparam }
|
96
|
+
end
|
97
|
+
|
98
|
+
def fix(**context)
|
99
|
+
Expo3.new(**(@context.merge(context)), &@block)
|
100
|
+
end
|
101
|
+
|
102
|
+
def upgrade(&block)
|
103
|
+
return self unless block
|
104
|
+
return Expo3.new(**(@context), &block) unless @block
|
105
|
+
this = self
|
106
|
+
Expo3.new do |obj|
|
107
|
+
merge_expo obj, this
|
108
|
+
merge_expo obj, Expo3.new(&block)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def expo(obj=nil, **context)
|
113
|
+
builder = Builder.new(self)
|
114
|
+
builder.instance_exec(obj, **(@context.merge(context)), &@block) if @block
|
115
|
+
builder.output(obj, **context)
|
116
|
+
end
|
117
|
+
|
118
|
+
def expo_collection(coll)
|
119
|
+
coll.map(&method(:expo))
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Serguei Filimonov
|
@@ -20,6 +20,7 @@ files:
|
|
20
20
|
- lib/argument_parser.rb
|
21
21
|
- lib/expo.rb
|
22
22
|
- lib/expo2.rb
|
23
|
+
- lib/expo3.rb
|
23
24
|
- lib/hash_helper.rb
|
24
25
|
- lib/null_expo.rb
|
25
26
|
- lib/presenters/asider.rb
|