destruct 0.0.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 +7 -0
- data/.buildkite/pipeline.yml +9 -0
- data/.gitignore +3 -0
- data/.rspec +3 -0
- data/Dockerfile +2 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +42 -0
- data/LICENSE +20 -0
- data/README.md +683 -0
- data/bin/rubocop +29 -0
- data/bin/test +64 -0
- data/destruct.gemspec +15 -0
- data/docker-compose.yml +21 -0
- data/lib/destruct.rb +39 -0
- data/lib/destruct/dsl.rb +32 -0
- data/lib/destruct/hash.rb +32 -0
- data/lib/destruct/object.rb +12 -0
- data/lib/destruct/resolver.rb +41 -0
- data/spec/destruct/hash_spec.rb +94 -0
- data/spec/destruct/object_spec.rb +42 -0
- data/spec/destruct/resolver_spec.rb +31 -0
- data/spec/destruct_spec.rb +68 -0
- data/spec/spec_helper.rb +15 -0
- metadata +76 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
RSpec.describe Destruct do
|
2
|
+
subject {
|
3
|
+
{
|
4
|
+
body: "test",
|
5
|
+
headers: {
|
6
|
+
content_type: "text/html",
|
7
|
+
status: 200
|
8
|
+
},
|
9
|
+
metadata: {
|
10
|
+
body: "duplicate",
|
11
|
+
one: 1,
|
12
|
+
two: 2,
|
13
|
+
nested: {
|
14
|
+
deep: true,
|
15
|
+
"multiple words" => {
|
16
|
+
test: "example"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
describe "#destruct" do
|
24
|
+
it "returns destruct hash" do
|
25
|
+
actual = subject.destruct(headers: :status)
|
26
|
+
expect(actual).to be_a(described_class::Hash)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "splats destruct hash values" do
|
30
|
+
search = { headers: %i(content_type status) }
|
31
|
+
content_type, status = subject.destruct(search)
|
32
|
+
expect(content_type).to eq("text/html")
|
33
|
+
expect(status).to eq(200)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "parses mixed arguments" do
|
37
|
+
array = %i(metadata nested deep)
|
38
|
+
hash = { headers: %i(content_type status) }
|
39
|
+
|
40
|
+
actual = subject.destruct(:body, array, hash) do
|
41
|
+
metadata
|
42
|
+
metadata.one
|
43
|
+
metadata[:two] if respond_to?(:anything)
|
44
|
+
metadata.nested["multiple words"].test
|
45
|
+
end
|
46
|
+
|
47
|
+
expect(actual.body).to eq("test")
|
48
|
+
expect(actual.content_type).to eq("text/html")
|
49
|
+
expect(actual.status).to eq(200)
|
50
|
+
expect(actual.deep).to eq(true)
|
51
|
+
|
52
|
+
expect(actual.metadata).to eq(subject[:metadata])
|
53
|
+
expect(actual.one).to eq(1)
|
54
|
+
expect(actual.two).to eq(2)
|
55
|
+
expect(actual.test).to eq("example")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "parses keys with the same name" do
|
59
|
+
actual = subject.destruct(:body, metadata: :body)
|
60
|
+
expect(actual.body).to eq("duplicate")
|
61
|
+
expect(actual.size).to eq(1)
|
62
|
+
|
63
|
+
body, metadata_body = actual
|
64
|
+
expect(body).to eq("test")
|
65
|
+
expect(metadata_body).to eq("duplicate")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
if ENV["CODECLIMATE_REPO_TOKEN"]
|
2
|
+
require "codeclimate-test-reporter"
|
3
|
+
CodeClimate::TestReporter.start
|
4
|
+
else
|
5
|
+
require "simplecov"
|
6
|
+
SimpleCov.start { add_filter("/vendor/bundle/") }
|
7
|
+
end
|
8
|
+
|
9
|
+
require File.expand_path("../../lib/destruct", __FILE__)
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.filter_run :focus
|
13
|
+
config.raise_errors_for_deprecations!
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: destruct
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- LendingHome
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: github@lendinghome.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files:
|
18
|
+
- LICENSE
|
19
|
+
files:
|
20
|
+
- ".buildkite/pipeline.yml"
|
21
|
+
- ".gitignore"
|
22
|
+
- ".rspec"
|
23
|
+
- Dockerfile
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE
|
27
|
+
- README.md
|
28
|
+
- bin/rubocop
|
29
|
+
- bin/test
|
30
|
+
- destruct.gemspec
|
31
|
+
- docker-compose.yml
|
32
|
+
- lib/destruct.rb
|
33
|
+
- lib/destruct/dsl.rb
|
34
|
+
- lib/destruct/hash.rb
|
35
|
+
- lib/destruct/object.rb
|
36
|
+
- lib/destruct/resolver.rb
|
37
|
+
- spec/destruct/hash_spec.rb
|
38
|
+
- spec/destruct/object_spec.rb
|
39
|
+
- spec/destruct/resolver_spec.rb
|
40
|
+
- spec/destruct_spec.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
homepage: https://github.com/lendinghome/destruct
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- "--charset=UTF-8"
|
49
|
+
- "--inline-source"
|
50
|
+
- "--line-numbers"
|
51
|
+
- "--main"
|
52
|
+
- README.md
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 2.3.0
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.5.1
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: ES6 style object destructuring in Ruby
|
71
|
+
test_files:
|
72
|
+
- spec/destruct/hash_spec.rb
|
73
|
+
- spec/destruct/object_spec.rb
|
74
|
+
- spec/destruct/resolver_spec.rb
|
75
|
+
- spec/destruct_spec.rb
|
76
|
+
- spec/spec_helper.rb
|