disposable 0.4.6 → 0.6.1

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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +29 -0
  3. data/.gitignore +1 -0
  4. data/CHANGES.md +18 -0
  5. data/Gemfile +2 -0
  6. data/Gemfile_builder_test.rb +6 -0
  7. data/README.md +4 -0
  8. data/Rakefile +8 -2
  9. data/disposable.gemspec +2 -5
  10. data/lib/disposable/twin/builder.rb +1 -0
  11. data/lib/disposable/twin/coercion.rb +4 -1
  12. data/lib/disposable/twin/default.rb +3 -3
  13. data/lib/disposable/twin/property/struct.rb +3 -1
  14. data/lib/disposable/twin/property/unnest.rb +4 -3
  15. data/lib/disposable/twin.rb +2 -2
  16. data/lib/disposable/version.rb +1 -1
  17. data/test/callback_group_test.rb +27 -27
  18. data/test/callbacks_test.rb +44 -44
  19. data/test/expose_test.rb +16 -16
  20. data/test/persisted_test.rb +30 -30
  21. data/test/rescheme_test.rb +22 -22
  22. data/test/skip_getter_test.rb +14 -14
  23. data/test/test_helper.rb +1 -1
  24. data/test/twin/builder_test.rb +7 -3
  25. data/test/twin/changed_test.rb +36 -36
  26. data/test/twin/coercion_test.rb +61 -23
  27. data/test/twin/collection_test.rb +46 -46
  28. data/test/twin/composition_test.rb +20 -20
  29. data/test/twin/default_test.rb +15 -15
  30. data/test/twin/expose_test.rb +15 -15
  31. data/test/twin/feature_test.rb +10 -10
  32. data/test/twin/from_collection_test.rb +4 -4
  33. data/test/twin/from_test.rb +3 -3
  34. data/test/twin/hash_test.rb +38 -38
  35. data/test/twin/inherit_test.rb +7 -7
  36. data/test/twin/inheritance_test.rb +6 -6
  37. data/test/twin/parent_test.rb +5 -5
  38. data/test/twin/property_processor_test.rb +3 -3
  39. data/test/twin/readable_test.rb +9 -9
  40. data/test/twin/save_test.rb +44 -44
  41. data/test/twin/setup_test.rb +25 -25
  42. data/test/twin/skip_unchanged_test.rb +6 -6
  43. data/test/twin/struct/coercion_test.rb +4 -4
  44. data/test/twin/struct_test.rb +41 -38
  45. data/test/twin/sync_test.rb +29 -29
  46. data/test/twin/twin_test.rb +14 -14
  47. data/test/twin/unnest_test.rb +7 -7
  48. data/test/twin/virtual_test.rb +3 -3
  49. data/test/twin/writeable_test.rb +8 -8
  50. metadata +11 -67
  51. data/.travis.yml +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d17fbfc73eb6b25b90136d515733b694ac2631ad3861f47d62dde5517ec394b
4
- data.tar.gz: be69f4aaed8fda60749dcb3dc3188bb57def014cd91715198baab0eebd801386
3
+ metadata.gz: e381c394b04f502f9af8ba27192e898d4e1f1214e85e441b50182f5f353e1137
4
+ data.tar.gz: 4a6b6a0e270c0229f5bed96d51d2b4a41bd1a66bd2b80293a61e1cab74803d52
5
5
  SHA512:
6
- metadata.gz: eb4b2eca60ed3001be80d50eff19fe008abf68030a99101eb0282b5fe65d091c21d62537a3dcbfafb32484e985d4e670377d701413de25832b8195f0ff08cdeb
7
- data.tar.gz: b95131034f38c0907672943108c0633164817981ba0107c508e618467b69f0c7f2e914c91d1152219b3488e6432cd1a9839e394704a1465e1792ef540140613e
6
+ metadata.gz: dfeeff838ca34e37a5741cb7ac7829a7be52248b8b5a8fe16c7d7dbef32e13dffe7d543e668bc1cfb674daeeb75d7d144bab1b5caf15d892b4a427b1dedf7e44
7
+ data.tar.gz: 154949ab53a0508659db1d47acc9b9f797870724d554c2935fb92764e6156308ab00c5d5ec33629b8f3c37204c5fda4cb2bae879b5f87cd3b6d879889bf39ecb
@@ -0,0 +1,29 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ ruby: [2.6]
9
+ active_record: [5.2, 6.0]
10
+ dry_types: [1.0, 1.2]
11
+
12
+ include:
13
+ - ruby: 2.7
14
+ active_record: 6.1
15
+ dry_types: 1.5
16
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
17
+ - ruby: '3.0'
18
+ active_record: 6.1
19
+ dry_types: 1.5
20
+
21
+ runs-on: ubuntu-latest
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ - uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby }}
27
+ # bundler-cache: true # runs 'bundle install' and caches installed gems automatically
28
+ - run: ACTIVERECORD=${{ matrix.active_record}} DRY_TYPES=${{ matrix.dry_types }} bundle install
29
+ - run: ACTIVERECORD=${{ matrix.active_record}} DRY_TYPES=${{ matrix.dry_types }} bundle exec rake
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ test/tmp
15
15
  test/version_tmp
