superstructure 0.0.1 → 1.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 +4 -4
- data/lib/superstructure/value_obj.rb +7 -7
- data/lib/superstructure/version.rb +1 -1
- data/spec/value_obj_spec.rb +22 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dba89c3e4aeda5883b1f0512c3f4e785ad206b0
|
4
|
+
data.tar.gz: 27d2fbb43f389b2512ca582e9977c11c9daffe1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53a23c060e658cf07599f47ce5009d5b73ce88cfaa285d942fc18591e61371c6cd4982bc29f7e3ac387882d0579201b2aad24cb7d119948f412f527edbecad46
|
7
|
+
data.tar.gz: a99d7e6f99bfce4d57241ed9e7e3a3cf74951f066a50b0234889a477719cde9954889d8aa3a78e12176247553edb207a9001e6658a3087715cbbbbfe0ceadfee
|
@@ -3,10 +3,8 @@ module Superstructure
|
|
3
3
|
class << self
|
4
4
|
def new *arguments, superclass: Object, &blk
|
5
5
|
Class.new(superclass) do
|
6
|
-
attr_reader :to_hash
|
7
|
-
|
8
6
|
define_method(:initialize) do |opts={}|
|
9
|
-
attributes = {}
|
7
|
+
@attributes = {}
|
10
8
|
missing_params = []
|
11
9
|
shadowed_params = []
|
12
10
|
used_params = []
|
@@ -17,10 +15,10 @@ module Superstructure
|
|
17
15
|
used_params << argument << argument.to_s
|
18
16
|
|
19
17
|
elsif opts.has_key?(argument)
|
20
|
-
attributes[argument] = opts[argument]
|
18
|
+
@attributes[argument] = opts[argument]
|
21
19
|
used_params << argument
|
22
20
|
elsif opts.has_key?(argument.to_s)
|
23
|
-
attributes[argument] = opts[argument.to_s]
|
21
|
+
@attributes[argument] = opts[argument.to_s]
|
24
22
|
used_params << argument.to_s
|
25
23
|
else
|
26
24
|
missing_params << argument
|
@@ -36,12 +34,14 @@ module Superstructure
|
|
36
34
|
extra_params: extra_params
|
37
35
|
)
|
38
36
|
end
|
37
|
+
end
|
39
38
|
|
40
|
-
|
39
|
+
def to_hash
|
40
|
+
@attributes.clone
|
41
41
|
end
|
42
42
|
|
43
43
|
def inspect
|
44
|
-
opts =
|
44
|
+
opts = @attributes.map do |k, v|
|
45
45
|
"#{k}=#{v.inspect}"
|
46
46
|
end.join(", ")
|
47
47
|
"#<value_obj #{self.class} #{opts}>"
|
data/spec/value_obj_spec.rb
CHANGED
@@ -20,12 +20,28 @@ RSpec.describe Superstructure::ValueObj do
|
|
20
20
|
expect(foobar.bar).to eq :bar
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
describe "#to_hash" do
|
24
|
+
it "exposes the passed-in options" do
|
25
|
+
foobar = FooBar.new(foo: "foo?", bar: "bar?")
|
26
|
+
expect(foobar.to_hash).to eq({
|
27
|
+
foo: "foo?",
|
28
|
+
bar: "bar?"
|
29
|
+
})
|
30
|
+
end
|
31
|
+
|
32
|
+
it "converts options passed in as strings to symbols" do
|
33
|
+
foobar = FooBar.new("foo" => "foo?", "bar" => "bar?")
|
34
|
+
expect(foobar.to_hash).to eq({
|
35
|
+
foo: "foo?",
|
36
|
+
bar: "bar?"
|
37
|
+
})
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns an object that can be mutated without affecting the value object" do
|
41
|
+
foobar = FooBar.new(foo: "alpha", bar: nil)
|
42
|
+
foobar.to_hash[:foo] = "beta"
|
43
|
+
expect(foobar.foo).to eq "alpha"
|
44
|
+
end
|
29
45
|
end
|
30
46
|
|
31
47
|
it "exposes the parameters as readers" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superstructure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Finnie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|