finer_struct 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e77234d562a38294c85ca067153e4e7fadc076d
4
- data.tar.gz: b143677a32cd55a07a1c14d709923f754102c20f
3
+ metadata.gz: a138624305cc893f3f77a51c8c688b77340b0f2c
4
+ data.tar.gz: a9b1f9876dece3c19255d80b49aa303afda049fd
5
5
  SHA512:
6
- metadata.gz: 2f5acd6d885fd1f0347277d6653b7365c20bb56dbf87448e15e1e486af76c394fc24001932e9ec9a7e7d1ffae1d81ff740fc51b7a8d61cb52efc7ab91272d2e6
7
- data.tar.gz: cd328a7638545efd05cb5f353f14465ba714b8f3c4e9f9a0d089885f6fcb6fd5aae67835e3d9f48c6f951be8b6ba4f1b313f608551097ef440c777638648bf32
6
+ metadata.gz: a6e1dfe66882a768136ae35fc733c0ef1c5ab00912cd28ce976247ac403fcbd43024b65b392ab65779d3b2d1e0a8d7284aee908c1b345c6b81a997fe3c116876
7
+ data.tar.gz: 1ec2bed7215fa39ae7716a2a6830f30fc1209a3b631aaef5e23a53dbdbbb979a5d718981d0c3c04d64aff756c3618a77d81edec13f06ef496f6b5e6bbd721cef
@@ -7,15 +7,15 @@ module FinerStruct
7
7
  end
8
8
 
9
9
  def method_missing(method, *arguments)
10
- if @attributes.has_key?(method)
10
+ if has_attribute?(method)
11
11
  @attributes[method]
12
12
  else
13
13
  super
14
14
  end
15
15
  end
16
16
 
17
- def respond_to?(method)
18
- @attributes.has_key?(method) || super
17
+ def respond_to?(method, include_all = false)
18
+ has_attribute?(method) || super
19
19
  end
20
20
 
21
21
  def to_hash
@@ -26,5 +26,10 @@ module FinerStruct
26
26
  other.class == self.class && other.to_hash == to_hash
27
27
  end
28
28
 
29
+ private
30
+
31
+ def has_attribute?(attribute)
32
+ @attributes && @attributes.has_key?(attribute)
33
+ end
29
34
  end
30
35
  end
@@ -6,17 +6,17 @@ module FinerStruct
6
6
  end
7
7
 
8
8
  def method_missing(method, *arguments)
9
- if @attributes.has_key?(method)
9
+ if has_attribute?(method)
10
10
  @attributes[method]
11
- elsif is_assigment?(method) && @attributes.has_key?(key_for_assignment(method))
11
+ elsif is_assigment?(method) && has_attribute?(key_for_assignment(method))
12
12
  @attributes[key_for_assignment(method)] = arguments[0]
13
13
  else
14
14
  super
15
15
  end
16
16
  end
17
17
 
18
- def respond_to?(method)
19
- @attributes.has_key?(method) || super
18
+ def respond_to?(method, include_all = false)
19
+ has_attribute?(method) || super
20
20
  end
21
21
 
22
22
  def to_hash
@@ -37,6 +37,9 @@ module FinerStruct
37
37
  method.to_s[0..-2].to_sym
38
38
  end
39
39
 
40
+ def has_attribute?(attribute)
41
+ @attributes && @attributes.has_key?(attribute)
42
+ end
40
43
  end
41
44
  end
42
45
 
@@ -1,3 +1,3 @@
1
1
  module FinerStruct
2
- VERSION = "0.0.8"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -2,9 +2,11 @@ require 'finer_struct'
2
2
  require 'shared_examples/struct'
3
3
  require 'shared_examples/named'
4
4
  require 'shared_examples/immutable'
5
+ require 'shared_examples/serializable'
5
6
 
6
7
  describe "a named immutable struct" do
7
- let(:klass) { FinerStruct::Immutable(:a, :b) }
8
+ TestNamedImmutableStruct = FinerStruct::Immutable(:a, :b)
9
+ let(:klass) { TestNamedImmutableStruct }
8
10
  subject { klass.new(a: 1, b: 2) }
9
11
  let(:identical) { klass.new(a: 1, b: 2) }
10
12
  let(:different) { klass.new(a: 3, b: 4) }
@@ -12,4 +14,5 @@ describe "a named immutable struct" do
12
14
  it_behaves_like "a struct"
13
15
  it_behaves_like "a named struct"
14
16
  it_behaves_like "an immutable struct"
17
+ it_behaves_like "a serializable"
15
18
  end
@@ -2,9 +2,11 @@ require 'finer_struct'
2
2
  require 'shared_examples/struct'
3
3
  require 'shared_examples/named'
4
4
  require 'shared_examples/mutable'
5
+ require 'shared_examples/serializable'
5
6
 
6
7
  describe "a named mutable struct" do
7
- let(:klass) { FinerStruct::Mutable(:a, :b) }
8
+ TestNamedMutableStruct = FinerStruct::Mutable(:a, :b)
9
+ let(:klass) { TestNamedMutableStruct }
8
10
  subject { klass.new(a: 1, b: 2) }
9
11
  let(:identical) { klass.new(a: 1, b: 2) }
10
12
  let(:different) { klass.new(a: 3, b: 4) }
@@ -12,6 +14,7 @@ describe "a named mutable struct" do
12
14
  it_behaves_like "a struct"
13
15
  it_behaves_like "a named struct"
14
16
  it_behaves_like "a mutable struct"
17
+ it_behaves_like "a serializable"
15
18
 
16
19
  it "allows you alias attribute assignments" do
17
20
  subclass = Class.new(klass) do
@@ -0,0 +1,15 @@
1
+ require 'yaml'
2
+
3
+ shared_examples "a serializable" do
4
+ it "can be serialized and de-serialized via YAML" do
5
+ serialized = YAML.dump(subject)
6
+ deserialized = YAML.load(serialized)
7
+ expect(deserialized).to eq(subject)
8
+ end
9
+
10
+ it "can be serialized and de-serialized via binary" do
11
+ serialized = Marshal.dump(subject)
12
+ deserialized = Marshal.load(serialized)
13
+ expect(deserialized).to eq(subject)
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finer_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Yandell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-21 00:00:00.000000000 Z
11
+ date: 2016-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -79,6 +79,7 @@ files:
79
79
  - spec/shared_examples/immutable.rb
80
80
  - spec/shared_examples/mutable.rb
81
81
  - spec/shared_examples/named.rb
82
+ - spec/shared_examples/serializable.rb
82
83
  - spec/shared_examples/struct.rb
83
84
  homepage: https://github.com/notahat/finer_struct
84
85
  licenses:
@@ -100,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  version: '0'
101
102
  requirements: []
102
103
  rubyforge_project:
103
- rubygems_version: 2.4.5
104
+ rubygems_version: 2.5.1
104
105
  signing_key:
105
106
  specification_version: 4
106
107
  summary: A nicer replacement for Ruby's Struct and OpenStruct
@@ -112,4 +113,5 @@ test_files:
112
113
  - spec/shared_examples/immutable.rb
113
114
  - spec/shared_examples/mutable.rb
114
115
  - spec/shared_examples/named.rb
116
+ - spec/shared_examples/serializable.rb
115
117
  - spec/shared_examples/struct.rb