16
16
  tmp
17
17
  Gemfile*.lock
18
+ .rubocop*
data/CHANGES.md CHANGED
@@ -1,3 +1,21 @@
1
+ # 0.6.1
2
+
3
+ * Remove `**options` argument from `#property` as it's inconsistent with underlying gems.
4
+
5
+ # 0.6.0
6
+
7
+ * Remove `uber` gem.
8
+ * Remove `declarative-builder` dependency and make it optional. Add `gem "declarative-builder"` to your `Gemfile` should you need this feature.
9
+
10
+ # 0.5.0
11
+
12
+ * Upgrade `representable` to replace `Declarative::Option` with `Representable::Option` in order to support ruby-3 style of keyword arguments.
13
+
14
+ # 0.4.7
15
+
16
+ * Deprecation warning for nilify options for dry-v >= 1.x
17
+ * Fix initializer struct when using `false` as value
18
+
1
19
  # 0.4.6
2
20
 
3
21
  * Remove deprecation warnings for newer versions of dry-types
data/Gemfile CHANGED
@@ -7,4 +7,6 @@ gem "minitest-line"
7
7
  gem gem_name, dependency
8
8
  end
9
9
 
10
+ gem "sqlite3", ENV.fetch('ACTIVERECORD', '5.2').to_f >= 6 ? '~> 1.4' : '~> 1.3.0'
10
11
 
12
+ # gem "declarative-builder"
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+ gem "minitest-line"
4
+ gem "sqlite3"
5
+
6
+ gem "declarative-builder", "0.2.0"
data/README.md CHANGED
@@ -640,3 +640,7 @@ Note that this will internally add a `parent` property.
640
640
 
