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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c025de98f670afc858e54a8b6f7be0b0a91a193
4
- data.tar.gz: 7bf2df28edf8683689a8b5cc52a08a39c243752d
3
+ metadata.gz: 1dba89c3e4aeda5883b1f0512c3f4e785ad206b0
4
+ data.tar.gz: 27d2fbb43f389b2512ca582e9977c11c9daffe1a
5
5
  SHA512:
6
- metadata.gz: b54485982cd3042f02ca18cf6d81e9eaccb6d9a37e610ee124bd66e31cc680f2257aa3298589b571ce8efbd413d9e9af1571d2d343e374522411c89ebb52e576
7
- data.tar.gz: 1e935204cc0f528a86dddc15da0ae668d0e33d81e1125f986801cce33ad648973eed473a6075a540f213ca861bafd757e66a827b58a0f8fef3a7ff45cca1c0b9
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
- @to_hash = attributes
39
+ def to_hash
40
+ @attributes.clone
41
41
  end
42
42
 
43
43
  def inspect
44
- opts = to_hash.map do |k, v|
44
+ opts = @attributes.map do |k, v|
45
45
  "#{k}=#{v.inspect}"
46
46
  end.join(", ")
47
47
  "#<value_obj #{self.class} #{opts}>"
@@ -1,3 +1,3 @@
1
1
  module Superstructure
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -20,12 +20,28 @@ RSpec.describe Superstructure::ValueObj do
20
20
  expect(foobar.bar).to eq :bar
21
21
  end
22
22
 
23
- it "exposes options in the to_hash method" do
24
- foobar = FooBar.new(foo: "foo?", bar: "bar?")
25
- expect(foobar.to_hash).to eq({
26
- foo: "foo?",
27
- bar: "bar?"
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.1
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-13 00:00:00.000000000 Z
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler