props_template 1.0.3 → 1.1.1
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a54115d5cb581b3b4a3c487ca6bdad66a2f533a56f1171d65c9f1759ca9f2ec
|
|
4
|
+
data.tar.gz: d7672f8b3324ec7ae2b63e790b2c0f38e73f3b5534ad18a5e8a1704bd14c98b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d07608d99ad469d3dfe6c4f264b7addb844b7a35f6a5ce2c13469bd1bd1dfa14d41c6800f62933a122d86d3ecf65a08aba95a4746d3fc329b5daf1305ec288af
|
|
7
|
+
data.tar.gz: b76b141b1938ebc83b40c2208c0d77274472c02615a17a0a6771147b38ac7639923b092b066333708087f2074b920e06d99e824b4b36fc9a8e4d517afb7d3f3a
|
data/lib/props_template/base.rb
CHANGED
|
@@ -63,6 +63,21 @@ module Props
|
|
|
63
63
|
nil
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
+
def set_value!(key, value)
|
|
67
|
+
if @scope == :array
|
|
68
|
+
raise InvalidScopeForObjError.new("Attempted to set! on an array! scope")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
if @scope.nil?
|
|
72
|
+
@scope = :object
|
|
73
|
+
@stream.push_object
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
@stream.push_value(value, format_key(key))
|
|
77
|
+
|
|
78
|
+
nil
|
|
79
|
+
end
|
|
80
|
+
|
|
66
81
|
def handle_collection_item(collection, item, index, options)
|
|
67
82
|
@item_context = item
|
|
68
83
|
|
|
@@ -124,7 +139,7 @@ module Props
|
|
|
124
139
|
[value, value]
|
|
125
140
|
end
|
|
126
141
|
|
|
127
|
-
|
|
142
|
+
set_value!(
|
|
128
143
|
key,
|
|
129
144
|
object.is_a?(Hash) ? object.fetch(attribute) : object.public_send(attribute)
|
|
130
145
|
)
|
|
@@ -153,6 +168,15 @@ module Props
|
|
|
153
168
|
@child_index = child_index
|
|
154
169
|
end
|
|
155
170
|
|
|
171
|
+
def capture_json
|
|
172
|
+
parent_stream = @stream
|
|
173
|
+
@stream = Oj::StringWriter.new(mode: :rails)
|
|
174
|
+
yield
|
|
175
|
+
@stream.raw_json.strip
|
|
176
|
+
ensure
|
|
177
|
+
@stream = parent_stream
|
|
178
|
+
end
|
|
179
|
+
|
|
156
180
|
def result!
|
|
157
181
|
if @scope.nil?
|
|
158
182
|
@stream.push_object
|
|
@@ -70,22 +70,16 @@ module Props
|
|
|
70
70
|
|
|
71
71
|
def handle_cache(options, item)
|
|
72
72
|
if options[:cache]
|
|
73
|
-
recently_cached = false
|
|
74
|
-
|
|
75
73
|
key, rest = Cache
|
|
76
74
|
.normalize_options(options[:cache], item)
|
|
75
|
+
|
|
76
|
+
# A miss renders into a writer of its own, so its JSON is added to
|
|
77
|
+
# the output below like a hit's.
|
|
77
78
|
state = @cache.cache(key, rest) do
|
|
78
|
-
recently_cached = true
|
|
79
79
|
result = nil
|
|
80
|
-
start = base.stream.to_s.length
|
|
81
80
|
base.scoped_state { |stream, deferred_paths, fragment_paths|
|
|
82
|
-
yield
|
|
81
|
+
raw = base.capture_json { yield }
|
|
83
82
|
meta = Oj.dump([deferred_paths, fragment_paths]).strip
|
|
84
|
-
json_in_progress = base.stream.to_s
|
|
85
|
-
if json_in_progress[start] == ","
|
|
86
|
-
start += 1
|
|
87
|
-
end
|
|
88
|
-
raw = base.stream.to_s[start..].strip
|
|
89
83
|
result = "#{meta}\n#{raw}"
|
|
90
84
|
}
|
|
91
85
|
result
|
|
@@ -96,9 +90,7 @@ module Props
|
|
|
96
90
|
deferred.push(*next_deferred)
|
|
97
91
|
fragments.push(*next_fragments)
|
|
98
92
|
|
|
99
|
-
|
|
100
|
-
base.stream.push_json(raw_json)
|
|
101
|
-
end
|
|
93
|
+
base.stream.push_json(raw_json)
|
|
102
94
|
else
|
|
103
95
|
yield
|
|
104
96
|
end
|
data/lib/props_template.rb
CHANGED
|
@@ -67,8 +67,10 @@ module Props
|
|
|
67
67
|
@builder.item_context = found_item
|
|
68
68
|
set!(key, found_options, &found_block)
|
|
69
69
|
end
|
|
70
|
-
|
|
70
|
+
elsif block || options.is_a?(Props::Options)
|
|
71
71
|
@builder.set!(key, options, &block)
|
|
72
|
+
else
|
|
73
|
+
@builder.set_value!(key, options)
|
|
72
74
|
end
|
|
73
75
|
end
|
|
74
76
|
|