641
641
  * [Reform](https://github.com/apotonick/reform) forms are based on twins and add a little bit of form decoration on top. Every nested form is a twin.
642
642
  * [Trailblazer](https://github.com/apotonick/trailblazer) uses twins as decorators and callbacks in operations to structure business logic.
643
+
644
+ ## Development
645
+
646
+ * `rake test` runs all tests without `builder_test.rb`. For the latter, run `BUNDLE_GEMFILE=Gemfile_builder_test.rb bundle exec rake test_builder`
data/Rakefile CHANGED
@@ -4,6 +4,12 @@ require "rake/testtask"
4
4
  task :default => [:test]
5
5
  Rake::TestTask.new(:test) do |test|
6
6
  test.libs << 'test'
7
- test.test_files = FileList['test/**/*_test.rb']
7
+ test.test_files = FileList['test/**/*_test.rb'] - ["test/twin/builder_test.rb"]
8
8
  test.verbose = true
9
- end
9
+ end
10
+
11
+ Rake::TestTask.new(:test_builder) do |test|
12
+ test.libs << 'test'
13
+ test.test_files = FileList["test/twin/builder_test.rb"]
14
+ test.verbose = true
15
+ end
data/disposable.gemspec CHANGED
@@ -16,17 +16,14 @@ Gem::Specification.new do |spec|
16
16
  spec.test_files = spec.files.grep(%r{^(test)/})
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_dependency "uber", "< 0.2.0"
20
19
  spec.add_dependency "declarative", ">= 0.0.9", "< 1.0.0"
21
- spec.add_dependency "declarative-builder", "< 0.2.0"
22
- spec.add_dependency "declarative-option", "< 0.2.0"
23
- spec.add_dependency "representable", ">= 2.4.0", "<= 3.1.0"
20
+ # spec.add_dependency "declarative-builder" #, ">= 0.2.0"
21
+ spec.add_dependency "representable", ">= 3.1.1", "< 3.2.0"
24
22
 
25
23
  spec.add_development_dependency "bundler"#, "~> 1.3"
26
24
  spec.add_development_dependency "rake"
27
25
  spec.add_development_dependency "minitest"
28
26
  spec.add_development_dependency "activerecord"#, "4.2.5"
29
- spec.add_development_dependency "sqlite3", '~> 1.3.0'
30
27
  spec.add_development_dependency "dry-types"# "~> 0.6"
31
28
  # spec.add_development_dependency "database_cleaner"
32
29
  end
@@ -1,3 +1,4 @@
1
+ gem "declarative-builder", "0.2.0"
1
2
  require "declarative/builder"
2
3
 
3
4
  module Disposable
@@ -18,7 +18,10 @@ module Disposable::Twin::Coercion
18
18
  end
19
19
 
20
20
  def coercing_setter!(name, type, nilify=false)
21
- type = type ? (DRY_TYPES_CONSTANT::Nil | type) : DRY_TYPES_CONSTANT::Nil if nilify
21
+ # TODO: remove nilily with next release (0.5) for new dry-type versions
22
+ type = type ? (DRY_TYPES_CONSTANT::Nil | type) : DRY_TYPES_CONSTANT::Nil if nilify
23
+
24
+ warn "DEPRECATION WARNING [Disposable]: nilify is deprecated and it will be removed with the next release" if nilify && DRY_TYPES_VERSION >= Gem::Version.new("1.0.0")
22
25
 
23
26
  mod = Module.new do
24
27
  define_method("#{name}=") do |value|
@@ -1,4 +1,4 @@
1
- require "declarative/option"
1
+ require "representable/option"
2
2
 
3
3
  # TODO: allow default: -> for hashes, etc.
4
4
  module Disposable::Twin::Default
@@ -12,13 +12,13 @@ module Disposable::Twin::Default
12
12
  # TODO: introduce Null object in Declarative::Definition#[].
13
13
  # dfn[:default].(self) # dfn#[] should return a Null object here if empty.
14
14
  return unless dfn[:default]
15
- dfn[:default].(self)
15
+ dfn[:default].(exec_context: self) # Representable::Option#call
16
16
  end
17
17
 
18
18
  module ClassMethods
19
19
  private
20
20
  def build_definition(name, options={}, &block)
21
- options = options.merge(default: Declarative::Option(options[:default], instance_exec: true)) if options.has_key?(:default)
21
+ options = options.merge(default: ::Representable::Option(options[:default])) if options.has_key?(:default)
22
22
  super
23
23
  end
24
24
  end
@@ -6,7 +6,9 @@ class Disposable::Twin
6
6
  module Struct
7
7
  def read_value_for(dfn, options)
8
8
  name = dfn[:name]
9
- @model[name.to_s] || @model[name.to_sym] # TODO: test sym vs. str.
9
+ # TODO: test sym vs. str.
10
+ return unless key_value = model.to_h.find { |k, _| k.to_sym == name.to_sym }
11
+ key_value.last
10
12
  end
11
13
 
12
14
  def sync_hash_representer # TODO: make this without representable, please.
@@ -1,10 +1,11 @@
1
- require "uber/delegates"
1
+ require "forwardable"
2
2
 
3
3
  module Disposable::Twin::Property
4
4
  module Unnest
5
+ extend Forwardable
5
6
  # TODO: test that nested properties options are "unnested", too, e.g. populator.
6
7
  def self.included(includer)
7
- includer.send(:include, Uber::Delegates)
8
+ includer.send(:include, Forwardable)
8
9
  end
9
10
 
10
11
  def unnest(name, options)
@@ -15,7 +16,7 @@ module Disposable::Twin::Property
15
16
  options = options.merge(virtual: true, _inherited: true, private_name: nil)
16
17
 
17
18
  property(name, options)
18
- delegates from, name, "#{name}="
19
+ def_delegators from, name, "#{name}="
19
20
  end
20
21
  end
21
22
  end
@@ -1,4 +1,4 @@
1
- require "uber/inheritable_attr"
1
+ # require "uber/inheritable_attr"
2
2
  require "declarative/schema"
3
3
  require "representable/decorator"
4
4
 
@@ -140,7 +140,7 @@ require "disposable/twin/definitions"
140
140
  require "disposable/twin/collection"
141
141
  require "disposable/twin/sync"
142
142
  require "disposable/twin/save"
143
- require "disposable/twin/builder"
143
+ # require "disposable/twin/builder"
144
144
  require "disposable/twin/changed"
145
145
  require "disposable/twin/property_processor"
146
146
  require "disposable/twin/persisted"
@@ -1,3 +1,3 @@
1
1
  module Disposable
2
- VERSION = "0.4.6"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -55,7 +55,7 @@ class CallbackGroupTest < MiniTest::Spec
55
55
  album = Album.new(songs: [Song.new(title: "Dead To Me"), Song.new(title: "Diesel Boy")])
56
56
  twin = AlbumTwin.new(album)
57
57
 
58
- Group.new(twin).().invocations.must_equal [
58
+ expect(Group.new(twin).().invocations).must_equal [
59
59
  [:on_change, :change!, []],
60
60
  [:on_add, :notify_album!, []],
61
61
  [:on_add, :reset_song!, []],
@@ -76,7 +76,7 @@ class CallbackGroupTest < MiniTest::Spec
76
76
 
77
77
  group = Group.new(twin).(content: content)
78
78
 
79
- group.invocations.must_equal [
79
+ expect(group.invocations).must_equal [
80
80
  [:on_change, :change!, [twin]],
81
81
  [:on_add, :notify_album!, [twin.songs[0], twin.songs[1]]],
82
82
  [:on_add, :reset_song!, [twin.songs[0], twin.songs[1]]],
@@ -85,8 +85,8 @@ class CallbackGroupTest < MiniTest::Spec
85
85
  [:on_update, :expire_cache!, []],
86
86
  ]
87
87
 
88
- content.must_equal "notify_album!notify_album!reset_song!reset_song!"
89
- group.output.must_equal "Album has changed!"
88
+ expect(content).must_equal "notify_album!notify_album!reset_song!reset_song!"
89
+ expect(group.output).must_equal "Album has changed!"
90
90
  end
91
91
 
92
92
 
@@ -129,7 +129,7 @@ class CallbackGroupTest < MiniTest::Spec
129
129
 
130
130
  # pp group.invocations
131
131
 
132
- group.invocations.must_equal [
132
+ expect(group.invocations).must_equal [
133
133
  [:on_change, :change!, [twin]],
134
134
  [:on_add, :notify_album!, [twin.songs[0]]],
135
135
  [:on_add, :reset_song!, [twin.songs[0]]],
@@ -138,7 +138,7 @@ class CallbackGroupTest < MiniTest::Spec
138
138
  [:on_update, :expire_cache!, []],
139
139
  ]
140
140
 
141
- content.must_equal "Op: changed! [CallbackGroupTest::Operation]Op: notify_album! [CallbackGroupTest::Operation]Op: reset_song! [CallbackGroupTest::Operation]"
141
+ expect(content).must_equal "Op: changed! [CallbackGroupTest::Operation]Op: notify_album! [CallbackGroupTest::Operation]Op: reset_song! [CallbackGroupTest::Operation]"
142
142
  end
143
143
  end
144
144
 
@@ -157,12 +157,12 @@ class CallbackGroupInheritanceTest < MiniTest::Spec
157
157
  end
158
158
 
159
159
  it do
160
- Group.hooks.size.must_equal 4
161
- Group.hooks[0].to_s.must_equal "[:on_change, :change!, {}]"
160
+ expect(Group.hooks.size).must_equal 4
161
+ expect(Group.hooks[0].to_s).must_equal "[:on_change, :change!, {}]"
162
162
  # Group.hooks[1][1][:nested].hooks.to_s.must_equal "[[:on_add, [:notify_album!]],[:on_add, [:reset_song!]]]"
163
- Group.hooks[2].to_s.must_equal "[:on_change, :rehash_name!, {:property=>:title}]"
163
+ expect(Group.hooks[2].to_s).must_equal "[:on_change, :rehash_name!, {:property=>:title}]"
164
164
 
165
- Group.definitions.get(Group.hooks[3][1])[:nested].hooks.to_s.must_equal "[[:on_change, :sing!, {}]]"
165
+ expect(Group.definitions.get(Group.hooks[3][1])[:nested].hooks.to_s).must_equal "[[:on_change, :sing!, {}]]"
166
166
  end
167
167
 
168
168
  class EmptyGroup < Group
@@ -171,7 +171,7 @@ class CallbackGroupInheritanceTest < MiniTest::Spec
171
171
 
172
172
 
173
173
  it do
174
- EmptyGroup.hooks.size.must_equal 4
174
+ expect(EmptyGroup.hooks.size).must_equal 4
175
175
  # TODO:
176
176
  end
177
177
 
@@ -183,10 +183,10 @@ class CallbackGroupInheritanceTest < MiniTest::Spec
183
183
  end
184
184
 
185
185
  it do
186
- Group.hooks.size.must_equal 4
186
+ expect(Group.hooks.size).must_equal 4
187
187
  # pp EnhancedGroup.hooks
188
- EnhancedGroup.hooks.size.must_equal 6
189
- EnhancedGroup.definitions.get(EnhancedGroup.hooks[5][1])[:nested].hooks.to_s.must_equal "[[:on_add, :rewind!, {}]]"
188
+ expect(EnhancedGroup.hooks.size).must_equal 6
189
+ expect(EnhancedGroup.definitions.get(EnhancedGroup.hooks[5][1])[:nested].hooks.to_s).must_equal "[[:on_add, :rewind!, {}]]"
190
190
  end
191
191
 
192
192
  class EnhancedWithInheritGroup < EnhancedGroup
@@ -199,13 +199,13 @@ class CallbackGroupInheritanceTest < MiniTest::Spec
199
199
  end
200
200
 
201
201
  it do
202
- Group.hooks.size.must_equal 4
203
- EnhancedGroup.hooks.size.must_equal 6
202
+ expect(Group.hooks.size).must_equal 4
203
+ expect(EnhancedGroup.hooks.size).must_equal 6
204
204
 
205
- EnhancedGroup.definitions.get(EnhancedGroup.hooks[5][1])[:nested].hooks.to_s.must_equal "[[:on_add, :rewind!, {}]]"
206
- EnhancedWithInheritGroup.hooks.size.must_equal 6
207
- EnhancedWithInheritGroup.definitions.get(EnhancedWithInheritGroup.hooks[1][1])[:nested].hooks.to_s.must_equal "[[:on_add, :rewind!, {}], [:on_add, :eat!, {}]]"
208
- EnhancedWithInheritGroup.definitions.get(EnhancedWithInheritGroup.hooks[3][1])[:nested].hooks.to_s.must_equal "[[:on_change, :sing!, {}], [:on_delete, :yell!, {}]]"
205
+ expect(EnhancedGroup.definitions.get(EnhancedGroup.hooks[5][1])[:nested].hooks.to_s).must_equal "[[:on_add, :rewind!, {}]]"
206
+ expect(EnhancedWithInheritGroup.hooks.size).must_equal 6
207
+ expect(EnhancedWithInheritGroup.definitions.get(EnhancedWithInheritGroup.hooks[1][1])[:nested].hooks.to_s).must_equal "[[:on_add, :rewind!, {}], [:on_add, :eat!, {}]]"
208
+ expect(EnhancedWithInheritGroup.definitions.get(EnhancedWithInheritGroup.hooks[3][1])[:nested].hooks.to_s).must_equal "[[:on_change, :sing!, {}], [:on_delete, :yell!, {}]]"
209
209
  end
210
210
 
211
211
  class RemovingInheritGroup < Group
@@ -226,10 +226,10 @@ class CallbackGroupInheritanceTest < MiniTest::Spec
226
226
  # TODO: object_id tests for all nested representers.
227
227
 
228
228
  it do
229
- Group.hooks.size.must_equal 4
230
- RemovingInheritGroup.hooks.size.must_equal 3
231
- RemovingInheritGroup.definitions.get(RemovingInheritGroup.hooks[0][1])[:nested].hooks.to_s.must_equal "[[:on_add, :reset_song!, {}]]"
232
- RemovingInheritGroup.definitions.get(RemovingInheritGroup.hooks[2][1])[:nested].hooks.to_s.must_equal "[[:on_change, :sing!, {}]]"
229
+ expect(Group.hooks.size).must_equal 4
230
+ expect(RemovingInheritGroup.hooks.size).must_equal 3
231
+ expect(RemovingInheritGroup.definitions.get(RemovingInheritGroup.hooks[0][1])[:nested].hooks.to_s).must_equal "[[:on_add, :reset_song!, {}]]"
232
+ expect(RemovingInheritGroup.definitions.get(RemovingInheritGroup.hooks[2][1])[:nested].hooks.to_s).must_equal "[[:on_change, :sing!, {}]]"
233
233
  end
234
234
 
235
235
  # Group::clone
@@ -239,7 +239,7 @@ class CallbackGroupInheritanceTest < MiniTest::Spec
239
239
  end
240
240
 
241
241
  it do
242
- Group.hooks.size.must_equal 4
243
- ClonedGroup.hooks.size.must_equal 3
242
+ expect(Group.hooks.size).must_equal 4
243
+ expect(ClonedGroup.hooks.size).must_equal 3
244
244
  end
245
- end
245
+ end