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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23e65c36347ae253cb19476c6e1e71d8780b7892
4
- data.tar.gz: f82fe69db0ce5d3dac0ce47f3fb6a00c608af520
3
+ metadata.gz: 591b51216e927a53f322119b2c11659e905d14fd
4
+ data.tar.gz: 8c3d791c8bb7ee3c74c2726a8cfb99c363850b86
5
5
  SHA512:
6
- metadata.gz: e6a0355d4d8c535bb22e84ba47d35103b547a5b2e29d14919c29d4a4db394ba9cd6f8a8aed5be844bf2ada7f0a84e7e5f7d4b5c5e89eb907fe1f1db760d78de9
7
- data.tar.gz: ecaa21a31b82dc5a063b621ae4aa4588e2753906f14ebfa75e928690bd55722ec40e2ca6601231148c0011172ef42cfa5a670d74e476fa8c2299c927fdff6ee2
6
+ metadata.gz: f425f6ab0594c9a3a9152f47ab05974c0648d3e6185795423d38fe6737d93b12350364d6af9dd9605d86e52d7991d157a445b876c9fadf76a3a621d53a4e740c
7
+ data.tar.gz: b59de05f895f35cae43e727240ab9fe069035258715efea8501eabf1bc9a97edc5bf48f30f4020993b2603cc8963f388c7f333affef38e7eed2124a0ab3b3bc6
data/Gemfile CHANGED
@@ -4,9 +4,11 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :test do
7
+ gem "codeclimate-test-reporter", require: nil
7
8
  gem 'rspec-given'
8
9
  gem 'flexmock'
9
10
  gem 'timecop'
10
11
 
12
+
11
13
  gem 'pry'
12
- end
14
+ end
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 idea than this gem. 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. This is also likely much ligher weight and therefore about half as meta.
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 and it's _mostly_ recommended you don't use this for real. Mostly. But it is awesome.
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
 
@@ -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|
@@ -1,3 +1,3 @@
1
1
  module Schemad
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
@@ -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
@@ -1,4 +1,5 @@
1
- # $LOAD_PATH.unshift "../lib"
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
2
3
 
3
4
  require 'rspec/given'
4
- require 'pry'
5
+ require 'pry'
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.1
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-01-22 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport