disposable 0.2.2 → 0.2.3
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/CHANGES.md +7 -1
- data/lib/disposable/twin/collection.rb +5 -0
- data/lib/disposable/twin/default.rb +4 -3
- data/lib/disposable/twin/struct.rb +5 -1
- data/lib/disposable/version.rb +1 -1
- data/test/twin/collection_test.rb +10 -0
- data/test/twin/default_test.rb +11 -0
- data/test/twin/struct_test.rb +6 -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: abc930b3fee06aab580e516948996aff0e05ec45
|
4
|
+
data.tar.gz: 4902d414b02e4fc94ad30ad360d99671f099b3fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa8ef4dae7775e779bb22de5bff27b7d503a7c9af92fef70b43ff3f679baecdbbacf9a53805882ee8368e7780adb9e5ac75a0f13bf9a4f70202f22ee75b09e1e
|
7
|
+
data.tar.gz: c6c45cfcbd947aeb2a7c2cab6ea9b6d7157a2daba38e59c756f73dcb8ce7a534391c6355207e404aeb11dd89999db6703c12ba4f409f231c4668cf922d8956f0
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# 0.2.3
|
2
|
+
|
3
|
+
* Add `Collection#find_by` for easier traversal/querying of twin collections: `album.songs.find_by(id: 1)`.
|
4
|
+
* Fix inheritance of the `:default` option. This would formerly wrap the default value into another `Uber::Options::Value`.
|
5
|
+
* Introduce `Struct#save!`.
|
6
|
+
|
1
7
|
# 0.2.2
|
2
8
|
|
3
9
|
* Use `Uber::Options::Value#call` to evaluate.
|
@@ -105,4 +111,4 @@
|
|
105
111
|
|
106
112
|
# 0.0.4
|
107
113
|
|
108
|
-
* Added `Composition#[]` to access contained models in favor of reader methods to models. The latter got removed. This allows mapping methods with the same name than the contained object.
|
114
|
+
* Added `Composition#[]` to access contained models in favor of reader methods to models. The latter got removed. This allows mapping methods with the same name than the contained object.
|
@@ -14,6 +14,11 @@ module Disposable
|
|
14
14
|
end
|
15
15
|
attr_reader :original # TODO: test me and rethink me.
|
16
16
|
|
17
|
+
def find_by(options)
|
18
|
+
field, value = options.to_a.first
|
19
|
+
find { |item| item.send(field).to_s == value.to_s }
|
20
|
+
end
|
21
|
+
|
17
22
|
# Note that this expects a model, untwinned.
|
18
23
|
def append(model)
|
19
24
|
(self << model).last
|
@@ -10,12 +10,13 @@ module Disposable::Twin::Default
|
|
10
10
|
# TODO: introduce Null object in Declarative::Definition#[].
|
11
11
|
# dfn[:default].(self) # dfn#[] should return a Null object here if empty.
|
12
12
|
return unless dfn[:default]
|
13
|
-
dfn[:default].(self)
|
13
|
+
dfn[:default].(self)
|
14
14
|
end
|
15
15
|
|
16
16
|
module ClassMethods
|
17
|
-
|
18
|
-
|
17
|
+
private
|
18
|
+
def build_definition(name, options={}, &block)
|
19
|
+
options = options.merge(default: Uber::Options::Value.new(options[:default])) if options[:default]
|
19
20
|
super
|
20
21
|
end
|
21
22
|
end
|
data/lib/disposable/version.rb
CHANGED
@@ -39,6 +39,16 @@ class TwinCollectionTest < MiniTest::Spec
|
|
39
39
|
|
40
40
|
end
|
41
41
|
end
|
42
|
+
|
43
|
+
describe "#find_by" do
|
44
|
+
let (:album) { Model::Album.new(1, "The Rest Is Silence", [Model::Song.new(3), Model::Song.new(4)]) }
|
45
|
+
let (:twin) { Twin::Album.new(album) }
|
46
|
+
|
47
|
+
it { twin.songs.find_by(id: 1).must_equal nil }
|
48
|
+
it { twin.songs.find_by(id: 3).must_equal twin.songs[0] }
|
49
|
+
it { twin.songs.find_by(id: 4).must_equal twin.songs[1] }
|
50
|
+
it { twin.songs.find_by(id: "4").must_equal twin.songs[1] }
|
51
|
+
end
|
42
52
|
end
|
43
53
|
|
44
54
|
require "disposable/twin/sync"
|
data/test/twin/default_test.rb
CHANGED
@@ -35,6 +35,17 @@ class DefaultTest < Minitest::Spec
|
|
35
35
|
twin = Twin.new(Song.new(false))
|
36
36
|
twin.title.must_equal false
|
37
37
|
end
|
38
|
+
|
39
|
+
describe "inheritance" do
|
40
|
+
class SuperTwin < Disposable::Twin
|
41
|
+
feature Default
|
42
|
+
property :name, default: "n/a"
|
43
|
+
end
|
44
|
+
class MegaTwin < SuperTwin
|
45
|
+
end
|
46
|
+
|
47
|
+
it { MegaTwin.new(Composer.new).name.must_equal "n/a" }
|
48
|
+
end
|
38
49
|
end
|
39
50
|
|
40
51
|
class DefaultAndVirtualTest < Minitest::Spec
|
data/test/twin/struct_test.rb
CHANGED
@@ -48,7 +48,6 @@ class TwinStructTest < MiniTest::Spec
|
|
48
48
|
# song.send(:model).object_id.must_equal model.object_id
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
52
51
|
end
|
53
52
|
|
54
53
|
|
@@ -96,4 +95,9 @@ class TwinWithNestedStructTest < MiniTest::Spec
|
|
96
95
|
model.options["recorded"].must_equal "yo"
|
97
96
|
model.options["preferences"].must_equal({"show_image" => 9, "play_teaser"=>2})
|
98
97
|
}
|
99
|
-
|
98
|
+
|
99
|
+
|
100
|
+
describe "#save" do
|
101
|
+
it { Song.new(model).extend(Disposable::Twin::Save).save }
|
102
|
+
end
|
103
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disposable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uber
|