knuckles 0.1.1 → 0.2.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/.rubocop.yml +12 -4
- data/CHANGELOG.md +9 -0
- data/lib/knuckles/combiner.rb +4 -4
- data/lib/knuckles/dumper.rb +6 -2
- data/lib/knuckles/enhancer.rb +23 -0
- data/lib/knuckles/fetcher.rb +3 -1
- data/lib/knuckles/hydrator.rb +3 -1
- data/lib/knuckles/keygen.rb +2 -0
- data/lib/knuckles/pipeline.rb +3 -0
- data/lib/knuckles/renderer.rb +3 -1
- data/lib/knuckles/version.rb +3 -1
- data/lib/knuckles/view.rb +2 -0
- data/lib/knuckles/writer.rb +3 -1
- data/lib/knuckles.rb +3 -0
- data/spec/knuckles/combiner_spec.rb +7 -7
- data/spec/knuckles/dumper_spec.rb +4 -1
- data/spec/knuckles/enhancer_spec.rb +33 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19a29c342c27e5b5dd82cf59118e2145707f2d06
|
4
|
+
data.tar.gz: 9660418feed584f2ae6b0b75a54ece8a31fab387
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a29a4f519dcae90684811f5905e3641d20823e681c487dbefaea4a0157abc8e242ec368fa6a6fc5fbbcca6faddef9a9d7dadea8f41f241c6be3c7af158bcfd2f
|
7
|
+
data.tar.gz: e6662ef32ed48439b934cb2997f8cbb8f21b539aba41ac28e30aa57ebdcc7847732e9b1028fd58485f1795a220cc655165ad3d759851e781b8faf75f122c3894
|
data/.rubocop.yml
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
|
-
-
|
4
|
-
-
|
5
|
-
-
|
6
|
-
-
|
3
|
+
- "bench/**/*"
|
4
|
+
- "bin/*"
|
5
|
+
- "tmp/**/*"
|
6
|
+
- "vendor/**/*"
|
7
|
+
|
8
|
+
Style/FrozenStringLiteralComment:
|
9
|
+
EnforcedStyle: always
|
10
|
+
Exclude:
|
11
|
+
- "Gemfile*"
|
12
|
+
- "Rakefile"
|
13
|
+
- "*.gemspec"
|
14
|
+
- "spec/**/*"
|
7
15
|
|
8
16
|
Style/IfUnlessModifier:
|
9
17
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## v0.2.0 - 2016-03-23
|
2
|
+
|
3
|
+
* Add: Introduce the enhancer stage, used to augment data after it has been
|
4
|
+
rendered but before it is combined. This allows pruning or augmenting rendered
|
5
|
+
data after it has been retrieved from the cache, meaning results can be
|
6
|
+
tailored to the "current user" of a request without per-user-caching.
|
7
|
+
* Add: Uniformly combine cached and rendered results regardless of key type.
|
8
|
+
This also sees an improvement to the `uniq` check performed during dumping.
|
9
|
+
|
1
10
|
## v0.1.1 - 2016-03-22
|
2
11
|
|
3
12
|
* Performance: Improve unique handling by favoring a single `uniq!` call over
|
data/lib/knuckles/combiner.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Knuckles
|
4
4
|
module Combiner
|
5
5
|
extend self
|
6
6
|
|
7
7
|
def name
|
8
|
-
"combiner"
|
8
|
+
"combiner"
|
9
9
|
end
|
10
10
|
|
11
11
|
def call(prepared, _)
|
12
12
|
prepared.each_with_object(array_backed_hash) do |hash, memo|
|
13
13
|
hash[:result].each do |root, values|
|
14
14
|
case values
|
15
|
-
when Hash then memo[root] << values
|
16
|
-
when Array then memo[root] += values
|
15
|
+
when Hash then memo[root.to_s] << values
|
16
|
+
when Array then memo[root.to_s] += values
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/knuckles/dumper.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Knuckles
|
2
4
|
module Dumper
|
3
5
|
extend self
|
4
6
|
|
5
7
|
def name
|
6
|
-
"dumper"
|
8
|
+
"dumper"
|
7
9
|
end
|
8
10
|
|
9
11
|
def call(objects, _options)
|
@@ -14,7 +16,9 @@ module Knuckles
|
|
14
16
|
|
15
17
|
def keys_to_arrays(objects)
|
16
18
|
objects.each do |_, value|
|
17
|
-
|
19
|
+
if value.is_a?(Array)
|
20
|
+
value.uniq! { |hash| hash["id"] || hash[:id] }
|
21
|
+
end
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Knuckles
|
4
|
+
module Enhancer
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def name
|
8
|
+
"enhancer"
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(prepared, options)
|
12
|
+
enhancer = options[:enhancer]
|
13
|
+
|
14
|
+
if enhancer
|
15
|
+
prepared.each do |hash|
|
16
|
+
hash[:result] = enhancer.call(hash[:result], options)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
prepared
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/knuckles/fetcher.rb
CHANGED
data/lib/knuckles/hydrator.rb
CHANGED
data/lib/knuckles/keygen.rb
CHANGED
data/lib/knuckles/pipeline.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Knuckles
|
2
4
|
class Pipeline
|
3
5
|
def self.default_stages
|
@@ -5,6 +7,7 @@ module Knuckles
|
|
5
7
|
Knuckles::Hydrator,
|
6
8
|
Knuckles::Renderer,
|
7
9
|
Knuckles::Writer,
|
10
|
+
Knuckles::Enhancer,
|
8
11
|
Knuckles::Combiner,
|
9
12
|
Knuckles::Dumper]
|
10
13
|
end
|
data/lib/knuckles/renderer.rb
CHANGED
data/lib/knuckles/version.rb
CHANGED
data/lib/knuckles/view.rb
CHANGED
data/lib/knuckles/writer.rb
CHANGED
data/lib/knuckles.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/notifications"
|
2
4
|
require "active_support/cache"
|
3
5
|
require "json"
|
@@ -5,6 +7,7 @@ require "json"
|
|
5
7
|
module Knuckles
|
6
8
|
autoload :Combiner, "knuckles/combiner"
|
7
9
|
autoload :Dumper, "knuckles/dumper"
|
10
|
+
autoload :Enhancer, "knuckles/enhancer"
|
8
11
|
autoload :Fetcher, "knuckles/fetcher"
|
9
12
|
autoload :Hydrator, "knuckles/hydrator"
|
10
13
|
autoload :Keygen, "knuckles/keygen"
|
@@ -10,8 +10,8 @@ RSpec.describe Knuckles::Combiner do
|
|
10
10
|
}
|
11
11
|
}, {
|
12
12
|
result: {
|
13
|
-
posts
|
14
|
-
tags
|
13
|
+
"posts" => [{"id" => 2, "title" => "there", "tag_ids" => [1]}],
|
14
|
+
"tags" => [{"id" => 1, "name" => "alpha"}]
|
15
15
|
}
|
16
16
|
}
|
17
17
|
]
|
@@ -19,17 +19,17 @@ RSpec.describe Knuckles::Combiner do
|
|
19
19
|
combined = Knuckles::Combiner.call(prepared, {})
|
20
20
|
|
21
21
|
expect(combined).to eq(
|
22
|
-
author
|
22
|
+
"author" => [
|
23
23
|
{id: 1, name: "Michael"}
|
24
24
|
],
|
25
|
-
posts
|
25
|
+
"posts" => [
|
26
26
|
{id: 1, title: "hello", tag_ids: [1, 2]},
|
27
|
-
{id
|
27
|
+
{"id" => 2, "title" => "there", "tag_ids" => [1]}
|
28
28
|
],
|
29
|
-
tags
|
29
|
+
"tags" => [
|
30
30
|
{id: 1, name: "alpha"},
|
31
31
|
{id: 2, name: "gamma"},
|
32
|
-
{id
|
32
|
+
{"id" => 1, "name" => "alpha"}
|
33
33
|
]
|
34
34
|
)
|
35
35
|
end
|
@@ -5,11 +5,14 @@ RSpec.describe Knuckles::Dumper do
|
|
5
5
|
author: {id: 1, name: "Ernest"},
|
6
6
|
posts: [
|
7
7
|
{id: 1, title: "great"},
|
8
|
+
{id: 2, title: "stuff"},
|
8
9
|
{id: 2, title: "stuff"}
|
9
10
|
],
|
10
11
|
tags: [
|
11
12
|
{id: 1, name: "alpha"},
|
12
|
-
{id: 2, name: "gamma"}
|
13
|
+
{id: 2, name: "gamma"},
|
14
|
+
{id: 1, name: "alpha"},
|
15
|
+
{"id" => 2, "name" => "gamma"}
|
13
16
|
]
|
14
17
|
}
|
15
18
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
RSpec.describe Knuckles::Enhancer do
|
2
|
+
describe ".call" do
|
3
|
+
it "is a noop without an enhancer lambda" do
|
4
|
+
prepared = [Tag.new(1, "alpha")]
|
5
|
+
|
6
|
+
expect(Knuckles::Enhancer.call(prepared, {})).to eq(prepared)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "modifies the rendered values with a lambda" do
|
10
|
+
prepared = [
|
11
|
+
{result: {"posts" => [], "tags" => []}},
|
12
|
+
{result: {"posts" => [], "tags" => []}}
|
13
|
+
]
|
14
|
+
|
15
|
+
enhanced = Knuckles::Enhancer.call(
|
16
|
+
prepared,
|
17
|
+
tagless: true,
|
18
|
+
enhancer: lambda do |result, options|
|
19
|
+
if options[:tagless]
|
20
|
+
result.delete_if { |key, _| key == "tags" }
|
21
|
+
end
|
22
|
+
|
23
|
+
result
|
24
|
+
end
|
25
|
+
)
|
26
|
+
|
27
|
+
expect(enhanced).to eq([
|
28
|
+
{result: {"posts" => []}},
|
29
|
+
{result: {"posts" => []}}
|
30
|
+
])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knuckles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Parker Selbert
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/knuckles.rb
|
94
94
|
- lib/knuckles/combiner.rb
|
95
95
|
- lib/knuckles/dumper.rb
|
96
|
+
- lib/knuckles/enhancer.rb
|
96
97
|
- lib/knuckles/fetcher.rb
|
97
98
|
- lib/knuckles/hydrator.rb
|
98
99
|
- lib/knuckles/keygen.rb
|
@@ -103,6 +104,7 @@ files:
|
|
103
104
|
- lib/knuckles/writer.rb
|
104
105
|
- spec/knuckles/combiner_spec.rb
|
105
106
|
- spec/knuckles/dumper_spec.rb
|
107
|
+
- spec/knuckles/enhancer_spec.rb
|
106
108
|
- spec/knuckles/fetcher_spec.rb
|
107
109
|
- spec/knuckles/hydrator_spec.rb
|
108
110
|
- spec/knuckles/keygen_spec.rb
|
@@ -141,6 +143,7 @@ summary: Simple performance aware data serialization
|
|
141
143
|
test_files:
|
142
144
|
- spec/knuckles/combiner_spec.rb
|
143
145
|
- spec/knuckles/dumper_spec.rb
|
146
|
+
- spec/knuckles/enhancer_spec.rb
|
144
147
|
- spec/knuckles/fetcher_spec.rb
|
145
148
|
- spec/knuckles/hydrator_spec.rb
|
146
149
|
- spec/knuckles/keygen_spec.rb
|