mystique 0.9.1 → 0.10.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/mystique.rb +4 -4
- data/lib/mystique/presenter.rb +21 -0
- data/lib/mystique/version.rb +1 -1
- 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: 3002fb22f03736997a6c51b1a106646ac95d60eb24a8c5317a87d3ed60c1eb8e
|
4
|
+
data.tar.gz: 8a9a8a51104e4a058562d9b317ffbd4e4d397d4e0cec8169209213428816ead9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae3668d7b1c1a5f2929dc4b05a0a5149bd400bce74a9644718c4d047033762f885c1e89f9f938e64db82970fb9c49bdd395cd6bf6e4a1b0f5bb686a4a573cb54
|
7
|
+
data.tar.gz: d4a4dddb0f7121a5bf392faa5cffc6697c50a709396b11abf009f40eea4613633db31e9a23537c001e14b4bb79cd7ffaa1a1f2fe6416422e5193597ddb80e8f1
|
data/lib/mystique.rb
CHANGED
@@ -18,15 +18,15 @@ module Mystique
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def present_collection(collection, context: nil, &block)
|
22
|
-
return to_enum(:present_collection, collection, context: context, &block) unless block_given?
|
21
|
+
def present_collection(collection, context: nil, with: nil, &block)
|
22
|
+
return to_enum(:present_collection, collection, context: context, with: with, &block) unless block_given?
|
23
23
|
|
24
24
|
collection.each do |element|
|
25
25
|
case block.arity
|
26
26
|
when 2
|
27
|
-
block.call( present(element, context: context), element )
|
27
|
+
block.call( present(element, context: context, with: with), element )
|
28
28
|
else
|
29
|
-
block.call(present(element, context: context))
|
29
|
+
block.call(present(element, context: context, with: with))
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/lib/mystique/presenter.rb
CHANGED
@@ -41,6 +41,8 @@ module Mystique
|
|
41
41
|
format( value )
|
42
42
|
when presented_method?(method)
|
43
43
|
Mystique.present(value, context: context)
|
44
|
+
when presented_collection?(method)
|
45
|
+
Mystique.present_collection(value, context: context, &block)
|
44
46
|
else
|
45
47
|
value
|
46
48
|
end
|
@@ -54,6 +56,10 @@ module Mystique
|
|
54
56
|
__presented_methods__.include?(method)
|
55
57
|
end
|
56
58
|
|
59
|
+
def presented_collection?(method)
|
60
|
+
__presented_collections__.include?(method)
|
61
|
+
end
|
62
|
+
|
57
63
|
def format(value)
|
58
64
|
result = if __formats__.keys.include?(value)
|
59
65
|
__formats__[value]
|
@@ -88,6 +94,13 @@ module Mystique
|
|
88
94
|
end
|
89
95
|
end
|
90
96
|
|
97
|
+
# TODO: Define this
|
98
|
+
def self.present_collection(matcher)
|
99
|
+
if matcher.is_a?(Symbol)
|
100
|
+
__presented_collections__ << matcher
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
91
104
|
def self.format_and_present(matcher)
|
92
105
|
format_method(method)
|
93
106
|
present_method(method)
|
@@ -97,6 +110,10 @@ module Mystique
|
|
97
110
|
@__presented_methods__ ||= []
|
98
111
|
end
|
99
112
|
|
113
|
+
def self.__presented_collections__
|
114
|
+
@__presented_collections__ ||= []
|
115
|
+
end
|
116
|
+
|
100
117
|
def self.__formatted_methods__
|
101
118
|
@__formatted_methods__ ||= []
|
102
119
|
end
|
@@ -105,6 +122,10 @@ module Mystique
|
|
105
122
|
self.class.__presented_methods__
|
106
123
|
end
|
107
124
|
|
125
|
+
def __presented_collections__
|
126
|
+
self.class.__presented_collections__
|
127
|
+
end
|
128
|
+
|
108
129
|
def __formatted_methods__
|
109
130
|
self.class.__formatted_methods__
|
110
131
|
end
|
data/lib/mystique/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mystique
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Iachetti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|