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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f714cb418f7788e8fdfe157660f02e9899a1e457
4
- data.tar.gz: d9aff55447493719b64c2b88a5c44d4668b40765
3
+ metadata.gz: abc930b3fee06aab580e516948996aff0e05ec45
4
+ data.tar.gz: 4902d414b02e4fc94ad30ad360d99671f099b3fc
5
5
  SHA512:
6
- metadata.gz: 8f3fb2157bd0afa059d7cf1f964964f3db9c00608a1c67aa7daeb68624b02b4dd10f64048e2ba4b98c9a5a153df7177b6d1fc8c95e22cb42911138f7056fda61
7
- data.tar.gz: 97dae2d7decbe780d89697925d23ea6dec33a54c3e69b9f61b71121483323d9c7ff0b1af33405a0d4862d9a595199d90c3d414617bdf76dc53a66eea8c7fb2c5
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) # TODO: use .()
13
+ dfn[:default].(self)
14
14
  end
15
15
 
16
16
  module ClassMethods
17
- def property(name, options={}, &block)
18
- options[:default] = Uber::Options::Value.new(options[:default]) if options[:default]
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
@@ -23,6 +23,10 @@
23
23
  sync_hash_representer.new(self).to_hash
24
24
  end
25
25
  alias_method :sync!, :sync
26
+
27
+ # So far, hashes can't be persisted separately.
28
+ def save!
29
+ end
26
30
  end
27
31
  end
28
- end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Disposable
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -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"
@@ -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
@@ -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
- end
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.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-21 00:00:00.000000000 Z
11
+ date: 2015-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber