disposable 0.2.5 → 0.2.6

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: 759a5958374916be8a4af8610667ea30520d6b58
4
- data.tar.gz: 894eaed202b55b5498b07cfd1861a459452c370a
3
+ metadata.gz: 671f773f835c6eba43f53ee846d24f4ac5b72d2b
4
+ data.tar.gz: 0742d9831fb0bcd7d5e66e7352f829d787250cb2
5
5
  SHA512:
6
- metadata.gz: 72ee2805890c1af032667f713861eb10d8b5edd3066b02faffb2d55c1b1fdd69e3c2a8477691151b9532e7709a5fff2937421022acc23ec727ff2cb205631c9a
7
- data.tar.gz: 090d0c2fa08690c152b80055d3e5449c7adee5e58703ed1b94cfe242838b0941031e1919aac56a06b472a5b6e71794e15c760f99412495252c4791c6719bdb5e
6
+ metadata.gz: fd89e067485d519c4cdd4ce66a3e02c6850bd78950c0854b11bdfa687d4847575cefad700b8a819fbd526279b3261c8e7c969124d43c31eb4d2d5e41c2e1aa9f
7
+ data.tar.gz: a1ebbb97af16dc427b484eaa311f47f0a4168cbfc27b77800f69384f4eae71124d6bf8b07829739efeb59352f76e3e07f8eef8a17b75b2818a474b273cda770e
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.2.6
2
+
3
+ * Manual accessors are no longer overridden when inheriting twin classes.
4
+ * The `:from` option is no longer ignored when inheriting.
5
+
1
6
  # 0.2.5
2
7
 
3
8
  * Fix loading order, you may now `require "disposable/twin"` without any further requires.
data/Gemfile CHANGED
@@ -6,4 +6,4 @@ gem "representable", "2.4.0"
6
6
  # gem "representable", github: "apotonick/representable"
7
7
  # gem "declarative", path: "../declarative"
8
8
  # gem "declarative", github: "apotonick/declarative"
9
- gem "minitest-line"
9
+ gem "minitest-line"
data/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  _Decorators on top of your ORM layer._
4
4
 
5
+ [![Gitter Chat](https://badges.gitter.im/trailblazer/chat.svg)](https://gitter.im/trailblazer/chat)
6
+ [![TRB Newsletter](https://img.shields.io/badge/TRB-newsletter-lightgrey.svg)](http://trailblazer.to/newsletter/)
7
+ [![Build
8
+ Status](https://travis-ci.org/apotonick/disposable.svg)](https://travis-ci.org/apotonick/disposable)
9
+ [![Gem Version](https://badge.fury.io/rb/disposable.svg)](http://badge.fury.io/rb/disposable)
10
+
5
11
  ## Introduction
6
12
 
7
13
  Disposable is the missing API of ActiveRecord*. The mission:
data/disposable.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "uber"
21
- spec.add_dependency "declarative", "~> 0.0.4"
21
+ spec.add_dependency "declarative", "~> 0.0.6"
22
22
  spec.add_dependency "representable", ">= 2.4.0", "<= 3.1.0"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -14,6 +14,13 @@ module Disposable
14
14
  Definition
15
15
  end
16
16
 
17
+ def self.inherited(subclass)
18
+ # no super here!
19
+ heritage.(subclass) do |cfg|
20
+ cfg[:args].last.merge!(_inherited: true) if cfg[:method] == :property
21
+ end
22
+ end
23
+
17
24
  def schema
18
25
  self.class.definitions.extend(DefinitionsEach)
19
26
  end
@@ -25,7 +32,8 @@ module Disposable
25
32
 
26
33
  # TODO: move to Declarative, as in Representable and Reform.
27
34
  def property(name, options={}, &block)
28
- options[:private_name] = options.delete(:from) || name
35
+ options[:private_name] ||= options.delete(:from) || name
36
+ is_inherited = options.delete(:_inherited)
29
37
 
30
38
  if options.delete(:virtual)
31
39
  options[:writeable] = options[:readable] = false
@@ -33,8 +41,8 @@ module Disposable
33
41
 
34
42
  options[:nested] = options.delete(:twin) if options[:twin]
35
43
 
36
- super(name, options, &block).tap do |definition|
37
- create_accessors(name, definition)
44
+ super(name, options, &block).tap do |definition| # super is Declarative::Schema::property.
45
+ create_accessors(name, definition) unless is_inherited
38
46
  end
39
47
  end
40
48
 
@@ -54,4 +54,4 @@ module Disposable
54
54
  end
55
55
  end
56
56
  end
57
- end
57
+ end
@@ -1,3 +1,3 @@
1
1
  module Disposable
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -54,4 +54,32 @@ class InheritTest < MiniTest::Spec
54
54
 
55
55
  # inherit inline twins when overriding.
56
56
  it { Twin::Compilation.new(album).artist.artist_id.must_equal 1 }
57
- end
57
+
58
+ describe "custom accessors get inherited" do
59
+ class Singer < Disposable::Twin
60
+ property :name
61
+
62
+ def name
63
+ super.reverse
64
+ end
65
+
66
+ def name=(val)
67
+ super(val.downcase)
68
+ end
69
+ end
70
+
71
+ class Star < Singer
72
+ end
73
+
74
+ let (:model) { Model::Artist.new("Helloween") }
75
+
76
+ it do
77
+ artist = Star.new(model)
78
+ artist.name.must_equal("neewolleh")
79
+
80
+ artist.name = "HELLOWEEN"
81
+ # artist.with_custom_setter = "this gets ignored"
82
+ artist.name.must_equal("neewolleh")
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,73 @@
1
+ require "test_helper"
2
+
3
+ class InheritanceTest < Minitest::Spec
4
+ let (:song) { OpenStruct.new(id: 0) }
5
+
6
+ module Id
7
+ def id
8
+ super - 1
9
+ end
10
+
11
+ def id=(v)
12
+ super(v+1)
13
+ end
14
+ end
15
+
16
+ class Twin < Disposable::Twin
17
+ property :id
18
+ include Id
19
+ end
20
+
21
+ it do
22
+ twin = Twin.new(song)
23
+ twin.id.must_equal 0
24
+ end
25
+
26
+ class TwinComposition < Disposable::Twin
27
+ include Composition
28
+
29
+ property :id, on: :song
30
+ include Id
31
+ end
32
+
33
+ it do
34
+ twin = TwinComposition.new(song: song)
35
+ twin.id.must_equal 0
36
+ twin.id= 3
37
+ twin.id.must_equal 3
38
+ end
39
+
40
+
41
+ class TwinCompositionDefineMethod < Disposable::Twin
42
+ include Composition
43
+
44
+ property :id, on: :song
45
+
46
+ define_method :id do
47
+ super() + 9
48
+ end
49
+ end
50
+
51
+ it do
52
+ twin = TwinCompositionDefineMethod.new(song: song)
53
+ twin.id.must_equal 9
54
+ end
55
+
56
+
57
+ describe ":from" do
58
+ let (:song) { Struct.new(:ident).new(1) }
59
+
60
+ class TwinWithFrom < Disposable::Twin
61
+ include Expose
62
+ property :id, from: :ident
63
+ end
64
+
65
+ class InheritingFrom < TwinWithFrom
66
+ end
67
+
68
+ it do
69
+ TwinWithFrom.new(song).id.must_equal 1
70
+ InheritingFrom.new(song).id.must_equal 1
71
+ end
72
+ end
73
+ 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.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-19 00:00:00.000000000 Z
11
+ date: 2016-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.4
33
+ version: 0.0.6
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.4
40
+ version: 0.0.6
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: representable
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -204,6 +204,7 @@ files:
204
204
  - test/twin/from_collection_test.rb
205
205
  - test/twin/from_test.rb
206
206
  - test/twin/inherit_test.rb
207
+ - test/twin/inheritance_test.rb
207
208
  - test/twin/option_test.rb
208
209
  - test/twin/parent_test.rb
209
210
  - test/twin/process_inline_test.rb
@@ -264,6 +265,7 @@ test_files:
264
265
  - test/twin/from_collection_test.rb
265
266
  - test/twin/from_test.rb
266
267
  - test/twin/inherit_test.rb
268
+ - test/twin/inheritance_test.rb
267
269
  - test/twin/option_test.rb
268
270
  - test/twin/parent_test.rb
269
271
  - test/twin/process_inline_test.rb