knuckles 0.2.0 → 0.3.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/CHANGELOG.md +8 -0
- data/README.md +40 -13
- data/lib/knuckles/keygen.rb +22 -0
- data/lib/knuckles/pipeline.rb +82 -26
- data/lib/knuckles/stages/combiner.rb +24 -0
- data/lib/knuckles/stages/dumper.rb +23 -0
- data/lib/knuckles/stages/enhancer.rb +21 -0
- data/lib/knuckles/stages/fetcher.rb +30 -0
- data/lib/knuckles/stages/hydrator.rb +29 -0
- data/lib/knuckles/stages/renderer.rb +27 -0
- data/lib/knuckles/stages/writer.rb +41 -0
- data/lib/knuckles/stages.rb +13 -0
- data/lib/knuckles/version.rb +1 -1
- data/lib/knuckles/view.rb +104 -5
- data/lib/knuckles.rb +55 -7
- data/spec/knuckles/pipeline_spec.rb +0 -40
- data/spec/knuckles/{combiner_spec.rb → stages/combiner_spec.rb} +2 -2
- data/spec/knuckles/{dumper_spec.rb → stages/dumper_spec.rb} +2 -2
- data/spec/knuckles/{enhancer_spec.rb → stages/enhancer_spec.rb} +3 -3
- data/spec/knuckles/{fetcher_spec.rb → stages/fetcher_spec.rb} +3 -3
- data/spec/knuckles/{hydrator_spec.rb → stages/hydrator_spec.rb} +3 -3
- data/spec/knuckles/{renderer_spec.rb → stages/renderer_spec.rb} +2 -2
- data/spec/knuckles/{writer_spec.rb → stages/writer_spec.rb} +3 -3
- metadata +31 -43
- data/.gitignore +0 -15
- data/.rspec +0 -2
- data/.rubocop.yml +0 -41
- data/.travis.yml +0 -10
- data/Gemfile +0 -11
- data/Rakefile +0 -9
- data/bench/bench_helper.rb +0 -48
- data/bench/fixtures/serializers.rb +0 -93
- data/bench/fixtures/submissions.json +0 -1
- data/bench/profiling.rb +0 -14
- data/bench/realistic.rb +0 -9
- data/bench/simple.rb +0 -25
- data/bin/rspec +0 -16
- data/knuckles.gemspec +0 -24
- data/lib/knuckles/combiner.rb +0 -26
- data/lib/knuckles/dumper.rb +0 -25
- data/lib/knuckles/enhancer.rb +0 -23
- data/lib/knuckles/fetcher.rb +0 -32
- data/lib/knuckles/hydrator.rb +0 -31
- data/lib/knuckles/renderer.rb +0 -29
- data/lib/knuckles/writer.rb +0 -43
data/lib/knuckles.rb
CHANGED
@@ -4,46 +4,94 @@ require "active_support/notifications"
|
|
4
4
|
require "active_support/cache"
|
5
5
|
require "json"
|
6
6
|
|
7
|
+
# Knuckles is a performance focused data serialization pipeline. More simply,
|
8
|
+
# it tries to serialize models into large JSON payloads as quickly as possible.
|
9
|
+
# It operates on a collection of data through stages, passing them through a
|
10
|
+
# pipeline of transformations.
|
11
|
+
#
|
12
|
+
# The default configuration uses `MemoryStore`, but you can configure it along
|
13
|
+
# with other customizations.
|
14
|
+
#
|
15
|
+
# @example Configuration
|
16
|
+
#
|
17
|
+
# Knuckles.configure do |config|
|
18
|
+
# config.cache = Readthis::Cache.new
|
19
|
+
# config.keygen = Readthis::Expanders
|
20
|
+
# config.serializer = Oj
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# With the module configured you can begin transforming models into JSON (or
|
24
|
+
# MessagePack, whatever your API uses):
|
25
|
+
#
|
26
|
+
# @example Usage with default pipeline
|
27
|
+
#
|
28
|
+
# Knuckles.new.call(models, view: SubmissionView) #=>
|
29
|
+
# '{"submissions":[], "tags":[], "responses":[]}'
|
30
|
+
#
|
7
31
|
module Knuckles
|
8
|
-
autoload :Combiner, "knuckles/combiner"
|
9
|
-
autoload :Dumper, "knuckles/dumper"
|
10
|
-
autoload :Enhancer, "knuckles/enhancer"
|
11
|
-
autoload :Fetcher, "knuckles/fetcher"
|
12
|
-
autoload :Hydrator, "knuckles/hydrator"
|
13
32
|
autoload :Keygen, "knuckles/keygen"
|
14
33
|
autoload :Pipeline, "knuckles/pipeline"
|
15
|
-
autoload :
|
34
|
+
autoload :Stages, "knuckles/stages"
|
16
35
|
autoload :View, "knuckles/view"
|
17
|
-
autoload :Writer, "knuckles/writer"
|
18
36
|
|
19
37
|
extend self
|
20
38
|
|
21
39
|
attr_writer :cache, :keygen, :notifications, :serializer
|
22
40
|
|
41
|
+
# Convenience method for initializing a new `Pipeline`
|
42
|
+
#
|
43
|
+
# @see Knuckles::Pipeline#initialize
|
44
|
+
#
|
23
45
|
def new(*args)
|
24
46
|
Knuckles::Pipeline.new(*args)
|
25
47
|
end
|
26
48
|
|
49
|
+
# Module accessor for `cache`, defaults to `Cache::MemoryStore`
|
50
|
+
#
|
51
|
+
# @return [#cache] A cache instance
|
52
|
+
#
|
27
53
|
def cache
|
28
54
|
@cache ||= ActiveSupport::Cache::MemoryStore.new
|
29
55
|
end
|
30
56
|
|
57
|
+
# Module accessor `keygen`, defaults to `Knuckles::Keygen`
|
58
|
+
#
|
59
|
+
# @return [Module] Cache key generation module
|
60
|
+
#
|
31
61
|
def keygen
|
32
62
|
@keygen ||= Knuckles::Keygen
|
33
63
|
end
|
34
64
|
|
65
|
+
# Module accessor for `notifications`, defaults to
|
66
|
+
# `ActiveSupport::Notifications`
|
67
|
+
#
|
68
|
+
# @return [Module] Instrumentation module
|
69
|
+
#
|
35
70
|
def notifications
|
36
71
|
@notifications ||= ActiveSupport::Notifications
|
37
72
|
end
|
38
73
|
|
74
|
+
# Module accessor for `serializer`, defaults to `JSON`
|
75
|
+
#
|
76
|
+
# @return [Module] The serializer
|
77
|
+
#
|
39
78
|
def serializer
|
40
79
|
@serializer ||= JSON
|
41
80
|
end
|
42
81
|
|
82
|
+
# Convenience for setting properties as within a block
|
83
|
+
#
|
84
|
+
# @example Configuring knuckles
|
85
|
+
#
|
86
|
+
# Knuckles.configure do |config|
|
87
|
+
# config.serializer = MessagePack
|
88
|
+
# end
|
89
|
+
#
|
43
90
|
def configure
|
44
91
|
yield self
|
45
92
|
end
|
46
93
|
|
94
|
+
# @private
|
47
95
|
def reset!
|
48
96
|
@cache = nil
|
49
97
|
@keygen = nil
|
@@ -13,46 +13,6 @@ RSpec.describe Knuckles::Pipeline do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe "#delete" do
|
17
|
-
it "removes an existing stage" do
|
18
|
-
pipeline = Knuckles::Pipeline.new
|
19
|
-
|
20
|
-
pipeline.delete(Knuckles::Writer)
|
21
|
-
|
22
|
-
expect(pipeline.stages).not_to include(Knuckles::Writer)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "#insert_after" do
|
27
|
-
it "adds a stage after an existing stage" do
|
28
|
-
custom = Module.new
|
29
|
-
pipeline = Knuckles::Pipeline.new
|
30
|
-
|
31
|
-
pipeline.insert_after(Knuckles::Fetcher, custom)
|
32
|
-
|
33
|
-
expect(pipeline.stages).to include(custom)
|
34
|
-
expect(pipeline.stages.take(2)).to eq([
|
35
|
-
Knuckles::Fetcher,
|
36
|
-
custom
|
37
|
-
])
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#insert_before" do
|
42
|
-
it "adds a stage after an existing stage" do
|
43
|
-
custom = Module.new
|
44
|
-
pipeline = Knuckles::Pipeline.new
|
45
|
-
|
46
|
-
pipeline.insert_before(Knuckles::Fetcher, custom)
|
47
|
-
|
48
|
-
expect(pipeline.stages).to include(custom)
|
49
|
-
expect(pipeline.stages.take(2)).to eq([
|
50
|
-
custom,
|
51
|
-
Knuckles::Fetcher
|
52
|
-
])
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
16
|
describe "#call" do
|
57
17
|
it "aggregates the result of all stages" do
|
58
18
|
filter_a = Module.new do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
RSpec.describe Knuckles::Combiner do
|
1
|
+
RSpec.describe Knuckles::Stages::Combiner do
|
2
2
|
describe ".call" do
|
3
3
|
it "merges all results into a single object" do
|
4
4
|
prepared = [
|
@@ -16,7 +16,7 @@ RSpec.describe Knuckles::Combiner do
|
|
16
16
|
}
|
17
17
|
]
|
18
18
|
|
19
|
-
combined = Knuckles::Combiner.call(prepared, {})
|
19
|
+
combined = Knuckles::Stages::Combiner.call(prepared, {})
|
20
20
|
|
21
21
|
expect(combined).to eq(
|
22
22
|
"author" => [
|
@@ -1,4 +1,4 @@
|
|
1
|
-
RSpec.describe Knuckles::Dumper do
|
1
|
+
RSpec.describe Knuckles::Stages::Dumper do
|
2
2
|
describe ".call" do
|
3
3
|
it "dumps a tree of objects" do
|
4
4
|
objects = {
|
@@ -16,7 +16,7 @@ RSpec.describe Knuckles::Dumper do
|
|
16
16
|
]
|
17
17
|
}
|
18
18
|
|
19
|
-
dumped = Knuckles::Dumper.call(objects, {})
|
19
|
+
dumped = Knuckles::Stages::Dumper.call(objects, {})
|
20
20
|
|
21
21
|
expect(dumped).to eq(
|
22
22
|
JSON.dump(
|
@@ -1,9 +1,9 @@
|
|
1
|
-
RSpec.describe Knuckles::Enhancer do
|
1
|
+
RSpec.describe Knuckles::Stages::Enhancer do
|
2
2
|
describe ".call" do
|
3
3
|
it "is a noop without an enhancer lambda" do
|
4
4
|
prepared = [Tag.new(1, "alpha")]
|
5
5
|
|
6
|
-
expect(Knuckles::Enhancer.call(prepared, {})).to eq(prepared)
|
6
|
+
expect(Knuckles::Stages::Enhancer.call(prepared, {})).to eq(prepared)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "modifies the rendered values with a lambda" do
|
@@ -12,7 +12,7 @@ RSpec.describe Knuckles::Enhancer do
|
|
12
12
|
{result: {"posts" => [], "tags" => []}}
|
13
13
|
]
|
14
14
|
|
15
|
-
enhanced = Knuckles::Enhancer.call(
|
15
|
+
enhanced = Knuckles::Stages::Enhancer.call(
|
16
16
|
prepared,
|
17
17
|
tagless: true,
|
18
18
|
enhancer: lambda do |result, options|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
RSpec.describe Knuckles::Fetcher do
|
1
|
+
RSpec.describe Knuckles::Stages::Fetcher do
|
2
2
|
describe ".call" do
|
3
3
|
it "fetches all cached data for top level objects" do
|
4
4
|
objects = [Tag.new(1, "alpha"), Tag.new(2, "gamma")]
|
@@ -6,7 +6,7 @@ RSpec.describe Knuckles::Fetcher do
|
|
6
6
|
Knuckles.cache.write(Knuckles.keygen.expand_key(objects.first), "result")
|
7
7
|
|
8
8
|
objects = prepare(objects)
|
9
|
-
results = Knuckles::Fetcher.call(objects, {})
|
9
|
+
results = Knuckles::Stages::Fetcher.call(objects, {})
|
10
10
|
|
11
11
|
expect(pluck(results, :result)).to eq(["result", nil])
|
12
12
|
expect(pluck(results, :cached?)).to eq([true, false])
|
@@ -20,7 +20,7 @@ RSpec.describe Knuckles::Fetcher do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
objects = prepare([Tag.new(1, "alpha")])
|
23
|
-
results = Knuckles::Fetcher.call(objects, keygen: keygen)
|
23
|
+
results = Knuckles::Stages::Fetcher.call(objects, keygen: keygen)
|
24
24
|
|
25
25
|
expect(pluck(results, :key)).to eq(["alpha"])
|
26
26
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
RSpec.describe Knuckles::Hydrator do
|
1
|
+
RSpec.describe Knuckles::Stages::Hydrator do
|
2
2
|
describe ".call" do
|
3
3
|
it "is a noop without a hydrate lambda" do
|
4
4
|
objects = [Tag.new(1, "alpha")]
|
5
5
|
|
6
|
-
expect(Knuckles::Hydrator.call(objects, {})).to eq(objects)
|
6
|
+
expect(Knuckles::Stages::Hydrator.call(objects, {})).to eq(objects)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "refines the object collection using hydrate" do
|
@@ -14,7 +14,7 @@ RSpec.describe Knuckles::Hydrator do
|
|
14
14
|
hashes.each { |hash| hash[:object] = :updated }
|
15
15
|
end
|
16
16
|
|
17
|
-
hydrated = Knuckles::Hydrator.call(prepared, hydrate: hydrate)
|
17
|
+
hydrated = Knuckles::Stages::Hydrator.call(prepared, hydrate: hydrate)
|
18
18
|
|
19
19
|
expect(hydrated.map { |hash| hash[:object] }).to eq([:updated, :updated])
|
20
20
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
RSpec.describe Knuckles::Renderer do
|
1
|
+
RSpec.describe Knuckles::Stages::Renderer do
|
2
2
|
describe ".call" do
|
3
3
|
it "serializes a collection of objects" do
|
4
4
|
tag_a = Tag.new(1, "alpha")
|
@@ -7,7 +7,7 @@ RSpec.describe Knuckles::Renderer do
|
|
7
7
|
post_b = Post.new(2, "there", [tag_a])
|
8
8
|
|
9
9
|
objects = prepare([post_a, post_b])
|
10
|
-
results = Knuckles::Renderer.call(objects, view: PostView)
|
10
|
+
results = Knuckles::Stages::Renderer.call(objects, view: PostView)
|
11
11
|
|
12
12
|
expect(results[0][:result]).to eq(
|
13
13
|
posts: [
|
@@ -1,4 +1,4 @@
|
|
1
|
-
RSpec.describe Knuckles::Writer do
|
1
|
+
RSpec.describe Knuckles::Stages::Writer do
|
2
2
|
class FakeCache
|
3
3
|
def write_multi(*)
|
4
4
|
true
|
@@ -16,7 +16,7 @@ RSpec.describe Knuckles::Writer do
|
|
16
16
|
{key: "t/2/2", cached?: false, result: {tags: [{id: 2, name: "b"}]}}
|
17
17
|
]
|
18
18
|
|
19
|
-
result = Knuckles::Writer.call(prepared, {})
|
19
|
+
result = Knuckles::Stages::Writer.call(prepared, {})
|
20
20
|
|
21
21
|
expect(result).to eq(prepared)
|
22
22
|
expect(Knuckles.cache.read("t/1/1")).to be_nil
|
@@ -33,7 +33,7 @@ RSpec.describe Knuckles::Writer do
|
|
33
33
|
|
34
34
|
expect(Knuckles.cache).to receive(:write_multi) { true }
|
35
35
|
|
36
|
-
result = Knuckles::Writer.call(prepared, {})
|
36
|
+
result = Knuckles::Stages::Writer.call(prepared, {})
|
37
37
|
|
38
38
|
expect(result).to eq(prepared)
|
39
39
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knuckles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Parker Selbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,50 +73,37 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- ".gitignore"
|
77
|
-
- ".rspec"
|
78
|
-
- ".rubocop.yml"
|
79
|
-
- ".travis.yml"
|
80
76
|
- CHANGELOG.md
|
81
|
-
- Gemfile
|
82
77
|
- LICENSE.txt
|
83
78
|
- README.md
|
84
|
-
- Rakefile
|
85
|
-
- bench/bench_helper.rb
|
86
|
-
- bench/fixtures/serializers.rb
|
87
|
-
- bench/fixtures/submissions.json
|
88
|
-
- bench/profiling.rb
|
89
|
-
- bench/realistic.rb
|
90
|
-
- bench/simple.rb
|
91
|
-
- bin/rspec
|
92
|
-
- knuckles.gemspec
|
93
79
|
- lib/knuckles.rb
|
94
|
-
- lib/knuckles/combiner.rb
|
95
|
-
- lib/knuckles/dumper.rb
|
96
|
-
- lib/knuckles/enhancer.rb
|
97
|
-
- lib/knuckles/fetcher.rb
|
98
|
-
- lib/knuckles/hydrator.rb
|
99
80
|
- lib/knuckles/keygen.rb
|
100
81
|
- lib/knuckles/pipeline.rb
|
101
|
-
- lib/knuckles/
|
82
|
+
- lib/knuckles/stages.rb
|
83
|
+
- lib/knuckles/stages/combiner.rb
|
84
|
+
- lib/knuckles/stages/dumper.rb
|
85
|
+
- lib/knuckles/stages/enhancer.rb
|
86
|
+
- lib/knuckles/stages/fetcher.rb
|
87
|
+
- lib/knuckles/stages/hydrator.rb
|
88
|
+
- lib/knuckles/stages/renderer.rb
|
89
|
+
- lib/knuckles/stages/writer.rb
|
102
90
|
- lib/knuckles/version.rb
|
103
91
|
- lib/knuckles/view.rb
|
104
|
-
- lib/knuckles/writer.rb
|
105
|
-
- spec/knuckles/combiner_spec.rb
|
106
|
-
- spec/knuckles/dumper_spec.rb
|
107
|
-
- spec/knuckles/enhancer_spec.rb
|
108
|
-
- spec/knuckles/fetcher_spec.rb
|
109
|
-
- spec/knuckles/hydrator_spec.rb
|
110
92
|
- spec/knuckles/keygen_spec.rb
|
111
93
|
- spec/knuckles/pipeline_spec.rb
|
112
|
-
- spec/knuckles/
|
94
|
+
- spec/knuckles/stages/combiner_spec.rb
|
95
|
+
- spec/knuckles/stages/dumper_spec.rb
|
96
|
+
- spec/knuckles/stages/enhancer_spec.rb
|
97
|
+
- spec/knuckles/stages/fetcher_spec.rb
|
98
|
+
- spec/knuckles/stages/hydrator_spec.rb
|
99
|
+
- spec/knuckles/stages/renderer_spec.rb
|
100
|
+
- spec/knuckles/stages/writer_spec.rb
|
113
101
|
- spec/knuckles/view_spec.rb
|
114
|
-
- spec/knuckles/writer_spec.rb
|
115
102
|
- spec/knuckles_spec.rb
|
116
103
|
- spec/spec_helper.rb
|
117
104
|
- spec/support/models.rb
|
118
105
|
- spec/support/views.rb
|
119
|
-
homepage:
|
106
|
+
homepage: https://github.com/sorentwo/knuckles
|
120
107
|
licenses:
|
121
108
|
- MIT
|
122
109
|
metadata: {}
|
@@ -141,17 +128,18 @@ signing_key:
|
|
141
128
|
specification_version: 4
|
142
129
|
summary: Simple performance aware data serialization
|
143
130
|
test_files:
|
144
|
-
- spec/knuckles/combiner_spec.rb
|
145
|
-
- spec/knuckles/dumper_spec.rb
|
146
|
-
- spec/knuckles/enhancer_spec.rb
|
147
|
-
- spec/knuckles/fetcher_spec.rb
|
148
|
-
- spec/knuckles/hydrator_spec.rb
|
149
131
|
- spec/knuckles/keygen_spec.rb
|
150
132
|
- spec/knuckles/pipeline_spec.rb
|
151
|
-
- spec/knuckles/
|
133
|
+
- spec/knuckles/stages/combiner_spec.rb
|
134
|
+
- spec/knuckles/stages/dumper_spec.rb
|
135
|
+
- spec/knuckles/stages/enhancer_spec.rb
|
136
|
+
- spec/knuckles/stages/fetcher_spec.rb
|
137
|
+
- spec/knuckles/stages/hydrator_spec.rb
|
138
|
+
- spec/knuckles/stages/renderer_spec.rb
|
139
|
+
- spec/knuckles/stages/writer_spec.rb
|
152
140
|
- spec/knuckles/view_spec.rb
|
153
|
-
- spec/knuckles/writer_spec.rb
|
154
141
|
- spec/knuckles_spec.rb
|
155
142
|
- spec/spec_helper.rb
|
156
143
|
- spec/support/models.rb
|
157
144
|
- spec/support/views.rb
|
145
|
+
has_rdoc:
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
AllCops:
|
2
|
-
Exclude:
|
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/**/*"
|
15
|
-
|
16
|
-
Style/IfUnlessModifier:
|
17
|
-
Enabled: false
|
18
|
-
|
19
|
-
# Documentation is coming
|
20
|
-
Style/Documentation:
|
21
|
-
Enabled: false
|
22
|
-
|
23
|
-
# Extend self preserves private methods
|
24
|
-
Style/ModuleFunction:
|
25
|
-
Enabled: false
|
26
|
-
|
27
|
-
Style/PredicateName:
|
28
|
-
NamePrefix:
|
29
|
-
- is_
|
30
|
-
NamePrefixBlacklist:
|
31
|
-
- is_
|
32
|
-
|
33
|
-
Style/StringLiterals:
|
34
|
-
EnforcedStyle: double_quotes
|
35
|
-
|
36
|
-
Style/SpaceInsideHashLiteralBraces:
|
37
|
-
EnforcedStyle: no_space
|
38
|
-
EnforcedStyleForEmptyBraces: no_space
|
39
|
-
|
40
|
-
Style/IndentArray:
|
41
|
-
Enabled: false
|
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/bench/bench_helper.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require "bundler"
|
2
|
-
|
3
|
-
Bundler.setup
|
4
|
-
|
5
|
-
require "active_support/cache"
|
6
|
-
require "benchmark/ips"
|
7
|
-
require "json"
|
8
|
-
require "knuckles"
|
9
|
-
require_relative "fixtures/serializers"
|
10
|
-
|
11
|
-
class BenchModel
|
12
|
-
attr_reader :key
|
13
|
-
|
14
|
-
def initialize(key, attributes)
|
15
|
-
attributes.each do |key, value|
|
16
|
-
self.class.send(:define_method, key) { value }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def cache_key
|
21
|
-
"#{key}/#{id}/#{updated_at}"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
module BenchHelper
|
26
|
-
extend self
|
27
|
-
|
28
|
-
def submissions
|
29
|
-
mapping = %w[scout responses tags]
|
30
|
-
loaded = JSON.load(IO.read("bench/fixtures/submissions.json"))
|
31
|
-
|
32
|
-
loaded.map do |object|
|
33
|
-
mapping.each do |key|
|
34
|
-
object[key] = structify(key, object[key])
|
35
|
-
end
|
36
|
-
|
37
|
-
structify('submissions', object)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def structify(key, object)
|
42
|
-
if object.is_a?(Array)
|
43
|
-
object.map { |obj| BenchModel.new(key, obj) }
|
44
|
-
else
|
45
|
-
BenchModel.new(key, object)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
module ScoutView
|
2
|
-
extend Knuckles::View
|
3
|
-
|
4
|
-
def self.root
|
5
|
-
:scouts
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.data(object, _)
|
9
|
-
{ id: object.id,
|
10
|
-
first_name: object.first_name,
|
11
|
-
gender: object.gender,
|
12
|
-
city: object.city,
|
13
|
-
state: object.state,
|
14
|
-
country: object.country,
|
15
|
-
education: object.education,
|
16
|
-
employment_status: object.employment_status,
|
17
|
-
ethnicity: object.ethnicity,
|
18
|
-
household_composition: object.household_composition,
|
19
|
-
household_income: object.household_income,
|
20
|
-
industry: object.industry,
|
21
|
-
created_at: object.created_at,
|
22
|
-
updated_at: object.updated_at }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
module ResponseView
|
27
|
-
extend Knuckles::View
|
28
|
-
|
29
|
-
def self.root
|
30
|
-
:responses
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.data(object, _)
|
34
|
-
{ id: object.id,
|
35
|
-
answers: object.answers,
|
36
|
-
question_id: object.question_id,
|
37
|
-
respondable_id: object.respondable_id,
|
38
|
-
longitude: object.longitude,
|
39
|
-
latitude: object.latitude,
|
40
|
-
time_zone: object.time_zone,
|
41
|
-
answered_at: object.answered_at,
|
42
|
-
created_at: object.created_at,
|
43
|
-
updated_at: object.updated_at }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
module TagView
|
48
|
-
extend Knuckles::View
|
49
|
-
|
50
|
-
def self.root
|
51
|
-
:tags
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.data(object, _)
|
55
|
-
{ id: object.id,
|
56
|
-
parent_id: object.parent_id,
|
57
|
-
name: object.name,
|
58
|
-
group: object.group,
|
59
|
-
auto_tag: object.auto_tag,
|
60
|
-
keywords: object.keywords,
|
61
|
-
created_at: object.created_at,
|
62
|
-
updated_at: object.updated_at }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
module SubmissionView
|
67
|
-
extend Knuckles::View
|
68
|
-
|
69
|
-
def self.root
|
70
|
-
:submissions
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.data(object, _)
|
74
|
-
{ id: object.id,
|
75
|
-
screener_id: object.screener_id,
|
76
|
-
rating: object.rating,
|
77
|
-
latitude: object.latitude,
|
78
|
-
longitude: object.longitude,
|
79
|
-
source: object.source,
|
80
|
-
time_zone: object.time_zone,
|
81
|
-
bookmarks_count: object.bookmarks_count,
|
82
|
-
notes_count: object.notes_count,
|
83
|
-
finished_at: object.finished_at,
|
84
|
-
created_at: object.created_at,
|
85
|
-
updated_at: object.updated_at }
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.relations(object, _)
|
89
|
-
{ scouts: has_one(object.scout, ScoutView),
|
90
|
-
responses: has_many(object.responses, ResponseView),
|
91
|
-
tags: has_many(object.tags, TagView) }
|
92
|
-
end
|
93
|
-
end
|