disposable 0.4.1 → 0.4.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: 1a74d3e306a9301f6e9ab4b6aea20395df6eae38
4
- data.tar.gz: a24e79ec0ade0a96579b0a25f520deea856e4e02
3
+ metadata.gz: f5456dc9441dfd2abd73248171b431ebc61aa999
4
+ data.tar.gz: 1dddb07f693e9d894387ee25d9127b15d4ceadcb
5
5
  SHA512:
6
- metadata.gz: f83c3a2ae0a3a85a5114afe05dec55ca9ceab8949b5472c3eb5324951f84a6251617b34611ecf185d9153bc954e216f415d48881e72b6ec0a69b8240f906fe09
7
- data.tar.gz: 0bba9cf7c8603f36a0c2e005215fbd66a0b2ed833002eba606df4bcd94292c421540e8f7d3c581f92ba08e72dbc0e854d47bf5b8a75cceab62aecd7abca903dc
6
+ metadata.gz: 362fd4826566616d0c8f1129b5898f27a1f7c342e4472843ea406fdcd9dc0782d2188e2e5bf228bc225b6607f2cefbfc4619fe61f7edfaf2616ebc84bb635721
7
+ data.tar.gz: 287ed98cc543a4cee24aafa03ffc7c372fc1cb7e904c11618d8b7caa5afda2839960645db873a32edfce2d035fc23e92618f66a4e1c5bbbdb8e5c13e995532b4
@@ -1,9 +1,13 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - 2.3.0 # why?
4
+ - 2.4.0
5
+ - 2.3.0
5
6
  - 2.2
6
7
  - 2.1
7
- - 2.0
8
+ # - 2.0
8
9
  gemfile:
9
10
  - Gemfile
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: 2.4.0
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.4.2
2
+
3
+ * `Twin#schema` doesn't `extend` at runtime anymore but uses a decorator for `each`.
4
+ * `PropertyProcessor` now yields `(twin, index)` if its working on a collection.
5
+
1
6
  # 0.4.1
2
7
 
3
8
  * Allow `false` as a `:default` value.
@@ -22,7 +22,7 @@ module Disposable
22
22
  end
23
23
 
24
24
  def schema
25
- self.class.definitions.extend(DefinitionsEach)
25
+ Definition::Each.new(self.class.definitions) # TODO: change this interface.
26
26
  end
27
27
 
28
28
  class << self
@@ -7,22 +7,25 @@ class Disposable::Twin
7
7
  def setter
8
8
  "#{self[:name]}="
9
9
  end
10
- end
11
-
12
- module DefinitionsEach
13
- def each(options={})
14
- return self unless block_given?
15
10
 
16
- super() do |dfn|
11
+ # :private:
12
+ Filter = ->(definitions, options) do
13
+ definitions.collect do |dfn|
17
14
  next if options[:exclude] and options[:exclude].include?(dfn[:name])
18
15
  next if options[:scalar] and dfn[:collection]
19
16
  next if options[:collection] and ! dfn[:collection]
20
17
  next if options[:twin] and ! dfn[:nested]
18
+ dfn
19
+ end.compact
20
+ end
21
21
 
22
- yield dfn
23
- end
22
+ require "delegate"
23
+ class Each < SimpleDelegator
24
+ def each(options={})
25
+ return __getobj__ unless block_given?
24
26
 
25
- self
27
+ Definition::Filter.(__getobj__, options).each { |dfn| yield dfn }
28
+ end
26
29
  end
27
30
  end
28
- end
31
+ end
@@ -3,9 +3,10 @@
3
3
  #
4
4
  # For a scalar property, this will be run once and yield the property's value.
5
5
  # For a collection, this is run per item and yields the item.
6
+ #:private:
6
7
  class Disposable::Twin::PropertyProcessor
7
8
  def initialize(definition, twin, value=nil)
8
- value ||= twin.send(definition.getter)
9
+ value ||= twin.send(definition.getter) # DISCUSS: should we decouple definition and value, here?
9
10
  @definition = definition
10
11
  @value = value
11
12
  end
@@ -20,12 +21,11 @@ class Disposable::Twin::PropertyProcessor
20
21
 
21
22
  private
22
23
  def collection!
23
- # FIXME: the nil collection is not tested, yet!
24
- (@value || []).collect { |nested_twin| yield(nested_twin) }
24
+ (@value || []).each_with_index.collect { |nested_twin, i| yield(nested_twin, i) }
25
25
  end
26
26
 
27
27
  def property!
28
28
  twin = @value or return nil
29
- nested_model = yield(twin)
29
+ yield(twin)
30
30
  end
31
- end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Disposable
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -176,8 +176,8 @@ class CoercionTypingTest < MiniTest::Spec
176
176
  twin.title = "Yo"
177
177
  twin.title.must_equal "Yo"
178
178
 
179
- twin.enabled = " TRUE"
180
- twin.enabled.must_equal true
179
+ # twin.enabled = " TRUE"
180
+ # twin.enabled.must_equal true
181
181
  end
182
182
  end
183
183
 
@@ -0,0 +1,45 @@
1
+ require "test_helper"
2
+
3
+ class PropertyProcessorTest < Minitest::Spec
4
+ Album = Struct.new(:title, :artist, :songs)
5
+ Artist = Struct.new(:name)
6
+ Song = Struct.new(:id)
7
+
8
+ class AlbumTwin < Disposable::Twin
9
+ property :title
10
+
11
+ property :artist do
12
+ property :name
13
+ end
14
+
15
+ collection :songs do
16
+ property :id
17
+ end
18
+ end
19
+
20
+ describe "collection" do
21
+ let(:twin) { AlbumTwin.new(Album.new("Live!", Artist.new, [Song.new(1), Song.new(2)])) }
22
+ it "yields twin, index" do
23
+ called = []
24
+ Disposable::Twin::PropertyProcessor.new(twin.class.definitions.get(:songs), twin).() { |v, i| called << [v.model, i] }
25
+
26
+ called.inspect.must_equal %{[[#<struct PropertyProcessorTest::Song id=1>, 0], [#<struct PropertyProcessorTest::Song id=2>, 1]]}
27
+ end
28
+
29
+ it "yields twin" do
30
+ called = []
31
+ Disposable::Twin::PropertyProcessor.new(twin.class.definitions.get(:songs), twin).() { |v| called << [v.model] }
32
+
33
+ called.inspect.must_equal %{[[#<struct PropertyProcessorTest::Song id=1>], [#<struct PropertyProcessorTest::Song id=2>]]}
34
+ end
35
+
36
+ it "allows nil collection" do
37
+ twin = AlbumTwin.new(Album.new("Live!", Artist.new, nil))
38
+
39
+ called = []
40
+ Disposable::Twin::PropertyProcessor.new(twin.class.definitions.get(:songs), twin).() { |v, i| called << [v.model, i] }
41
+
42
+ called.inspect.must_equal %{[]}
43
+ end
44
+ end
45
+ 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.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-28 00:00:00.000000000 Z
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber
@@ -246,6 +246,7 @@ files:
246
246
  - test/twin/option_test.rb
247
247
  - test/twin/parent_test.rb
248
248
  - test/twin/process_inline_test.rb
249
+ - test/twin/property_processor_test.rb
249
250
  - test/twin/readable_test.rb
250
251
  - test/twin/save_test.rb
251
252
  - test/twin/setup_test.rb
@@ -277,7 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
278
  version: '0'
278
279
  requirements: []
279
280
  rubyforge_project:
280
- rubygems_version: 2.6.3
281
+ rubygems_version: 2.5.1
281
282
  signing_key:
282
283
  specification_version: 4
283
284
  summary: Decorators on top of your ORM layer with change tracking, collection semantics
@@ -309,6 +310,7 @@ test_files:
309
310
  - test/twin/option_test.rb
310
311
  - test/twin/parent_test.rb
311
312
  - test/twin/process_inline_test.rb
313
+ - test/twin/property_processor_test.rb
312
314
  - test/twin/readable_test.rb
313
315
  - test/twin/save_test.rb
314
316
  - test/twin/setup_test.rb