cot 0.2.0 → 0.3.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/.ackrc +3 -0
- data/.ruby-version +1 -1
- data/Gemfile.lock +9 -7
- data/cot.gemspec +1 -1
- data/lib/cot.rb +1 -0
- data/lib/cot/collection.rb +8 -6
- data/lib/cot/rspec/matchers.rb +1 -1
- data/lib/cot/version.rb +1 -1
- data/spec/lib/cot/collection_spec.rb +14 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b54755a09317578c48c93d680043d3e6bcf1caab
|
4
|
+
data.tar.gz: a264c498df609509981b8c5afb837a211ad84d36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f71356f473c1de0f94513b553dd8222977744489434808c90de5fa9f130019cb710278b7df826f37b6365d532712886148a28e027cd88c8bda0c5729dfc7cf3
|
7
|
+
data.tar.gz: d25fc72929dd6e80b7ece0d5ccbd02854a8bb49df4376a17d188ae11b1ec8209187a2c9d2717f10fcc8602e7fdad1489b443568e86950231d33b2837fbed54de
|
data/.ackrc
ADDED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.0.0
|
1
|
+
ruby-2.0.0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cot (0.
|
4
|
+
cot (0.3.0)
|
5
5
|
activemodel
|
6
6
|
|
7
7
|
GEM
|
@@ -17,6 +17,8 @@ GEM
|
|
17
17
|
thread_safe (~> 0.1)
|
18
18
|
tzinfo (~> 1.1)
|
19
19
|
ast (2.0.0)
|
20
|
+
astrolabe (1.3.0)
|
21
|
+
parser (>= 2.2.0.pre.3, < 3.0)
|
20
22
|
builder (3.2.2)
|
21
23
|
diff-lcs (1.2.5)
|
22
24
|
docile (1.1.5)
|
@@ -24,7 +26,7 @@ GEM
|
|
24
26
|
json (1.8.1)
|
25
27
|
minitest (5.4.0)
|
26
28
|
multi_json (1.10.1)
|
27
|
-
parser (2.2.0.pre.
|
29
|
+
parser (2.2.0.pre.4)
|
28
30
|
ast (>= 1.1, < 3.0)
|
29
31
|
slop (~> 3.4, >= 3.4.5)
|
30
32
|
powerpack (0.0.9)
|
@@ -44,9 +46,9 @@ GEM
|
|
44
46
|
rspec-mocks (3.0.2)
|
45
47
|
rspec-support (~> 3.0.0)
|
46
48
|
rspec-support (3.0.2)
|
47
|
-
rubocop (0.
|
48
|
-
|
49
|
-
parser (>= 2.2.0.pre.
|
49
|
+
rubocop (0.26.0)
|
50
|
+
astrolabe (~> 1.3)
|
51
|
+
parser (>= 2.2.0.pre.4, < 3.0)
|
50
52
|
powerpack (~> 0.0.6)
|
51
53
|
rainbow (>= 1.99.1, < 3.0)
|
52
54
|
ruby-progressbar (~> 1.4)
|
@@ -62,7 +64,7 @@ GEM
|
|
62
64
|
multi_json
|
63
65
|
simplecov-html (~> 0.8.0)
|
64
66
|
simplecov-html (0.8.0)
|
65
|
-
slop (3.
|
67
|
+
slop (3.6.0)
|
66
68
|
thread_safe (0.3.4)
|
67
69
|
tzinfo (1.2.1)
|
68
70
|
thread_safe (~> 0.1)
|
@@ -75,6 +77,6 @@ DEPENDENCIES
|
|
75
77
|
cot!
|
76
78
|
rspec
|
77
79
|
rspec-its
|
78
|
-
rubocop
|
80
|
+
rubocop (>= 0.26.0)
|
79
81
|
shoulda
|
80
82
|
simplecov
|
data/cot.gemspec
CHANGED
@@ -22,6 +22,6 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency 'bundler', '>= 1.0.0'
|
23
23
|
s.add_development_dependency 'rspec', '>= 0'
|
24
24
|
s.add_development_dependency 'rspec-its', '>= 0'
|
25
|
-
s.add_development_dependency 'rubocop', '>= 0'
|
25
|
+
s.add_development_dependency 'rubocop', '>= 0.26.0'
|
26
26
|
s.add_development_dependency 'simplecov', '>= 0'
|
27
27
|
end
|
data/lib/cot.rb
CHANGED
data/lib/cot/collection.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
module Cot
|
2
2
|
class Collection < SimpleDelegator
|
3
|
-
def initialize(klass, objects,
|
3
|
+
def initialize(klass, objects, options = {})
|
4
|
+
options = { sub_key: options } unless options.is_a?(Hash)
|
5
|
+
@options = options.with_indifferent_access
|
6
|
+
@options[:default_attributes] = {} unless @options[:default_attributes].is_a?(Hash)
|
4
7
|
@klass = klass
|
5
|
-
@sub_key = sub_key
|
6
8
|
@objects = objects
|
7
9
|
|
8
10
|
# If you pass in different types of things here we can't be friends
|
@@ -24,7 +26,7 @@ module Cot
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def errors
|
27
|
-
Hash[@objects.reject
|
29
|
+
Hash[@objects.reject(&:valid?).map { |x| [x.id, x.errors] }]
|
28
30
|
end
|
29
31
|
|
30
32
|
def update_members(payload)
|
@@ -41,10 +43,10 @@ module Cot
|
|
41
43
|
def initialize_objects(objects)
|
42
44
|
@objects = []
|
43
45
|
@objects = objects.map do |payload|
|
44
|
-
if @sub_key
|
45
|
-
@klass.new payload[
|
46
|
+
if @options[:sub_key]
|
47
|
+
@klass.new @options[:default_attributes].merge(payload.fetch(@options[:sub_key], {}))
|
46
48
|
else
|
47
|
-
@klass.new payload
|
49
|
+
@klass.new @options[:default_attributes].merge(payload || {})
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
data/lib/cot/rspec/matchers.rb
CHANGED
@@ -46,7 +46,7 @@ RSpec::Matchers.define :set_property do |field|
|
|
46
46
|
end
|
47
47
|
|
48
48
|
failure_message do
|
49
|
-
failed = @tests.
|
49
|
+
failed = @tests.select { |_, v| !v }.keys
|
50
50
|
"Expected the property #{field} to be set, but the following attributes weren't set correctly #{failed}"
|
51
51
|
end
|
52
52
|
|
data/lib/cot/version.rb
CHANGED
@@ -81,11 +81,24 @@ describe Cot::Collection do
|
|
81
81
|
expect(coll.first).to be_kind_of FakeDouble
|
82
82
|
end
|
83
83
|
|
84
|
-
it 'takes an optional sub_key to pull the object out of the payload' do
|
84
|
+
it 'takes an optional sub_key option to pull the object out of the payload' do
|
85
|
+
coll = Cot::Collection.new FakeDouble, [{ inner: { fooy: :bar } }, { inner: { asdf: :fdas } }], sub_key: :inner
|
86
|
+
expect(coll.first).to be_kind_of FakeDouble
|
87
|
+
expect(coll.first.fooy).to eq :bar
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'takes an optional default_attributes option to add set attributes in every object.' do
|
91
|
+
coll = Cot::Collection.new FakeDouble, [{ fooy: :bar }, { asdf: :fdas }], default_attributes: { foo: :baz }
|
92
|
+
expect(coll).to all be_kind_of FakeDouble
|
93
|
+
expect(coll.map(&:foo).uniq).to eq [:baz]
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'support a legacy optional sub_key parameter to pull the object out of the payload' do
|
85
97
|
coll = Cot::Collection.new FakeDouble, [{ inner: { fooy: :bar } }, { inner: { asdf: :fdas } }], :inner
|
86
98
|
expect(coll.first).to be_kind_of FakeDouble
|
87
99
|
expect(coll.first.fooy).to eq :bar
|
88
100
|
end
|
101
|
+
|
89
102
|
end
|
90
103
|
|
91
104
|
context 'update members' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Henrich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.26.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 0.26.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: simplecov
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,6 +115,7 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
+
- .ackrc
|
118
119
|
- .gitignore
|
119
120
|
- .rubocop.yml
|
120
121
|
- .ruby-gemset
|
@@ -153,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
154
|
version: '0'
|
154
155
|
requirements: []
|
155
156
|
rubyforge_project:
|
156
|
-
rubygems_version: 2.
|
157
|
+
rubygems_version: 2.2.2
|
157
158
|
signing_key:
|
158
159
|
specification_version: 4
|
159
160
|
summary: Simplifies creating models for rest based resources
|