schemad 1.2.1 → 1.2.2
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/Gemfile +3 -1
- data/README.md +2 -2
- data/lib/schemad/entity.rb +5 -1
- data/lib/schemad/version.rb +1 -1
- data/spec/entity_spec.rb +54 -0
- data/spec/spec_helper.rb +3 -2
- 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: 591b51216e927a53f322119b2c11659e905d14fd
|
4
|
+
data.tar.gz: 8c3d791c8bb7ee3c74c2726a8cfb99c363850b86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f425f6ab0594c9a3a9152f47ab05974c0648d3e6185795423d38fe6737d93b12350364d6af9dd9605d86e52d7991d157a445b876c9fadf76a3a621d53a4e740c
|
7
|
+
data.tar.gz: b59de05f895f35cae43e727240ab9fe069035258715efea8501eabf1bc9a97edc5bf48f30f4020993b2603cc8963f388c7f333affef38e7eed2124a0ab3b3bc6
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -311,9 +311,9 @@ commit.comment # "Your Mom"
|
|
311
311
|
|
312
312
|
## Notes
|
313
313
|
|
314
|
-
[Hashie](https://github.com/intridea/hashie) is probably a better
|
314
|
+
[Hashie](https://github.com/intridea/hashie) is probably a better fit for most people, but I couldn't find a decent way to combine the [DeepFetch](https://github.com/intridea/hashie#deepfetch) functionality with the [Dash](https://github.com/intridea/hashie#dash)/[Trash](https://github.com/intridea/hashie#trash) functionality. However, this gem is also likely much ligher weight and therefore about half as meta.
|
315
315
|
|
316
|
-
Be warned, this is a lot of crazy metacode
|
316
|
+
Be warned, this is a lot of crazy metacode, but it does work well for most of my use-cases (as seen in the examples above).
|
317
317
|
|
318
318
|
## Installation
|
319
319
|
|
data/lib/schemad/entity.rb
CHANGED
@@ -6,7 +6,7 @@ module Schemad
|
|
6
6
|
extend Schemad::Extensions
|
7
7
|
|
8
8
|
def self.inherited(subclass)
|
9
|
-
subclass.instance_variable_set(:@attributes,
|
9
|
+
subclass.instance_variable_set(:@attributes, inherited_attrs)
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.attribute(name, args={}, &block)
|
@@ -45,6 +45,10 @@ module Schemad
|
|
45
45
|
alias_method :attributes, :to_hash
|
46
46
|
|
47
47
|
private
|
48
|
+
def self.inherited_attrs
|
49
|
+
parent_attrs = self.instance_variable_get(:@attributes)
|
50
|
+
default_attrs = (parent_attrs ? parent_attrs.dup : [])
|
51
|
+
end
|
48
52
|
|
49
53
|
def self.define_parser_for(name, args, &block)
|
50
54
|
define_method "parse_#{name}" do |data|
|
data/lib/schemad/version.rb
CHANGED
data/spec/entity_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'timecop'
|
3
|
+
require 'schemad/default_types'
|
3
4
|
require 'schemad/entity'
|
4
5
|
|
5
6
|
require_relative 'fixtures/demo_class'
|
@@ -53,4 +54,57 @@ describe Schemad::Entity do
|
|
53
54
|
}}
|
54
55
|
end
|
55
56
|
end
|
57
|
+
|
58
|
+
context "inherited entities" do
|
59
|
+
class Base < Schemad::Entity
|
60
|
+
attribute :name
|
61
|
+
end
|
62
|
+
|
63
|
+
class Sub < Base
|
64
|
+
attribute :place
|
65
|
+
end
|
66
|
+
|
67
|
+
context "via setters" do
|
68
|
+
Given(:parent) { Base.new }
|
69
|
+
Given(:child) { Sub.new }
|
70
|
+
|
71
|
+
context "parent has top-level attributes" do
|
72
|
+
When { parent.name = "Whil Wheaton" }
|
73
|
+
Then { parent.name.should == "Whil Wheaton" }
|
74
|
+
end
|
75
|
+
|
76
|
+
context "parent does not get child attributes" do
|
77
|
+
When(:result) { parent.place }
|
78
|
+
Then { expect(result).to have_failed(NoMethodError) }
|
79
|
+
end
|
80
|
+
|
81
|
+
context "child has all attributes" do
|
82
|
+
Given do
|
83
|
+
child.name = "Bill Cosby"
|
84
|
+
child.place = "NY, NY"
|
85
|
+
end
|
86
|
+
Then { child.name.should == "Bill Cosby" }
|
87
|
+
And { child.place.should == "NY, NY" }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'via #from_data' do
|
92
|
+
Given(:parent) { Base.from_data({ name: "Whil Wheaton", place: "Burt's Bees" }) }
|
93
|
+
|
94
|
+
context "parent has top-level attributes" do
|
95
|
+
Then { parent.name.should == "Whil Wheaton" }
|
96
|
+
end
|
97
|
+
|
98
|
+
context "parent does not get child attributes" do
|
99
|
+
When(:result) { parent.place }
|
100
|
+
Then { expect(result).to have_failed(NoMethodError) }
|
101
|
+
end
|
102
|
+
|
103
|
+
context "child has all attributes" do
|
104
|
+
Given(:child) { Sub.from_data({ name: "Jim Beam", place: "Black, Not" }) }
|
105
|
+
Then { child.name.should == "Jim Beam" }
|
106
|
+
And { child.place.should == "Black, Not" }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
56
110
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke van der Hoeven
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|